0

I am trying to generate bulk invoices (for printing) in the same PDF by using tcpdf library. The problem is that if there are too many (over 50 pages ) to generate the server will crash with this error.

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 72 bytes) in /home/user/public_html/lib/tcpdf/tcpdf.php on line 16680

So i can see that the max memory limit on my account is 335544320 bytes. I tried using ini_set('memory_limit', '-1'); but it cannot pass 335544320 bytes. On my localhost is working OK because i have all the memory_limit available.

So the question is how can fix this in order to work. To see or download the PDF containing all the invoices. I was thinking if this cannot be done because of the memory problem, to save each PDF in a folder and then zip and download the folder.

Alex
  • 1,033
  • 4
  • 23
  • 43
  • 1
    You answered your own question - if you can flush your memory by dumping data into individual files on the local file storage and then use `ZipArchive` to put them all together, it works easily. – sjagr Dec 11 '14 at 15:13
  • @sjagr While it would work to open each pdf and print it individualy, it's not ideal. – Marek Dec 11 '14 at 15:25

1 Answers1

0

TCPDF's contructor has $diskcache parameter:

/**
 * @param $diskcache (boolean) If TRUE reduce the RAM memory usage by caching temporary data on filesystem (slower).
*/
public function __construct($orientation='P', $unit='mm', $format='A4', $unicode=true, $encoding='UTF-8', $diskcache=false, $pdfa=false)

Another option is to create individual pages/invoices as separate pdf files, and then merge them using any solution you have available. See Merge pdf files with php.

Community
  • 1
  • 1
Marek
  • 7,337
  • 1
  • 22
  • 33