Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Javascript generated content #454

Closed
sander76 opened this issue Apr 7, 2017 · 6 comments
Closed

Javascript generated content #454

sander76 opened this issue Apr 7, 2017 · 6 comments
Labels
feature New feature that should be supported

Comments

@sander76
Copy link

sander76 commented Apr 7, 2017

Not really an issue, but more a question:
Can weasyprint render javascript created content? I did search the docs, but there is no mention of it.

@liZe
Copy link
Member

liZe commented Apr 7, 2017

Can weasyprint render javascript created content?

Short answer: unfortunately, no.

You'll find some interesting comments in #23 explaining how you can add some generated content using Python. That's the easiest way to do this currently.

@liZe liZe added the feature New feature that should be supported label Apr 7, 2017
@drukepple
Copy link

@sander76 I wanted this feature in order to run a JS syntax highlighter. Check out this SO answer: https://stackoverflow.com/questions/12450868/how-to-print-html-source-to-console-with-phantomjs/12469284#12469284

As a pre-PDF step, I'm running my HTML through PhantomJS and writing the output to a new file, which now includes DOM manipulations from JS, and using that to feed into WeasyPrint.

Worth noting that Prince can do this just fine by using the --javascript option. But Prince is ridiculously expensive, and WeasyPrint is priced just right. For which I thank you.

@Tontyna
Copy link
Contributor

Tontyna commented Dec 17, 2018

@liZe
Copy link
Member

liZe commented Jul 25, 2019

As we won't include a JS engine in WeasyPrint, I close this issue. Using a preprocessing JS tool is the best solution if you want to rely on JS, otherwise editing the document with Python (or anything else) is possible too.

@liZe liZe closed this as completed Jul 25, 2019
@luizmof
Copy link

luizmof commented Sep 13, 2019

@sander76 I wanted this feature in order to run a JS syntax highlighter. Check out this SO answer: https://stackoverflow.com/questions/12450868/how-to-print-html-source-to-console-with-phantomjs/12469284#12469284

As a pre-PDF step, I'm running my HTML through PhantomJS and writing the output to a new file, which now includes DOM manipulations from JS, and using that to feed into WeasyPrint.

Worth noting that Prince can do this just fine by using the --javascript option. But Prince is ridiculously expensive, and WeasyPrint is priced just right. For which I thank you.

Hi, can you show some example how to do this? I'm trying to figure out this to implement a template with JS that render maps em graphs.

I use Django and I've read some people saying to use PhantomJS to render the page in the front end and give it back to Weasy.

Some thing like this:
https://stackoverflow.com/questions/39893123/execute-javascript-and-css-in-django-template

@maximedieudonne
Copy link

maximedieudonne commented Jun 10, 2020

@sander76 I wanted this feature in order to run a JS syntax highlighter. Check out this SO answer: https://stackoverflow.com/questions/12450868/how-to-print-html-source-to-console-with-phantomjs/12469284#12469284

As a pre-PDF step, I'm running my HTML through PhantomJS and writing the output to a new file, which now includes DOM manipulations from JS, and using that to feed into WeasyPrint.

Worth noting that Prince can do this just fine by using the --javascript option. But Prince is ridiculously expensive, and WeasyPrint is priced just right. For which I thank you.

@drukepple thank you for your answer ! could you please give an exemple ? what do you mean by "I'm running my HTML through PhantomJS" please ? thanks a lot !
here is an exemple of file.js, it is what you mean ?
var page = require('webpage').create(); page.open('path_to_file.html', function () { console.log(page.content); phantom.exit(); });

how do you get the DOM tree of your html file with phantomJS please ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature that should be supported
Projects
None yet
Development

No branches or pull requests

6 participants