I'm looking for a library to transform my web page into a PDF file after click event from a button.
I'm trying jspdf
, but it prints without the CSS, how can I make this using JavaScript/jQuery
and keep my CSS? Or another CSS that I can choose?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- How to fix IE ClearType + jQuery opacity problem i
- void before promise syntax
- Correctly parse PDF paragraphs with Python
try this npm package
htmlto
.It creates PDF from html with CSS stylinginstall:
npm install -S htmlto
npm install -S phantom
*you can also specify the dimensions.phantom version ^4.0.3 and node version v6.5.0 https://www.npmjs.com/package/htmlto
There is a new jQuery + cloud solution that will render any HTML page and its CSS (including print media rules) to PDF. The solution is setup to print any region of your webpage, you just tell the Formatter which container element you want to print and the library does the rest. What you get back is an embeddable PDF or the backend will push back a PDF for download.
Here's your library (GitHub):
https://github.com/Xportability/css-to-pdf
Here's your fiddle:
http://jsfiddle.net/kstubs/jrtM5/
Here's a working demo:
http://xep.cloudformatter.com/doc/
Currently there are not useage instructions, but following along with the samples (view source) should be pretty self-explanatory (look for the Print It buttons) and here is, more or less the additional options/parameters that the Format method understands.
Here is list of CSS attributes that are currently supported.
Hope this helps!
I have created a simple & very easy to use API that uses the snappy library, based on the wkhtmltopdf webkit-based CLI, in order to convert an HTML page from the URL to PDF. Here is the Github repo: https://github.com/Dellos7/dhtml2pdf
This is an example of how to use it from an anchor tag. This will show the generated PDF of the
https://www.github.com
site in a new browser tab:Example of how to use it to download the PDF:
With this solution you don't even need to use javascript in order to generate your PDF.
But if you still need to do it using javascript, you can do it like this:
In the repo I also explain how to very easily clone & deploy your own API in Heroku so you can mantain the API yourself and not to depend on external services.