I'm currently trying to add HTML content to an existing PDF document using the FPDI library to import the PDF and the mPDF library to generate the HTML content in my wordpress project. However, I'm facing difficulties as my code doesn't seem to display anything in the resulting PDF.
Problem:
I'm using the FPDI library to import an existing PDF document. The import process seems to work fine, but when I try to add HTML content using mPDF, it doesn't appear in the output PDF.
I'm generating HTML content using the mPDF library and then attempting to add this content to the imported PDF pages using the FPDI library. However, the generated HTML doesn't display as expected in the resulting PDF. I've double-checked my code, but I can't identify the issue.
Code:
Here's a simplified version of my code:
// ... (include necessary libraries)
function generate_pdf_from_url_param() { // ... (handle GET parameters and other setup)
// Create FPDI object and import existing PDF
$fpdi = new FpdiLibrary();
$pageCount = $fpdi->setSourceFile(get_template_directory() . '/existing.pdf');
// Loop through pages and add content
for ($page = 1; $page <= $pageCount; $page++) {
$tplIdx = $fpdi->importPage($page);
$fpdi->AddPage();
$fpdi->useTemplate($tplIdx);
// Create mPDF object and generate HTML content
$mpdf = new MpdfLibrary();
// ... (generate HTML content)
// Get the HTML content from mPDF
$html_content = $mpdf->Output('', 'S'); // Captures the output as a string
// Add HTML content to PDF using FPDI
// This line does not seem to work as expected
$fpdi->SetXY(30, 190); // Set position for HTML content
$fpdi->MultiCell(0, 10, $html_content);
}
// ... (other steps and output)
} add_action('init', 'generate_pdf_from_url_param');
I'm not sure why the HTML content generated using mPDF is not displaying in the output PDF. Could someone please provide guidance on how to properly integrate HTML content into an existing PDF using FPDI and mPDF? If there's a better approach to achieve this, I'd greatly appreciate your insights.
Thank you for your assistance!