Skip to content
Snippets Groups Projects
Commit a7c8a849 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Ajout des commandes shell de concaténation de fichiers PDF avec Ghostscript ou QPDF.

parent f6001127
Branches
Tags
No related merge requests found
Pipeline #21739 passed
CHANGELOG
=========
6.1.0
-----
- Ajout des commandes shell de concaténation de fichiers PDF avec Ghostscript ou QPDF.
6.0.1
-----
- Ajout d'une fonction statique afin de simplifier le code de création de PDF dans les applications.
......
......@@ -5,7 +5,8 @@
"php": "^8.0",
"mpdf/mpdf": "^8.0",
"laminas/laminas-view": "^2.22",
"laminas/laminas-dependency-plugin": "^2.1"
"laminas/laminas-dependency-plugin": "^2.1",
"unicaen/shell": "^1.0"
},
"require-dev": {
"laminas/laminas-test": "^4.0",
......
......@@ -2,7 +2,27 @@
namespace UnicaenPdf;
use UnicaenPdf\Command\PdfMergeShellCommandGs;
use UnicaenPdf\Command\PdfMergeShellCommandQpdf;
use UnicaenPdf\Options\ModuleOptions;
use UnicaenPdf\Options\ModuleOptionsFactory;
return [
'unicaen-pdf' => [
],
'unicaen-shell' => [
'commands' => [
PdfMergeShellCommandGs::class => [
'executable' => '/usr/bin/gs',
],
PdfMergeShellCommandQpdf::class => [
'executable' => '/usr/bin/qpdf',
],
],
],
'router' => [
'routes' => [
],
......@@ -15,6 +35,7 @@ return [
],
'service_manager' => [
'factories' => [
ModuleOptions::class => ModuleOptionsFactory::class,
],
],
'view_helpers' => [
......
<?php
namespace UnicaenPdf\Command;
trait PdfMergeShellCommandAwareTrait
{
protected PdfMergeShellCommandInterface $pdfMergeShellCommand;
public function setPdfMergeShellCommand(PdfMergeShellCommandInterface $pdfMergeShellCommand): void
{
$this->pdfMergeShellCommand = $pdfMergeShellCommand;
}
}
\ No newline at end of file
<?php
namespace UnicaenPdf\Command;
use UnicaenPdf\Command\PdfMergeShellCommandInterface;
use UnicaenShell\Command\ShellCommand;
/**
* Commande de concaténation de N fichiers PDF.
*
* Version utilisant 'ghostscript'.
*/
final class PdfMergeShellCommandGs extends ShellCommand implements PdfMergeShellCommandInterface
{
protected string $noCompressionOption = '-dColorConversionStrategy=/LeaveColorUnchanged -dDownsampleMonoImages=false -dDownsampleGrayImages=false -dDownsampleColorImages=false -dAutoFilterColorImages=false -dAutoFilterGrayImages=false -dColorImageFilter=/FlateEncode -dGrayImageFilter=/FlateEncode';
/**
* @return string
*/
public function getName(): string
{
return 'PdfMergeShellCommandGs';
}
public function checkRequirements(): void
{
$this->assertExecutableExists();
}
/**
* @inheritDoc
*/
public function generateCommandLine()
{
$command = $this->executable . ' ' . $this->noCompressionOption;
$command .=
' -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=' . $this->outputFilePath .
' -dBATCH ' . implode(' ', $this->inputFilesPaths);
$this->commandLine = $command;
}
}
\ No newline at end of file
<?php
namespace UnicaenPdf\Command;
use UnicaenShell\Command\ShellCommandInterface;
/**
* Commande de concaténation de fichiers PDF.
*/
interface PdfMergeShellCommandInterface extends ShellCommandInterface
{
}
\ No newline at end of file
<?php
namespace UnicaenPdf\Command;
use UnicaenPdf\Command\PdfMergeShellCommandInterface;
use UnicaenShell\Command\ShellCommand;
/**
* Commande de concaténation de N fichiers PDF.
*
* Version utilisant 'qpdf'.
*/
final class PdfMergeShellCommandQpdf extends ShellCommand implements PdfMergeShellCommandInterface
{
public function getName(): string
{
return 'MergeShellCommandQpdf';
}
public function checkRequirements(): void
{
$this->assertExecutableExists();
}
public function generateCommandLine()
{
// Commande de fusion (cf. https://qpdf.readthedocs.io/en/10.5/cli.html#page-selection-options)
$command = $this->executable .
sprintf(' --warning-exit-0 %s --pages . %s -- %s',
array_shift($this->inputFilesPaths),
implode(' ', $this->inputFilesPaths),
$this->outputFilePath
);
$this->commandLine = $command;
}
}
\ No newline at end of file
<?php
namespace UnicaenPdf\Options;
/**
* Classe encapsulant les options de fonctionnement du module.
*
* @author Bertrand GAUTHIER <bertrand.gauthier@unicaen.fr>
*/
class ModuleOptions
{
}
\ No newline at end of file
<?php
namespace UnicaenPdf\Options;
trait ModuleOptionsAwareTrait
{
protected ModuleOptions $moduleOptions;
public function setModuleOptions(ModuleOptions $moduleOptions): void
{
$this->moduleOptions = $moduleOptions;
}
}
\ No newline at end of file
<?php
namespace UnicaenPdf\Options;
use Interop\Container\ContainerInterface;
/**
* @author Unicaen
*/
class ModuleOptionsFactory
{
public function __invoke(ContainerInterface $container): ModuleOptions
{
return new ModuleOptions();
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment