How to generate low memory PDF on server?

7

I'm passing a table from my DB to PDF and I'm using TCPDF .

But first I have to move my table to HTML and then I can move to PDF, which leads to a lot of memory and I have few resources on the server (256M for PHP max ).

How can I pass a table that can have thousands of records to PDF with maximum 256M of memory in PHP?

    
asked by anonymous 25.07.2014 / 12:30

2 answers

1

I always use MPDF, in a matter of memory you can increase the maximum size of memory allocation in PHP with ini_set("memory_limit","120M"); or the size you find necessary, in terms of performance I can not make a comparison with these other classes for not having used others in any of my projects.

    
28.07.2014 / 20:33
1

I've had the same problem. I solved using Snappy that generates the PDF in a different way, using little memory.

The library can be found here .

Installing via composer:

$ composer require knplabs/knp-snappy

Requires Wkhtmltopdf and Wkhtmltoimage applications available for Windows Linux and OS X available here

Including and using the library in your project:

require __DIR__ . '/vendor/autoload.php';
use Knp\Snappy\Pdf;

//adicione o caminho para o seu wkhtmltopdf como no exemplo abaixo
$snappy = new Pdf('/usr/local/bin/wkhtmltopdf');

//configure a pasta temporária para salvar o arquivo
$snappy->generateFromHtml($html, '/tmp/arquivo.pdf');

//force o download do arquivo
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="file.pdf"');
readfile('/tmp/file.pdf);

In this link make the folder with the files available if you can not download. Extract the file and put the vendor folder and the wkhtmltox folder at the root of your project.

The path of wkhtmltopdf will be '__DIR__./wkhtmltox/bin/wkhtmltopdf'

    
06.09.2016 / 14:31