Convert html to pdf using pure js and jshtmlpdf using jshtmlpdf
The project has encountered an abnormal requirement. You need to export an entire page to pdf format and retain all the tables, svg images, and styles on the page.In short, we want to cut down the entire page and save it as a pdf.Why not go to heaven .....
) {3 varImgdata = Canvas.todataurl (' image/jpeg '));4 varIMG =NewImage ();5IMG.SRC =Imgdata;6 //according to the size of the picture to set the PDF specifications, to be executed when the picture is loaded successfully, the reason is *0.225 because of the scale problem7Img.onload =function() {8 //It is important to note that the PDF is horizontally and vertically two properties that need
Mobile js Image Viewer and js Image Viewer
This article provides examples to share with you how to use the js Image Viewer plug-in and how to create a webpage Image Viewer for your refe
In this Post we is providing best jQuery PDF Viewer Plugin tutorial with examples. Due to popularity of online document viewer like Google Docs some JavaScript developers develop a good and useful plugins To view PDF file on online PDF
I. Methods of UseSecond, HTML structureThird, initialize the plug-inYou can also add some colorful tabs bookmarks to the PDF page.$ (function () {$ ("#myPDF"). PDF ({Source: "Demo.pdf",tabs:[{title: "Tab 1", Page:2, Color: "Orange"},{title: "Tab 2", Page:3, Color: "Green"},{title: "Tab 3", Page:5, Color: "Blue"},]});});Keymob Mobile Advertising Platform is a prof
Viewer main function
/** *
Picture Viewer
* @param object obj action Objects
* @param Object Set Object sets *
/base.dialog = function (obj, set) {
var i = set.index (obj); Current page index
var rel = set.length///number of items
var html = '
Load Swipe.js on Demand
/**
* On-demand load JS
Two options: a direct link to the PDF file as an img file, similar to the
Copy Code code as follows:
Another: Use JS plugin ha.
The realization of reading a PDF file of JS Plug-ins a lot, such as: Pdf.js: is a technology prototype is mainly used to display PDF
) - Paper.subscribe (joe.drinkcoffee); inPaper.subscribe (Joe.sundayprenap, ' monthly ')); the //that is, Joe provides a method that can be called for the default "any" event, while another method that can be called is used when an event of type "monthly" occurs. Now let's trigger some events: thePaper.daily ();//Just Readbig News Today AboutPaper.daily ();//Just Readbig News Today thePaper.monthly ();//About to fall asleep reading thisinteresting analysis thePaper.monthly ();//About to
. }; varprinthtml=$ (' #pdfDom '). Get (0); //the contents of a div within a page, and get the div content by IDpdf.addhtml (printhtml, the, the, Options,function() {Pdf.save ('Target. pdf'); }); }}Script>4, or the above JS method can be replaced with this is also possible.Export the HTML page. pdf file (for
: http://wkhtmltopdf.org/downloads.htmlAfter installation, you need to add after the system environment variable variable named "Path":;D: \wkhtmltopdf\bin is the directory you installed. Reboot the computer after installation.Test use effectInput directly in cmd: Wkhtmltopdf http://www.baidu.com/D:website1.pdfWhere the temp file is, where your CSS will be, or you can directly use a relative path, referencing a CSS style from another file, the simplest is to write the CSS style directly in the
1. Introduction of the relevant jar package in the projectItextasian-1.5.2.jarItext-4.2.1.jarItextpdf-5.1.2.jarItextpdf-5.1.2-sources.jar 2. Add a button to a page that needs to convert the page to a PDF document3. Then introduce the relevant JS and jar packageHtml2canvas.js 4. Write the JS code that generates the PDF
In the Venus sourcing system, a new export PDF function is added. The entire feature uses third-party software wkhtmltopdf (download) official website https://wkhtmltopdf.org/offers more version downloadHe can convert HTML page to PDF, the software is simply incredible-incredible, the function is too powerful.Because, I have a
Tomcat, you can use:
Http: // localhost: 8080/generic/web/viewer.html
Access! You can see a very handsome interface:
Generic/web/viewer.html is mainly used to render the style of the pdf reader, while generic/web/viewer. js specifies the opened PDF file (of course there are other functions, but these are not our conc
parameters only 3, to. pdf, if written as a common mode, of course, can be passed as an external parameter.FORMAT:A4 paper, can be set "5in*7.5in", "10cm*20cm", "letter" and so onOrientation: Paper direction is vertical, or landscapeMargin: With the width of the paper, customizable, can also be set in detail margin: {left: ' 0.8cm ', Top: ' 0.8cm ', right: ' 0.8cm ', bottom: ' 0.8cm '}1 Page.zoomfactor = 1;2 Page.settings.loadImages = true;Zoomfactor
official documents, you can find them on your own.
This is not a perfect method. MPDF can only parse relatively simple css (it cannot parse ul li and other labels in js and css ). Now that the wkhtmltoimage extension is used, you do not care about the use of wkhtmltopdf.Similarly, wkhtmltoimage 0.11 may cause an error. you need to download Version 0.10.0 _ rc2.
32-bit:
The code is as follows:
Wget http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf
PHP implementation of HTML to generate PDF file method,
The example of this paper describes the use of Html2fpdf and Wkhtmltoimage in Linux to generate HTML directly in PDF format file method, share to everyone for your reference. The implementation method is as follows:
Find a fpdf and Html2fpdf source code based on
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.