I have Symfony framework with TWIG template engine. I am making 1000 page pdf within
<dynamic-page>...content in for-loop...</dynamic-page>`
However while writing onto disk with ps_facade
, it gives me memory exhausted fatal error. So is there any ways I can create this pdf by 5 pages a chunk?
After research I found that using template with 5 page worth of data and then write it on file should work. But in that way I won't be able to add page numbers, as page number should be 1-1000. My footer code looks like this,
<placeholders>
<footer>
<div height="30px" width="100%">
<hr/>
<div float="left">Blah Blah</div>
<div float="left" margin-left="350px"><page-info format="Page %s of %s"></div>
</div>
</footer>
</placeholders>
You should use a messaging system for long processes like this. RabbitMQ could do the job.
Pros: Since the process is not run by the web version of php, it does not have the memory_limit and max_execution time limitation If the job is already running, you can tell your user so instead of launching another generation for the same pdf. And since people often refresh the page when they get impatient, this can really be a huge Pro for your server (less CPU usage).
Cons: You'll have to setup a messaging server and learn a few things. But is this really a Con?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With