splitbrain / dokuwiki-plugin-dw2pdf

A fork of Luigi Micco's PDF export plugin for DokuWiki
http://www.dokuwiki.org/plugin:dw2pdf
55 stars 68 forks source link

javascript plugins are not resolved #446

Closed peetervois closed 2 years ago

peetervois commented 2 years ago

I think that this is not very correct place to talks about it but all plugins that use javascript are excluded when exporting to PDF. That seems to be Docuwiki's general issue. The PDF export works at the backend level of PHP but javascript runs on frontend browser. Thus when doing the PDF export all javascript plugins are not rendered. At least the following plugins are not rendered: https://www.dokuwiki.org/plugin:flowcharts and https://narezka.org/tablecalc are not rendered. What happens is that the PDF does not contain the flowchart but the flowchart syntax and when on the table there is a row with SUM of other rows, then there appears no sum on PDF.

I think of one possible easy solution for DocuWiki: When a page is viewed, there is a mechanism to send rendered pictures back to Docuwiki and the picture is stored for non-javascript use.

splitbrain commented 2 years ago

easy, eh? I'm looking forward to your pull request.

peetervois commented 2 years ago

I'm looking forward to read about ideas that are easier.

peetervois commented 2 years ago

I am sorry about the word "easy" - but I am looking for the solution and am ready to support its development. So, ideas are welcome.

I see some more possibilities, like the PDF is created on javascript on browser side, the pages might be rendered in the hidden window. I am not sure how this idea would work out, if somebody knows and has some additional ideas, then I would cladly see them here.

Please unclose the discussion.

splitbrain commented 2 years ago

Sorry, supporting JS based plugins is well beyond what this plugin's approach can do. TBH you're probably better off to just use your browser's print mechanism to export to PDF.

peetervois commented 2 years ago

Yes, I've been using the print dialog but I like this plugin a lot, its ability to collect many pages into one pdf and so on. I think you have made a very good thing. Thus I was thinking that if the docuwiki could have mechanism to store the rendered image could actually solve this plugin's issue not haveing the javascript rendered sections. I think if the images are with "poor" quality is better than not to have them as for start. I also think that the one who modifies the page / plugin is most likely making a preview run of the saved result and thus a image is created.

I can imagine that it is possible or there already is a div that is encapsulating a plugin area and a javascriptlet that does monitor if something on the div is changed dynamically by some other script. If there is a change, then it could be possible to create a image of visible divs and send back to docuwiki with ajax for example. I found a following page just now http://adnan-tech.com/save-div-as-image-html2canvas/

Now the dw2pdf could be able to check if such plugin encapsulating div's is haveing a image stored and use that instead. It would happen only for javascript enchanced plugins that change the div's content.

Sorry again for being little offensive at the start. I can not imagine any other method at the moment that would support pdf creation by PHP without invoking a background browser or renderer- that again might not be possible for most of the rental web servers.

splitbrain commented 2 years ago

JavaScript will not only produce images but modify the DOM. PDFs do not consist of images either. Again, this is simply way beyond what this plugin can do.

If you want a JavaScript capable, server side PDF exporter you need to create a new plugin, probably based on a real browser engine like headless chrom.

peetervois commented 2 years ago

If to think about new plugin, then it would also be possible to produce the PDF using javascript on frontend side. I like the dw2pdf ability to collect many sub-pages into one PDF, also the pagebreak feature is nice. What you think about possibilities to make a javascript that does query the pages from server in a format for printing out the page into separate visible or invisible window and then produce the pdf based on what it does find from those rendered pages ?