mikehaertl/php-pdftk

File doesn't get saved to the path provided !

senuradp opened this issue · 3 comments

Hi, I used pdf-tk to merge 2 pdf documents and when I try to save it, it doesn't get saved to the path provided. I have attached the code I have used, below. Your help would be highly appreciated. TIA.

            $pdfTk = new PdfTk($pdf1, $pdf2);

            $now = DateTime::createFromFormat('U.u', microtime(true));

            $fileName = 'merged_' . $now->format('Y-m-d H:i:s.u') . '.pdf';

            $pdfTk->saveAs(public_path('letters/' . $fileName));

            return APIHelper::makeAPIResponse(true, 'Files merged successfully', 'letters/merge.pdf', 200 );

You have not called any operation. In your case you need to add cat().

You should also check the return value of saveAs() and if it's false check for errors with getError().

You have not called any operation. In your case you need to add cat().

You should also check the return value of saveAs() and if it's false check for errors with getError().

Hi, thank you for your prompt response!

If possible could you please point out the place where I should add cat() ?

And... the return value is false :|

php-pdftk/src/Pdf.php

Lines 157 to 160 in c856d2d

* $files = ['file1.pdf', 'file2.pdf', 'file3.pdf'];
* $pdf = new Pdf($files);
* $pdf->cat() // all files, all pages
* ->saveAs('out.pdf');

Sorry, I can not provide more help than this. Please check the manual and study the code to get a better understanding.