P
P
podust2015-01-22 11:19:06
PHP
podust, 2015-01-22 11:19:06

What is the correct way to pass text to PHP through stdin using popen()?

Trying to remove or change PDF metadata (author, title, etc.). I do it through the pdftk utility , and everything works fine. But the hitch happens in PHP. I want to implement such a simple algorithm without resorting to creating files on disk:
1. I get the PDF metadata and add them to an array:
exec("pdftk $pdffile dump_data output", $result);
2. I change the metadata in the array in the way I need.
3. I'm trying to submit this metadata under the guise of a text file, in the same form in which I received them:

$sh = popen("pdftk $pdffile update_info - output $resultpdf", "w");
fwrite( $sh, implode(PHP_EOL, $result) );
pclose($sh);

But the method doesn't work, the metadata in $resultpdf remains the same as before. Although in the terminal (using files) such a command works with a bang. Anticipating the question - yes, pdftk supports input via stdin.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Egor Kazantsev, 2015-01-25
@saintbyte

You don't need php - you need bash

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question