Closed sandy0201 closed 8 years ago
Push the force download http headers to the browser?
On Dec 8, 2015, at 4:02 AM, Sandy Lin notifications@github.com wrote:
Hi,
Is there a way to render the PDF file for download after combining/merging several PDF/DOC/DOCX files into one PDF file? Or is there any possible way to integrate pdftk with mpdf?
Thank you. Kind regards.
— Reply to this email directly or view it on GitHub.
I'm using this extension in Yii2 framework, therefore not sure if it's possible to do that? Is it possible for you to give an example?
@sandy0201 Have you seen the send()
method?
https://github.com/mikehaertl/php-pdftk/blob/master/src/Pdf.php#L499
@mikehaertl I have seen it, but not quite sure how I should use it. For example: Example link: http://inspirationlab.git/curriculum-vitae/download?id=33 If I have it in a function called actionDownload($id), should it be: return $pdf->send('attachments.pdf', false); or just, $pdf->send('attachments.pdf', false);
Just $pdf->send(...)
. Make sure, that you don't render any other output in that case.
@mikehaertl Below is a code snippet of how I did it, will this work? Because when I test it, the page is just blank (see below screenshot).
$path = '../uploads/curriculum-vitae/user/attachments/'; $files = FileHelper::findFiles($path); $attachments = array(); if (isset($files[0])) { foreach ($files as $index => $file) { $fileName = substr($file, strrpos($file, '/') + 1); array_push($attachments, $path.$fileName); } }
$pdf = new Pdf($attachments); $pdf->cat(1, 'end', '0') ->cat(1, 'end', '1') ->cat(1, 'end', '2') ->saveAs('attachments.pdf');
$pdf->send('attachments.pdf', true);
Maybe start with a simple example first. I can't say if your code works. But if there's no output, you could check for an error:
if ($pdf->send(..)===false) {
$error = $pdf->getError();
}
Okay, I tried to check for an error, below is what displays: Failed without error message: pdftk 0="../uploads/curriculum-vitae/94/attachments/\16076970141445979317.pdf" 1="../uploads/curriculum-vitae/94/attachments/\16486317671444304282.pdf" 2="../uploads/curriculum-vitae/94/attachments/\1762541641445982047.pdf" cat 01-end 11-end 21-end output "C:\Users\Sandy Lin\AppData\Local\Temp\tmp9585.tmp.pdf"
Not really clear in terms of what the error is or why it failed.
You've used invalid keys (array keys) for your pdf files: 0, 1, 2... You must use A, B, C, ... because that's what pdftk expects.
Even using the letters as keys, I still get the error:
Then pdftk
is probably not in your search path. Please check the bottom of the README for how to configure that.
How can I access the path to pdftk that's outside in the root directory? If I add '..' in front of '/', it gives an error like below. If I remove '..', it says that the system can't find the path.
$pdf = new Pdf($combinedArr, [ 'command' => '../vendor/mikehaertl/php-pdftk', 'useExec' => true, ]); '..' is not recognized as an internal or external command, operable program or batch file.
$pdf = new Pdf($combinedArr, [ 'command' => '/vendor/mikehaertl/php-pdftk', 'useExec' => true, ]); The system cannot find the path specified.
This is the wrong path. You need to install the pdftk binary on your system. That's not part of this library. Then you need to configure the path to the executable under command.
Oh okay cool, now I understand. But does that mean every computer that accesses the link on the site will have to have Pdftk installed on their machine? Is there no other way to go around this?
Not sure what you mean. Of course pdftk only has to be installed on the server.
I'm closing this as there's no bug in the library.
Okay cool. Thank you for your help.
Hi,
Is there a way to render the PDF file for download after combining/merging several PDF/DOC/DOCX files into one PDF file? Or is there any possible way to integrate pdftk with mpdf?
Thank you. Kind regards.