tecnickcom / TCPDF

Official clone of PHP library to generate PDF documents and barcodes
https://tcpdf.org
Other
4.1k stars 1.51k forks source link

Blank page while trying to generate PDF #557

Open madsongr opened 1 year ago

madsongr commented 1 year ago

I recently installed using composer and it was generating pdf as expected. But for some reason it stopped working and it displays a blank page using $pdf->Output(); while testing on browser and no file is generated if I specify file name and directory.

And it doesn't work even if I try to execute some of the examples files from examples folder.

Here is part of my script:

<?php

require_once __DIR__ . '/vendor/autoload.php';

class CustomPdfGenerator extends TCPDF
{
    public function Header()
    {
        $contact = './images/description.PNG';
        $this->Image($contact, 118, 5, "", 25, 'PNG', '', 'T', false, 300, '', false, false, 0, false, false, false);
        $logo = './images/imgs.png';
        $this->Image($logo, 8, 7, "", 20, 'PNG', '', 'T', false, 300, '', false, false, 0, false, false, false);
        $this->SetFont('helvetica', 'B', 20);
        $this->Cell(0, 15, '', 0, false, 'C', 0, '', 0, false, 'M', 'M');
        $this->Ln(110, false);
    }
}

$pdf = new CustomPdfGenerator(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
$pdf->SetMargins(10, PDF_MARGIN_TOP, 10);
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
$pdf->setFontSubsetting(true);
$pdf->SetFont('helvetica', '', 12, '', true);

$pdf->AddPage();
$pdf->Ln(10, false);
$pdf->Write(0, "\n", '', 0, 'L', false, 0, false, false, null);

$pdf->writeHTML("<b>Text text text textText text text textText text text text</b>", true, false, false, false, "L");
$pdf->Ln(0, false);
$pdf->writeHTML("Text text text text", false, false, false, false, "L");
$pdf->Write(0, "\n", '', 0, 'L', false, 0, false, false, null);

// $pdf->Output(__DIR__ . '/files/teste.pdf', 'F');
$pdf->Output();

Does it work fine with php 8.0?

madsongr commented 1 year ago

Apparently it works fine if I change php to 8.1

williamdes commented 1 year ago

Thank you for the script, I will (probably) try to create an example file in examples/ to reproduce it. You may open a PR for it