Question

I am using an application on my windows server called PDFtK which generates pdfs and you can merge data into them etc.

I am trying to get passthru to work so I can just output the pdf to the browser without saving anything to the folder.

This works perfectly fine for creating the PDF in the folder. However, I dont want to create the PDF, I need to output it to the browser.

$WshShell = new COM("WScript.Shell");
$WshShell->exec('"pdftk" C:\\inetpub\\wwwroot\\xx\\demos\\pdf\\uploads\\xxx.pdf fill_form C:\\inetpub\\wwwroot\\xx\\demos\\pdf\\uploads\\'.$fdf_file.' output C:\\inetpub\\wwwroot\\xx\\demos\\pdf\\uploads\\'.$newPDF.' flatten'); 

Here is what I then tried:

header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="download.pdf"');
$WshShell = new COM("WScript.Shell");
$WshShell->passthru('"pdftk" C:\\inetpub\\wwwroot\\xx\\demos\\pdf\\uploads\\xxx.pdf fill_form C:\\inetpub\\wwwroot\\xx\\demos\\pdf\\uploads\\'.$fdf_file.' output -'); 

I then get this error when running it:

Call to undefined method com::passthru()

Is there a way to test is passthru is working correctly?

Was it helpful?

Solution

The function passthru() doesn't exist in the class COM. A possible solution would be, to write the pdf file (using COM::exec()), read it with file_get_contents('filename.pdf'), output the content and then delete it with php @unlink('filename.pdf').

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top