Generate PDF from PHP?

Asked

Viewed 1,148 times

0

I managed to generate the boleto in my site along with the project Boletophp, and the database data.

Now, when it goes to print on CHROME it comes out with the wrong barcode, this is up to a reported Issue: https://github.com/CobreGratis/boletophp/issues/103.

Curious fact is that it’s only on Chrome. Thinking of an alternative, I thought of saving in PDF, and then open by Acrobat and it worked.

As I can, when generating the PDF on the PHP page already download the file as PDF instead of simply displaying it? If this is not possible, if anyone has any other viable idea/alternative and that helps I thank you

1 answer

1

Hello, As Leonardo has already said, the FPDF will solve your case. It is easy to use and has plenty of tutorial on the internet. Here is an example:

require_once("fpdf/fpdf.php");
$pdf= new FPDF("P","pt","A4");
$pdf->AddPage();

$pdf->SetFont('arial','B',18);
$pdf->Cell(0,5,"Relatório",0,1,'C');
$pdf->Cell(0,5,"","B",1,'C');
$pdf->Ln(50);

//cabeçalho da tabela 
$pdf->SetFont('arial','B',14);
$pdf->Cell(130,20,'Coluna 1',1,0,"L");
$pdf->Cell(140,20,'Coluna 2',1,0,"L");
$pdf->Cell(130,20,'Coluna 3',1,0,"L");
$pdf->Cell(160,20,'Coluna 4',1,1,"L");

//linhas da tabela
$pdf->SetFont('arial','',12);
for($i= 1; $i <10;$i++){
$pdf->Cell(130,20,"Linha ".$i,1,0,"L");
$pdf->Cell(140,20,rand(),1,0,"L");
$pdf->Cell(130,20,rand(),1,0,"L");
$pdf->Cell(160,20,rand(),1,1,"L");
}
$pdf->Output("arquivo.pdf","D");

And to download instead of display just put that line of code at the end.

$pdf->Output("arquivo.pdf","D");

That example I took from here: http://www.botecodigital.info/php/criando-arquivos-pdf-com-php-e-classe-fpdf/

Browser other questions tagged

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