This is a quick solution I found for one of the issues I got while developing a web portal which allows PDF downloads. However these PDF documents had to be preceded with a dynamically generated page which should be inserted at the time of downloading the PDF.
After few hours of trying I came up with this solution which worked well in my case. Just thought of sharing my solution for someone who might have the same issue.
This can be easily done using mPDF. Please download mPDF and follow the instructions on the mPDF documentation to get it working with your PHP application. I use Yii for my projects and mPDF is available for Yii as an extension (yii-pdf) which you can find here.
mPDF allows importing pages from another PDF into the one you create on the fly. We use this feature for importing all the pages of the source PDF file and create a new PDF inserting a dynamically generated page at start.
A plain PHP example:
$pdf = new mPDF(); $pdf->AddPage(); $pdf->WriteHTML('Some HTML content for the first page');