I'm trying to use FPDF and FPDI to edit a PDF and add text to it. I keep getting an "Incorrect output destination" error but the destination is the correct location that I want it to create a file in, why does FPDF not like my output destination?
This is in a laravel project
$pdf = new \setasign\Fpdi\Fpdi();
$pdf->AddPage();
$pdf->setSourceFile(public_path('/pdf/higher.pdf'));
$tplIdx = $pdf->importPage(1);
$pdf->useTemplate($tplIdx, 10, 10, 100);
$pdf->SetFont('Helvetica');
$pdf->SetTextColor(255, 0, 0);
$pdf->SetXY(30, 30);
$pdf->Write(0, 'This is just a simple text');
$pdf->Output(public_path('/pdf/'),'higher2');
return $pdf;
and the error is:
message: "FPDF error: Incorrect output destination: /home/vagrant/code/project-name/public/pdf/"
I've also tried removing the "public_path()" and just setting it to Output('pdf', 'higher2')
and no good there either.
Furthermore I've also tried changing the name of the output pdf to higher2.pdf
just in case it wanted to see the extension (but obviously it's having more of a problem with the destination and not the name)
I've even tried changing permissions on this folder to be writable by anyone:
drwxrwxrwx 5 ion staff 160 May 21 05:44 pdf
edit: Just to note I see that the method with the public_path() is trying to save to my vagrant folder for some reason, that's part of the reason I'm confused. When I try to save to '/pdf' without public_path(), I get this error:
message: "FPDF error: Incorrect output destination: /pdf/"
edit 2:
I've also tried this:
$pdf->Output('F','/pdf/higher2.pdf');
and got the error:
message: "file_put_contents(/pdf/higher2.pdf): failed to open stream: No such file or directory"
and also tried the original name of the pdf which definitely exists and got the same error:
$pdf->Output('F','/pdf/higher.pdf');
Output('F', '/higher2.pdf')
but wouldn't work if I set it to ``Output('F', '/pdf/higher2.pdf') Thank you! As for editing I just meant I'm adding text over it using FPDI – Snooty