Skip to content

Commit

Permalink
Merge pull request #5 from langleyfoxall/feature/extra-arguments
Browse files Browse the repository at this point in the history
Allow additional arguments to be added.
  • Loading branch information
jameswilddev authored May 12, 2023
2 parents 84010f9 + ef8aae9 commit 0e2f70f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ A path to a Ghostscript executable can be passed into the `PdfStitcher` construc
new PdfStitcher('a/path/to/a/gs/executable')
```

### Additional Ghostscript arguments

Additional Ghostscript arguments can be passed into the `PdfStitcher` constructor:

```php
new PdfStitcher(null, '-dNEWPDF=false')
```

These will NOT be escaped in any way.

### Including only specific pages from a PDF

You may optionally give an array of page indices when adding a PDF:
Expand Down
13 changes: 12 additions & 1 deletion src/PdfStitcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,21 @@ class PdfStitcher
*/
private $overriddenGhostscriptExecutablePath = null;

private $extraGhostscriptArguments = null;

/**
* Creates a new instance of the PDF stitcher.
*
* @param ?string $overriddenGhostscriptExecutablePath A path to a Ghostscript executable to use instead of the default "gs".
* @param ?string $extraGhostscriptArguments Extra Ghostscript arguments to be included in any commands executed. No escaping will be performed.
*/
public function __construct($overriddenGhostscriptExecutablePath = null)
public function __construct(
$overriddenGhostscriptExecutablePath = null,
$extraGhostscriptArguments = null
)
{
$this->overriddenGhostscriptExecutablePath = $overriddenGhostscriptExecutablePath;
$this->$extraGhostscriptArguments = $extraGhostscriptArguments;
}

/**
Expand Down Expand Up @@ -135,6 +142,10 @@ private function getShellCommand($filePath): string
$command = $this->overriddenGhostscriptExecutablePath;
}

if ($this->extraGhostscriptArguments !== null) {
$command .= ' '.$this->extraGhostscriptArguments;
}

$command .= ' -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile='.Utils::quote($filePath).' ';
$command .= implode(' ', $this->arguments);

Expand Down

0 comments on commit 0e2f70f

Please sign in to comment.