Home > Enterprise >  TCPDF with different rendering classes and merging
TCPDF with different rendering classes and merging

Time:11-12

currently I'm rendering PDFs with TCPDF in Laravel 9 (PHP8.1) for labels for products. The PDF contains many pages, depends on the selected products. I start a TCPDF and do a addPage() per product and output() at the end.

Now I got a request to change the content abit for different kind of products. So I would like to create classes for the different product types. But I still need to be able to get one PDF file at the end. I would like to avoid to save the PDF as a file since it's always a download anyway.

But how to merge PDF-pages from different classes?

I was using FPDF/FPDI in the past but I would like to avoid adding to many old PDF libs to Laravel and they might not work with PHP8.1. I also only know for FPDI the way to load a PDF file from disk (setSourceFile()) for merging, which is not, what I need.

Is there a good way with TCPDF to add the flexibility?

CodePudding user response:

Didn't found a to merge tcpdf pdfs that way. Had to go a different way by just putting the rendering logic into the different classes so at the end it is getting generated by a wrapper class that will call the specific product pdf classes to add new pages.

  • Related