Generate PDF by PHP? [duplicate]

0

I was able to generate the ticket on my site along with the BoletoPHP project, and the bank's data.

Now, when it's going to print to CHROME it goes out with the wrong barcode, that's until a reported issue: link .

Curious fact is that it's just in chrome. Thinking of an alternative, I thought of Save to PDF, and then opened by Acrobat and it worked.

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

    
asked by anonymous 09.06.2017 / 19:48

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's 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 just display that line of code at the end.

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

This example will remove from here: link

    
16.07.2018 / 16:37