Ich muss PDF in PHP in Png konvertieren. Aus Qualitätsgründen möchten wir nicht Imagemagick verwenden, sondern bevorzugen pdftoppm.Konvertieren von PDF zu Bild mit pdftoppm in PHP ohne Dateien auf der Festplatte zu schreiben
Für die Leistung bevorzugen wir nicht das Dateisystem zu verwenden, sondern den Speicher.
pdftoppm ist ordnungsgemäß auf Ubuntu installiert und funktioniert.
Für ein anderes Projekt (html -> pdf) wir den folgenden Code verwenden:
//input is $html
$descriptorSpec =
[
0 => ['pipe', 'r'],
1 => ['pipe', 'w'],
2 => ['pipe', 'w']
];
$command = 'wkhtmltopdf --quiet - -';
$process = proc_open($command, $descriptorSpec, $pipes);
fwrite($pipes[0], $html);
fclose($pipes[0]);
$pdf = stream_get_contents($pipes[1]);
$errors = stream_get_contents($pipes[2]);
if ($errors)
{
$errors = ucfirst(strtr($errors, [
'sh: wkhtmltopdf: ' => '',
PHP_EOL => ''
]));
throw new Exception($errors);
}
fclose($pipes[1]);
$return_value = proc_close($process);
//output is $pdf
Das funktioniert perfekt!
Aber wenn ich diesen Code verwenden, um das gleiche mit pdftoppm zu tun, funktioniert es nicht, was mache ich falsch?
//input is $pdf
$descriptorSpec =
[
0 => ['pipe', 'r'],
1 => ['pipe', 'w'],
2 => ['pipe', 'w']
];
$command = 'pdftoppm -png - -';
$process = proc_open($command, $descriptorSpec, $pipes);
fwrite($pipes[0], $pdf);
fclose($pipes[0]);
$png = stream_get_contents($pipes[1]);
$errors = stream_get_contents($pipes[2]);
if ($errors)
{
$errors = ucfirst(strtr($errors, [
'sh: pdftoppm: ' => '',
PHP_EOL => ''
]));
throw new Exception($errors);
}
fclose($pipes[1]);
$return_value = proc_close($process);
//output is $png
Dank im Voraus für Tipps und sugestions Sorry für mein schlechtes Englisch ..