简体   繁体   中英

How to use wkHtmltoPdf to generate PDf files from statcic html files in JS

Can anyone suggest how to use wkhtmltopdf in JS to generate PDF files from static html files?

wkhtmltopdf - http://code.google.com/p/wkhtmltopdf/

All answers say run "wkhtmltopdf http://www.google.com google.pdf"

But run the code where? On a server? On a browser? On a command line?

Any code samples will be helpful

As per the project's homepage : it's a command line tool.

What is it?

wkhtmltopdf and wkhtmltoimage are open source (LGPL) command line tools to render HTML into PDF and various image formats using the QT Webkit rendering engine. These run entirely "headless" and do not require a display or display service.

In your server-side application, you can call the binary and wait for its output (for PHP, it's basically $output = exec("wkhtmltopdf $url $options"); ). There used to be an example wrapper on the project's Google Code wiki, but it seems to be gone.

If you're using PHP and don't want to write a wrapper yourself then you can use this one . If there's no wrapper for your chosen server-side language, then try making one yourself. It's not hard.

Your front-end JavaScript will have to call (probably using AJAX) a script that runs on your server to generate the PDF.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM