Generate PDF by PHP? [duplicate]
I managed to generate the boleto on my website along with the BoletoPHP project, and the bank data.
Now when it goes to print on CHROME it comes out with the wrong barcode, that's up to an issue reported: https://github.com/CobreGratis/boletophp/issues/103 .
Curious fact is that it's only in chrome. Thinking of an alternative, I thought to save to PDF, and then open by Acrobat and it worked.
How do I manage, when generating the PDF on the page in PHP already download the file as PDF instead of simply displaying it? if this is not possible, if anyone has any other viable idea / alternative that helps I thank
1 answers
Hello, As Leonardo already said, the FPDF will solve your case. It is easy to use and has a lot 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");
This example I removed from here: http://www.botecodigital.info/php/criando-arquivos-pdf-com-php-e-classe-fpdf /