Javascript doesnt work for PDF

joki94

Member
Hi,

I use JavaScript to hide some fields and Groups regarding of the value of another field. This works fine in form view and it also works nice in Detail view. If I want to save the Detail view as PDF, I got my whole form with all fields. So I think JavaScript is not working for PDF Generation.

But if I use Fabrik PDF Debug = yes, the page looks correct with only the fields I see in Details view as well.

If I use the print button or the browser print menu, the layout Looks completely different but also only the fields I want to Display are displayed.

Can someone say me how I get JavaScript working in PDF as well?

Thank you and Kind Regards,

joki94
 
No, Javascript won't work for PDF. There's no such thing as Javascript in PDF.

Javascript is a web browser language, that runs in HTML pages, after the document loads in the browser. PDF isn't rendered in the browser, it's rendered on the server.

When you use Print, that's running JS because it's HTML in a browser. Although as it's in "component" view (without the surrounding Joomla page content) it often looks different, as theres CSS files that won't get loaded.

-- hugh
 
Hi Chessegrits,

thanks for your answer. I thought something like this. But is there any way to create a pdf with only the fields displayed?

Maybe with css?
 
domPDF has a JS option
/**
* Enable inline Javascript
*
* If this setting is set to true then DOMPDF will automatically insert
* JavaScript code contained within <script type="text/javascript"> ... </script> tags.
*
* @var bool
*/
private $isJavascriptEnabled = true;
But I have no idea if it is enabled or what this is doing.
 
That won't work. That option is for injecting inline JS into the PDF itself, which is supported by some PDF viewers (like Acrobat) for performing PDF viewer specific operations, on compiled PDF document code, like opening media players, dealing with signature blocks, etc. It's not a browser JS engine.

-- hugh
 
The only way to effect a PDF is to use a custom template, and put the hide/show logic in that, which isn't entirely trivial.

-- hugh
 
There used to be a free version of PhantomPDF which allowed you to generate PDF's server side from HTML using a browser engine that supported JS, but that went away (is now a mimimum $10/month subscription product).

BTW, @troester - while we're on the subject of PDF ... at some point I'll make my mpdf branch public, and you can test that. It seems a lot less glitchy than DOMPDF, although the trade off is that the composer lib for it is about 100mb. Of course, it won't handle JS either.

-- hugh
 
Thanks for the information, finally I managed it by using the print button. Not the best option for me but a workaroud. If you can help me by creating a custom template for hiding or showing the elements and groups, that would be very nice.

Kind Regards,

joki94
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top