Menu

#851 Problem with images in PDF. PHP timing out

v1.0_(example)
closed
nobody
None
1
2015-02-13
2013-10-19
Adam S
No

In response to closed ticket #850.

Having a problem with a header image on CentOS 5.9 running PHP 5.4.19 with GD and Imagick and the latest TCPDF installed. I can reproduce this problem on two boxes of the same specs. Works fine on my Mac.

The problem is when I try to run the PDF, the page takes forever to load then white screens.

[Fri Oct 18 15:46:33 2013] [error] [client 70.62.126.50] PHP Fatal error:  Maximum execution time of 30 seconds exceeded in /home/asentner/sabackoffice/vendor/tcpdf/tcpdf.php on line 7189
[Fri Oct 18 16:11:03 2013] [error] [client 70.62.126.50] PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 130968 bytes) in /home/asentner/sabackoffice/vendor/tcpdf/tcpdf.php on line 7255

I upped the memory to 2048mb and the memory error went away. I changed the post time to 90 and it just generated more garbage in /tmp and still timedout.

I noticed that the one page load generates thousands of files prefixed mska_ and thousands more prefixed mskp in the /tmp directory which all appears to be my one image.

What are the mska and mskp temp files for? Is there an alternate way to use the image?

The library is unusable.

I can reproduce with example 003 (Custom header footer) using a custom header (see below) on any CentOS system running 5.9 with PHP 5.4 (Please see above for exact versions).

class BackofficeReportService extends TCPDF {
    var $printedBy;
    var $date;

    // Custom constructor
    public function __construct($orientation='P', $unit='mm', $format='A4', $unicode=true, $encoding='UTF-8', $diskcache=false, $pdfa=false) {
        parent::__construct($orientation, $unit, $format, $unicode, $encoding, $diskcache, $pdfa);
        $this->SetAuthor("BackOffice/".VERSION);
    }

    // Set Header Data
    public function setPrintedBy($name) {
        $this->printedBy = $name;
    }

    public function setDate($date) {
        $this->date = $date;
    }

    //Page header
    public function Header() {
        $this->SetFont('helvetica', 'B', 20);
        // Title
        $this->Cell(0, 10, $this->title, 0, false, 'C', 0, '', 0, false, 'C', 'C');
        $this->Ln();
        $this->SetFont('helvetica', '', 10);
        $this->Cell(0, 5, "Printed By: ".$this->printedBy, 0, false, 'C', 0, '', 0, false, 'C', 'T');
        $this->Ln();
        $this->SetFont('helvetica', '', 10);
        $this->Cell(0, 5, "Date: ".$this->date, 0, false, 'C', 0, '', 0, false, 'C', 'T');
        // Logo
        $image_file = $_SERVER['BACKOFFICE_ROOT'].'/htdocs/assets/img/logo.png';
        $this->Image($image_file, 15, 9, '40', '', 'PNG', '', 'T', false, 300, '', false, false, 0, false, false, false);
        //$style = array('width' => 0.25, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0));
        $this->Line(15, 23, 195, 23, array('width' => 0.25));
    }

    // Page footer
    public function Footer() {
        // Position at 15 mm from bottom
        $this->SetY(-15);
        // Set font
        $this->SetFont('helvetica', 'I', 8);
        // Page number
        $this->Line(15, 282, 195, 282, array('width' => 0.25));
        $this->Cell(0, 10, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
    }
}

Please don't close this ticket. I really like this library and would like to get this working. If you need something from me, let me know.

1 Attachments

Discussion

  • Adam S

    Adam S - 2013-10-19

    I can give you shell access if you need it as well.

     
  • Adam S

    Adam S - 2013-10-19

    After further review, I commented out the image and it did not resolve the problem. It seems it has nothing to do with the image but this issue with the tmp folder is alarming. Is it getting stuck in a loop somewhere?

    Oh, and here is the code calling the class:

    $pdf = new BackofficeReportService(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    
    // set document information
    $pdf->SetTitle('Test Report');
    $pdf->SetSubject('Testing the pdf report library');
    $pdf->setPrintedBy($session->getUser('first_name').' '.$session->getUser('last_name'));
    $pdf->setDate($localDate->format($backoffice['date_format'].' '.$backoffice['time_format']));
    
    
    // set default header data
    $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
    
    // set header and footer fonts
    $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
    $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
    
    // set default monospaced font
    $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
    
    // set margins
    $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
    $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
    $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
    
    // set auto page breaks
    $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
    
    // set image scale factor
    $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
    
    // set some language-dependent strings (optional)
    if ($_SERVER['BACKOFFICE_ROOT'].'/vendor/tcpdf/examples/lang/eng.php') {
        require_once($_SERVER['BACKOFFICE_ROOT'].'/vendor/tcpdf/examples/lang/eng.php');
        $pdf->setLanguageArray($l);
    }
    
    // ---------------------------------------------------------
    
    // set font
    $pdf->SetFont('times', 'BI', 12);
    
    // add a page
    $pdf->AddPage();
    
    $columns = array(
        0 => array('width'=>60, 'header'=>'Column 1'),
        1 => array('width'=>60, 'header'=>'Column 2'),
        2 => array('width'=>60, 'header'=>'Column 3'),
    );
    for ($i = 1; $i <= 420; $i++) {
        $data[] = array(100+$i, 200+$i, 300+$i);
    }
    
    $pdf->DataTable($columns,$data);
    
    // print a block of text using Write()
    //$pdf->Write(0, $txt, '', 0, 'C', true, 0, false, false, 0);
    
    // ---------------------------------------------------------
    
    //Close and output PDF document
    $pdf->Output('test.pdf', 'I');
    
     

    Last edit: Adam S 2013-10-19
  • Nicola Asuni

    Nicola Asuni - 2013-10-19

    If this issue has nothing to do with the images than this bug should be closed.
    Please note that this is is not the place to ask for custom support.
    If you think that TCPDF contains a bug, please provide a very simple example to reproduce it because I do not have time to debug custom code.

     
  • Adam S

    Adam S - 2013-10-19

    The examples (http://www.tcpdf.org/examples.php) do not work either (none of them). Please read the description. PHP is timing out. It has something to do with the library on a system with the specs provided (Enterprise Linux 5, very common among hosts). The library even using the examples provided on your site, cause PHP to time out. I find it odd that you think a pdf with an image (including example 003) creates thousands of temp files in the temp directory is not a bug but something that should be posted in the forum. This is a problem with TCPDF. Is this library no longer maintained? Is PHP 5.4 supported? If you are not interested in fixing this fatal issue, we'll find something else. I'd hate to do it, the library should do everything we need it to should we get this working. Now I ask, are you willing to help us out? I'll even give the project a donation if you willing to fix this issue to get us up and running. I really like this library. Thank you for putting the time you have this far.

     

    Last edit: Adam S 2013-10-19
  • Nicola Asuni

    Nicola Asuni - 2013-10-19

    Unfortunately I am unable to reproduce your issue.
    It can be a problem related to the imagick or gd libraries.
    Would you please provide the exact verion of PHP, imagick and gd version you are using?

     
  • Nicola Asuni

    Nicola Asuni - 2013-10-20

    OK. This should be fixed in TCPDF 6.0.040.
    Thank you for reporting this issue.
    Please comment here if this solution doesn't work for you.

     
  • Nicola Asuni

    Nicola Asuni - 2013-10-20
    • status: open --> closed
     
  • Adam S

    Adam S - 2013-10-21

    Unfortunately the latest did not. The tmp is now full of a ton of __tcpdf_imgmask_alpha_ and __tcpdf_imgmask_plain_ files and the page times out.

    Here are the version numbers:

    PHP 5.4.19 Running on Apache 2.2.3 as DSO
    imagick Module version: 3.1.2
    Image Magic Library Version: 6.2.8 05/07/12 (Stock shipped with OS)
    GD: bundled (2.1.0 compatible)
    libPNG: 1.2.10
    Freetype: 2.2.1

     

    Last edit: Adam S 2013-10-21
  • Nicola Asuni

    Nicola Asuni - 2013-10-21

    OK. This should be now fixed on TCPF 6.0.041.
    Please try it and let me know if it works for you.

     
  • Adam S

    Adam S - 2013-10-22

    Great! The latest release fixes it. Thanks!

     

Log in to post a comment.

MongoDB Logo MongoDB