From 95f9a803b891ec03ab580abf3a4529aad4a78856 Mon Sep 17 00:00:00 2001 From: vagrant Date: Fri, 9 Nov 2018 13:53:32 +0000 Subject: [PATCH] Enabled PdfSeparate functionality. Added file suffix option. --- src/PopplerPhp/PdfSeparate.php | 32 ++++++++++++++++++++++++++++++++ src/PopplerPhp/PopplerUtil.php | 16 +++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/PopplerPhp/PdfSeparate.php b/src/PopplerPhp/PdfSeparate.php index b9fd796..a3ec922 100644 --- a/src/PopplerPhp/PdfSeparate.php +++ b/src/PopplerPhp/PdfSeparate.php @@ -9,8 +9,28 @@ namespace NcJoes\PopplerPhp; +use NcJoes\PopplerPhp\Constants as C; +use NcJoes\PopplerPhp\PopplerOptions\CairoOptions; +use NcJoes\PopplerPhp\PopplerOptions\HelpFlags; +use NcJoes\PopplerPhp\PopplerOptions\PageRangeOptions; + + class PdfSeparate extends PopplerUtil { + /** + * PdfSeparate constructor. + * + * @param string $pdfFile + * @param array $options + */ + public function __construct($pdfFile = '', array $options = []) + { + $this->bin_file = C::PDF_SEPARATE; + + return parent::__construct($pdfFile, $options); + } + + public function utilOptions() { // TODO: Implement utilOptions() method. @@ -35,4 +55,16 @@ public function outputExtension() { return '.pdf'; } + + /** + * @return string + */ + public function generate() + { + $this->output_file_extension = $this->outputExtension(); + + return $this->shellExec(); + } + + } \ No newline at end of file diff --git a/src/PopplerPhp/PopplerUtil.php b/src/PopplerPhp/PopplerUtil.php index 57bd9b7..bcb65a5 100644 --- a/src/PopplerPhp/PopplerUtil.php +++ b/src/PopplerPhp/PopplerUtil.php @@ -22,6 +22,7 @@ abstract class PopplerUtil { protected $bin_file; protected $output_file_extension; + protected $output_file_suffix = ''; protected $require_output_dir = true; private $binary_dir; private $flags = []; @@ -311,7 +312,7 @@ private function makeShellCommand() $output_path = H::parseDirName($directory.C::DS.$this->getOutputFilenamePrefix()); - $command[] = $q.$output_path.$this->output_file_extension.$q; + $command[] = $q . $output_path . $this->output_file_suffix . $this->output_file_extension . $q; } return implode(' ', $command); @@ -378,6 +379,19 @@ public function setOutputFilenamePrefix($name) throw new PopplerPhpException("Filename must be an alphanumeric string"); } + /** + * @param $name + * + * @return $this + * @throws PopplerPhpException + */ + public function setOutputFilenameSuffix($suffix = '') + { + $this->output_file_suffix = $suffix; + return $this; + } + + /** * @return mixed */