Reputation: 29079
I want to use tFPDF in Laravel 5.5. I added the package with composer and then I tried to output it the according to the docs but nothing worked.
I tried to output it directly to the browser:
Route::get('/test',function(){
$pdfLibrary = new tFPDF\PDF();
$pdfLibrary->AddPage();
$pdfLibrary->AddFont('DejaVuSansCondensed', '', 'DejaVuSansCondensed.ttf', true);
$pdfLibrary->SetFont('DejaVuSansCondensed', '', 14);
$pdfLibrary->Write(8, 'Hallo!');
$pdfLibrary->output();
});
but the sceen was just blank. When I tried return $pdfLibrary->output();
then it just returned
%PDF-1.3 3 0 obj <> endobj 4 0 obj <> stream x�u�� �@S�)>+�p�.......
I also tried to simply save the pdf to a file, but even
$pdfLibrary->output('F', storage_path() . '/test.pdf');
did not work.
How can I save & output the pdfs created by tFPDF ?
Upvotes: 2
Views: 1105
Reputation: 29079
I found another package from SetASign which is just want I wanted. Simple tFPDF
packge with namespace support. This works out of the box and is amazing.
I would strongly recommend to use the SetASing package over the DocNetUk package, because the DocNetUK package has just to many quirks. Here are some of the issues that I had using the DocNetUK package:
tFPDF
was changed to __construct
, so you have to call parent::construct
in your constructor each time, which was necessary because of the namespacing(see What's difference between __construct and function with same name as class has?)$this->w
=>$this->flt_current_width
$this->h
=>$this->flt_current_height
These changes make the version from DocNetUK incompatible with basically all add-ons.
*Outdated answer
I finally realized that the unofficial composer version of tFPDF changed slightly the behavior of the output
function. The output functions just returns the pdf content, but cannot save it to a file nor render it directly in the browser.
This is how to display raw binarys as a pdf in Laravel
\Response::make($this->output(), 200, ['content-type'=>'application/pdf', 'Content-Disposition' => 'inline; temp.pdf']);
Saving raw binaries goes like this:
Storage::put('file.pdf', $pdfLibrary->output());
or file_put_contents
if one is not using Laravel.
Upvotes: 2