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

docs(examples): render custom HTML to PDF #3376

Closed
wants to merge 1 commit into from

Conversation

guumaster
Copy link

add example to create an HTML page in memory, render it with puppeteer and save it as a pdf file.

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

@guumaster
Copy link
Author

I signed it!

@googlebot
Copy link

CLAs look good, thanks!

Copy link
Collaborator

@JoelEinbinder JoelEinbinder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate on a scenario where this would be useful for someone?

examples/custom-html-pdf.js Outdated Show resolved Hide resolved
examples/custom-html-pdf.js Show resolved Hide resolved
examples/custom-html-pdf.js Outdated Show resolved Hide resolved
add example to create an HTML page in memory, render it with puppeteer and save it as a pdf file.
@guumaster
Copy link
Author

Can you elaborate on a scenario where this would be useful for someone?

If you have a server that renders HTML and you want to generate pdf from any page, you can use this code to do it instead of navigating to an internal page with goto().

I've tried with setContent()/content() but even if you use await page.content() it wont show immediately. So after a while of going through the issues and docs I got this example working.

I thought it would be useful for somebody else.

Thanks for reviewing it!

@aslushnikov
Copy link
Contributor

@guumaster The "goto hack" is a consequence of #728; I'd rather have it fixed than spreading the hack further.

#728 requires contributing upstream to Chromium and DevTools protocol; let me know if you want to give it a shot.

@aslushnikov aslushnikov closed this Oct 9, 2018
@guumaster
Copy link
Author

guumaster commented Oct 10, 2018

Probably I can't contribute to #728 to Chromium.

This example may not be too important. But is not such a hack either, it is something that you can normally do with a browser, and puppeteer is meant to control a browser, isn't it? Maybe someone that needs this can find the code in this issue useful.

Thanks for your time anyway.

PS: You think you can merge it if I get the example working with setContent()/content() ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants