We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38285
    • 17 Posts
    I'm using MODx revolution 2.2.1-PL and FPDF to generate some PDFs. I've found that using any images over 100kb (at least around that ballpark) results in them being corrupted in the outputted PDF. It's almost as if the image is still half way through downloading when it is written to the PDF.

    This is my snippet which I output onto a page with a blank template:

    require_once($modx->config['base_path']."assets/fpdf/fpdf.php");

    define('FPDF_FONTPATH',$modx->config['base_path']."assets/fpdf/font/");

    $pdf=new FPDF();
    $pdf->AddPage();
    $pdf->AddFont('novecentowidedemibold','','novecentowidedemibold.php');
    $pdf->SetFont('novecentowidedemibold','',16);
    $pdf->Cell(40,10,'Dealer Application');
    $pdf->Image('assets/img/pdf/image.jpg',0,0,-300);
    $pdf->Output("myfile.pdf", D);

    It finds fonts and everything OK, it's just the image that isn't working correctly. If I use a smaller image (filesize), it works.

    If I take this code and execute on the same server but not within MODx the outputted PDF works perfectly regardless of image file size.

    Is there something I can do to make sure the image is fully downloaded before the PDF is generated?
      • 3749
      • 24,544 Posts
      It might be a PHP timeout issue. In the typical install, PHP has around 30 seconds to execute a script. Could you be going over that?

      You might try putting this at the top of the snippet:

      set_time_limit(0)




      ------------------------------------------------------------------------------------------
      PLEASE, PLEASE specify the version of MODX you are using.
      MODX info for everyone: http://bobsguides.com/modx.html
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 46315
        • 30 Posts
        Hi allhailtom

        I know this was posted a while back but did you ever find a solution for this as I'm experiencing the same problem.

        Small image file sizes work fine, as soon as they are greater than 100kb then the image doesn't render. I've included three images, two under 100kb the third 172kb, all images render except the larger.

        Executing the same code outside of modx on same server works perfectly.

        Many thanks.