Mubeenali's avatar

how to configure setasign/fpdi-fpdf in config/app.php ?

I have installed this package composer require setasign/fpdi-fpdf in my laravel application.but i am unable to use this package in controller.My Question is pretty simple what to do in config/app.php so that i can use it in my controller .?Please help me.

0 likes
7 replies
Sinnbeck's avatar

You dont need to do anything. Just add a use in the top, and then new it up

use setasign\Fpdi\Fpdi;

//and inside the method
$pdf = new Fpdi();
//do stuff
return $pdf->Output();
Mubeenali's avatar

after your code it is giving me something like that

%PDF-1.3 3 0 obj <> endobj 4 0 obj <> stream x�3R��2�35W(�� endstream endobj 1 0 obj <> endobj 2 0 obj << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI] /Font << >> /XObject << >> >> endobj 5 0 obj << /Producer (FPDF 1.82) /CreationDate (D:20191217150726) >> endobj 6 0 obj << /Type /Catalog /Pages 1 0 R >> endobj xref 0 7 0000000000 65535 f 0000000175 00000 n 0000000262 00000 n 0000000009 00000 n 0000000087 00000 n 0000000356 00000 n 0000000432 00000 n trailer << /Size 7 /Root 6 0 R /Info 5 0 R >> startxref 481 %%EOF

How to set content type application/pdf via this package ?

Mubeenali's avatar

thanks @sinnbeck actually i am trying to edit an existing file on run time.Below is my code but i could not.The page maximum load time exceeds but it don not return any output to me.


     //and inside the method
      $pdf = new Fpdi();
 // add a page
      $pdf->AddPage();
     // set the source file
      $pdf->setSourceFile(asset("assets/quotation/quotation.pdf"));
     // import page 1
      $tplIdx = $pdf->importPage(1);
     // use the imported page and place it at position 10,10 with a width of 100 mm
      $pdf->useTemplate($tplIdx, 10, 10, 100);

        // now write some text above the imported page
        $pdf->SetFont('Helvetica');
        $pdf->SetTextColor(255, 0, 0);
        $pdf->SetXY(30, 30);
        $pdf->Write(0, 'This is just a simple text');


    //  $pdf->addPage();
    //  $pdf->useImportedPage($pageId, 10, 10, 90);


        return response($pdf->Output())
            ->header('Content-Type', 'application/pdf');

Please or to participate in this conversation.