@@ -27,7 +27,7 @@ public function __construct(
2727 */
2828 public function fillForm (string $ pdfFilePath , string $ formDataFilePath , bool $ flatten = false ): string
2929 {
30- $ executablePath = $ this ->executablePath ?? $ this -> findExecutablePath ();
30+ $ executablePath = $ this ->getExecutablePath ();
3131
3232 $ command = [$ executablePath , $ pdfFilePath , 'fill_form ' , $ formDataFilePath , 'output ' , '- ' ];
3333
@@ -55,7 +55,7 @@ public function fillForm(string $pdfFilePath, string $formDataFilePath, bool $fl
5555 */
5656 public function dumpDataFields (string $ pdfFilePath , bool $ utf8 = true ): array
5757 {
58- $ executablePath = $ this ->executablePath ?? $ this -> findExecutablePath ();
58+ $ executablePath = $ this ->getExecutablePath ();
5959
6060 $ operation = $ utf8 ? 'dump_data_fields_utf8 ' : 'dump_data_fields ' ;
6161
@@ -143,7 +143,7 @@ public function dumpDataFields(string $pdfFilePath, bool $utf8 = true): array
143143 */
144144 public function cat (string ...$ pdfFilePaths ): string
145145 {
146- $ executablePath = $ this ->executablePath ?? $ this -> findExecutablePath ();
146+ $ executablePath = $ this ->getExecutablePath ();
147147
148148 $ command = [$ executablePath ];
149149
@@ -175,7 +175,7 @@ public function cat(string ...$pdfFilePaths): string
175175 */
176176 public function dumpData (string $ pdfFilePath , bool $ utf8 = true ): Report
177177 {
178- $ executablePath = $ this ->executablePath ?? $ this -> findExecutablePath ();
178+ $ executablePath = $ this ->getExecutablePath ();
179179
180180 $ operation = $ utf8 ? 'dump_data_utf8 ' : 'dump_data ' ;
181181
@@ -317,7 +317,7 @@ public function dumpData(string $pdfFilePath, bool $utf8 = true): Report
317317 */
318318 public function generateFdf (string $ pdfFilePath ): string
319319 {
320- $ executablePath = $ this ->executablePath ?? $ this -> findExecutablePath ();
320+ $ executablePath = $ this ->getExecutablePath ();
321321
322322 $ command = [$ executablePath , $ pdfFilePath , 'generate_fdf ' , 'output ' , '- ' ];
323323
@@ -342,7 +342,7 @@ public function generateFdf(string $pdfFilePath): string
342342 */
343343 public function burst (string $ pdfFilePath , string $ outputDir = null , string $ pageNamePrefixOutput = 'page_ ' ): void
344344 {
345- $ executablePath = $ this ->executablePath ?? $ this -> findExecutablePath ();
345+ $ executablePath = $ this ->getExecutablePath ();
346346
347347 $ outputDir ??= sys_get_temp_dir ();
348348
@@ -356,8 +356,62 @@ public function burst(string $pdfFilePath, string $outputDir = null, string $pag
356356 }
357357 }
358358
359- private function findExecutablePath (): string
359+ /**
360+ * Removes compression from a PDF file to create an uncompressed version.
361+ *
362+ * @param string $pdfFilePath Filepath to the input PDF file to be uncompressed.
363+ *
364+ * @return string Uncompressed PDF content.
365+ */
366+ public function uncompress (string $ pdfFilePath ): string
360367 {
368+ $ executablePath = $ this ->getExecutablePath ();
369+
370+ $ command = [$ executablePath , $ pdfFilePath , 'output ' , '- ' , 'uncompress ' ];
371+ ;
372+
373+ $ process = new Process ($ command );
374+ $ process ->run ();
375+
376+ if (false === $ process ->isSuccessful ()) {
377+ throw new ProcessFailedException ($ process );
378+ }
379+
380+ return $ process ->getOutput ();
381+ }
382+
383+ /**
384+ * Compresses the specified PDF file and returns the compressed output.
385+ *
386+ * @param string $pdfFilePath The file path of the PDF to be compressed.
387+ *
388+ * @return string The compressed content of the PDF file.
389+ *
390+ * @throws ProcessFailedException If the compression process fails.
391+ */
392+ public function compress (string $ pdfFilePath ): string
393+ {
394+ $ executablePath = $ this ->getExecutablePath ();
395+
396+ $ command = [$ executablePath , $ pdfFilePath , 'output ' , '- ' , 'compress ' ];
397+ ;
398+
399+ $ process = new Process ($ command );
400+ $ process ->run ();
401+
402+ if (false === $ process ->isSuccessful ()) {
403+ throw new ProcessFailedException ($ process );
404+ }
405+
406+ return $ process ->getOutput ();
407+ }
408+
409+ private function getExecutablePath (): string
410+ {
411+ if (null !== $ this ->executablePath ) {
412+ return $ this ->executablePath ;
413+ }
414+
361415 $ executableFinder = new ExecutableFinder ();
362416 $ executablePath = $ executableFinder ->find ('pdftk ' );
363417
0 commit comments