JsPDF isHTML5Client solution, used to generate PDF documents for various purposes. The method is simple. You only need to introduce the jsPDF library and then call the built-in method. Browser compatibility: IE 10, Firefox 3 +, Chrome, Safari 3 +, and Opera will be compatible with versions earlier than IE 10 in the future. For versions earlier than IE10, Downloadify will be used for file download.
Articles you may be interested in
- We recommend 10 JavaScript development frameworks with rich UI components.
- JQuery Wheel Menu: Beautiful Path-style rotation Menu
- SlimerJS-Web developers can write JavaScript-controlled browsers
- Chance-powerful JavaScript random number generation class library
- Carefully selected 12 excellent jQuery Ajax paging plug-ins and tutorials
Example
1. Text
var doc = new jsPDF();doc.text(20, 20, 'This is the default font.');doc.setFont("courier");doc.setFontType("normal");doc.text(20, 30, 'This is courier normal.');doc.setFont("times");doc.setFontType("italic");doc.text(20, 40, 'This is times italic.');doc.setFont("helvetica");doc.setFontType("bold");doc.text(20, 50, 'This is helvetica bold.');doc.setFont("courier");doc.setFontType("bolditalic");doc.text(20, 60, 'This is courier bolditalic.');
2. Images
// You'll need to make your image into a Data URL// Use http://dataurl.net/#dataurlmakervar imgData = 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD/4ge....../2Q==';var doc = new jsPDF();doc.setFontSize(40);doc.text(35, 25, "Octonyan loves jsPDF");doc.addImage(imgData, 'JPEG', 15, 40, 180, 180);
3. HTML
var doc = new jsPDF();// We'll make our own renderer to skip this editorvar specialElementHandlers = {'#editor': function(element, renderer){return true;}};// All units are in the set measurement for the document// This can be changed to "pt" (points), "mm" (Default), "cm", "in"doc.fromHTML($('#render_me').get(0), 15, 15, {'width': 170, 'elementHandlers': specialElementHandlers});
Articles you may be interested in
- Manifesto-HTML5 Offline Application cache verification tool
- Popline: a very special floating HTML5 text editor Toolbar
- Bootstrap 3.0 was officially released to better support mobile development
- JQuery Flat Shadow-easy to achieve beautiful long Shadow effect
- Superhero: resources for building large JavaScript applications
Link to this article: likes! JsPDF-powerful HTML5-based PDF generation tool
Source: Dream sky ◆ focus on front-end development technology ◆ share web design resources