1 | <?php |
||
7 | class Ghostscript implements CanRegeneratePDF |
||
8 | { |
||
9 | /** |
||
10 | * Ghostscript binary path. |
||
11 | */ |
||
12 | private string $bin; |
||
|
|||
13 | |||
14 | public function __construct(string $bin = 'ghostscript') |
||
15 | { |
||
16 | $this->bin = $bin; |
||
17 | } |
||
18 | |||
19 | /** |
||
20 | * Generates a temporary filename for a PDF file. |
||
21 | * |
||
22 | * @return string |
||
23 | */ |
||
24 | private static function tempFile(): string |
||
25 | { |
||
26 | return tempnam(sys_get_temp_dir(), 'ghostscript') . '.pdf'; |
||
27 | } |
||
28 | |||
29 | /** |
||
30 | * {@inheritdoc} |
||
31 | */ |
||
32 | public function regeneratePdf(string $pdfContents): string |
||
33 | { |
||
34 | file_put_contents($input = static::tempFile(), $pdfContents); |
||
35 | |||
36 | (new Process([ |
||
37 | $this->bin, |
||
38 | '-sDEVICE=pdfwrite', |
||
39 | '-dPDFSETTINGS=/prepress', |
||
50 |