Generating PDF with Laravel

Asked

Viewed 461 times

-1

I’m trying to implement this pdf lib for my Laravel project: https://tcpdf.org/. Since I’m having problems in the implementation, because its documentation is not very clear with the method I need to use to create a PDF.

  • What problems? Do you have any code ? I suggest that instead of using the original lib, use a version adapted for Laravel, see that.

  • Um, the methods to implement are unclear. My pdf will contain data from an order session, this integrating with QRCODE, and the problem is the PDF, how to generate it.

2 answers

1

To implement, as you are using a framework, I would suggest installing through Composer.

First, add to composer.json the dependency of TCPDF:

"require": {
    // Aqui terá todas as dependencias do Laravel, coloque em baixo o tcpdf.
    "tecnickcom/tcpdf": "^6.2.13"
}

Then execute the command composer install if there is the file composer.lock, otherwise, use composer update.

To use TCPDF, it would look something like this:

<?php
// Acredito que não será necessário a etapa abaixo, mas faça o teste com ou sem.
require __DIR__ . '/vendor/autoload.php';

$pdf = new TCPDF();
$pdf->AddPage();
$pdf->Write(1, 'Hello world');

$pdf->Output('hello_world.pdf');

?>

Original source

Examples of how to use the library here.

  • https://blog.especializati.com.br/gerar-pdf-no-laravel-com-dompdf/

0

I recommend using Dompdf, which is already widely accepted and used in the Laravel community.

In addition, it is easy to install and has great documentation.

Worth checking out: https://github.com/barryvdh/laravel-dompdf

Browser other questions tagged

You are not signed in. Login or sign up in order to post.