CalcBuilder Forum

PDF not formatted properly (does not open)

User moon_1868 2015-01-28 17:49:07


My form prints out a stream of html data saved in a php variable ($results).
When I recall this variable inside the Before/After calculation for pdf print this is what I obtain by clicking on the pdf icon:

Firefox: an index.php page is opened, showing the correct values. But if I download the file (mpdf.pdf) then I can't open it with Acrobat Reader because "the file is not supported". In fact, by inspecting the file with a text editor I can see my html code and after few lines the %PDF-1.4% header that should be at the very beginning of the file, according to what is stated on the Adobe site.

Chrome: no file is opened.

IE: no file is opened.

You can see the demo form here:

Could you please let me know how I could solve this issue?

Thanks for the assistance


Moonsoft support 2015-01-28 19:07:22

when you say the form is printing a stream, maybe you're using echo instructions or var_dumps at your php code? that kind of instructions can break the pdf format, as they are executed before sending the contents to pdf library. The right way to print the html you have built is to place ##results## at your output section.

If this is not your case and you can't solve the issue, please place a ticket at the helpdesk sharing an access to your site and we'll take a look.


User moon_1868 2015-01-29 09:35:47


That's been a very easy fix!!! Thank you!
I deleted the echo $results, and replaced it with a ##results## inside the exit layout and now everything works perfectly. Sorry, I thought it was the same.

Also, do you eventually know if it is possible to customize the pdf filename? I could hard-code a little bit the library if necessary, but I don't know where to look for.

Thanks again for the nice component and the very efficient assistance!


Moonsoft support 2015-01-29 12:24:53

great it worked. When no name is set, the library saves the file with a default name. You can force the file name editing the source where the output is printed:


replace the last line
$mpdf->Output ();

for this one
$mpdf->Output ('yourfilename.pdf','I');

This should do the work.


User moon_1868 2015-01-29 15:46:45

Thanks, I created an override inside my template and it works perfectly.


Support/development 10 hours

Get a bigger amount of hours for more complex tasks and get a 10% discount

Buy now!
Support/development 40 hours

With the peace of mind of having a professional team at your service (20% discount)

Buy now!