You need to specify the pdf_template_pdfpage to be relative to the theme folder. So in your example it should be placed in wp-content/wp-mpdf-themes/ . So if the file wp-mpdf_LetterTemplate.pdf is placed in that folder you can just set it as
$pdf_template_pdfpage = 'wp-mpdf_LetterTemplate.pdf';
As for your other question. You can define global $pdf_format and global $pdf_orientation and set them in your custom template. For allowed values see the mpdf library documentation.
Thanks for your prompt response. I placed my theme and the pdf template page file (a single blank pdf page) in the folder where I found “default.php”, namely wp-content/plugins/wp-mpdf/themes/. It seemed to find my custom theme there, but not the template pdf file. I was unaware of the other wp-mpdf-themes folder, so I moved my files there and tried again and still obtained the WordPress “critical error” message when attempting to specify the template pdf file.
I found success by defining the global $pdf_format as you suggested, so my immediate problem is solved. It would be nice to know how to utilize the pdf template mechanism in case I have some future customization. Maybe I am doing something wrong with the pdf file? I don’t have much information about what went wrong trying to use it. Is it “file not found” or some unexpected format of the pdf file? Are pdf template files different than any simple pdf file?
So you placed your custom theme in `wp-content/wp-mpdf-themes/ and in the same folder the PDF template? And then you selected the correct theme from the list and it still does not work? No PDF templates should be just a standard PDF file. Otherwise I recommend turning on error reporting/check the logs on your PHP server and see if that gives you more details of what exactly is failing.
Here is some info from my site host who looked at the php error log (below). I wondered if it was the format of the pdf file I was referencing. I tried writing my pdf from four different applications, including Adobe’s “Save As PDF”, and Acrobat. They had different file sizes, so presumably different compressions. All generated the same php error.
——
“Typically, you will find PHP errors in a filed named error_log. They are dropped to the filesystem in the current working directory of the running process. I looked in your cPanel under the PHP Selector and I see you have log_errors turned on, so I searched your account and found these two error_log have been updated today: /home/thorolso/public_html/error_log and /home/thorolso/public_html/wp-admin/error_log
I have pasted the last entry below. If it’s a PDF file you are working with, that’s the issue. I’ve recently discovered a similar thing on a project I was working on. The version of the PDF was too new, and recreating the PDF with a lower compatibility version of the PDF standard worked for me.
I hope this helps!
Bob
[27-Nov-2024 17:43:21 UTC] PHP Fatal error: Uncaught setasign\Fpdi\PdfParser\CrossReference\CrossReferenceException: This PDF document probably uses a compression technique which is not supported by the free parser shipped with FPDI. (See https://www.setasign.com/fpdi-pdf-parser for more details) in /home/thorolso/public_html/wp-content/plugins/wp-mpdf/vendor/setasign/fpdi/src/PdfParser/CrossReference/CrossReference.php:257″
Yeah as the error indicates it seem to be not supported. I would checkout the link (and reach out to the support of the fpdi library) to see if they can help what tool you can use to make your PDF compatible.
I was able to provide a pdf tempate page that was accepted! It had to be written in PDF/A (archival) format, which few pdf writers support. It was nice to see that it worked, but when I went to a custom page size or a landscape orientation, it didn’t give what I expected. Instead, I got the default A4 (portrait) page.
I’m probably pushing it beyond its original purpose, but this is the closest I’ve come to getting a clean pdf rendering of my web pages and I am thrilled that I can tune it to my preferences. If only it could do just a little more… If you are still working on this plugin and want to take it to this next use-case level (generating pdf pages for inclusion in a printed publication), I’d be happy to collaborate.
Thanks for this tool and your responsive support!