First, you have to include jsPDF library, and also html2canvas or rasterizeHTML.
Then, just create a jsPDF object and save to pdf the entire ‘body’ tag (or whatever):
var pdf = new jsPDF('p','pt','a4'); pdf.addHTML(document.body,function() { pdf.save('web.pdf'); });
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.0.272/jspdf.debug.js"></script> <body> <p id="to-pdf">HTML content...</p> </body>
You can find more examples on the jsPDF website: http://mrrio.github.io/jsPDF/
Related Posts:
- How to properly use jsPDF library
- jsPDF fromHTML() does not show HTML
- Getting a UnhandledPromiseRejectionWarning when testing using mocha/chai
- Creating multiline strings in JavaScript
- How to make a word underline in Markdown
- JQuery – $ is not defined
- Is it possible to sandbox JavaScript running in the browser?
- ActiveX – Automation Server Can’t Create Object
- How to loop through an array containing objects and access their properties
- RegEx Ignore Case
- What is the convention in JSON for empty vs. null?
- Generating random whole numbers in JavaScript in a specific range?
- Remove all child elements of a DOM node in JavaScript
- Why Is `Export Default Const` invalid?
- Why is process.env.NODE_ENV undefined?
- Better way to sum a property value in an array
- Javascript require() function giving ReferenceError: require is not defined
- jQuery AJAX cross domain
- How to extract extension from filename string in Javascript?
- keep getting “? Something is already running on port 3000” when I do npm start on react app
- How to remove text from a string?
- Convert character to ASCII code in JavaScript
- Disable same origin policy in Chrome
- How do I remove a key from a JavaScript object?
- What is causing the error `string.split is not a function`?
- Difference between innerText, innerHTML and value?
- Uncaught TypeError: data.push is not a function
- Length of a JavaScript object
- How to check a radio button with jQuery?
- Get current URL with jQuery?
- How to get JSON from URL in JavaScript?
- How do you put an image file in a json object?
- How can I add a class to a DOM element in JavaScript?
- Warning: findDOMNode is deprecated in StrictMode. findDOMNode was passed an instance of Transition which is inside StrictMode
- Module not found: Error: Can’t resolve ‘fs’ in
- TypeError: $(…).modal is not a function with bootstrap Modal
- How to do fade-in and fade-out with JavaScript and CSS
- I want to remove double quotes from a String
- Calculating median – javascript
- Vue is not defined
- npm WARN enoent ENOENT: no such file or directory, open ‘C:\Users\Nuwanst\package.json’
- How to change value of object which is inside an array using JavaScript or jQuery?
- How to detect pressing Enter on keyboard using jQuery?
- How to make your Discord Bot always active
- How to write inside a DIV box with javascript
- use Lodash to sort array of object by value
- How to make an HTML back link?
- How to fix getImageData() error The canvas has been tainted by cross-origin data?
- How to make fadeOut effect with pure JavaScript
- “Cross origin requests are only supported for HTTP.” error when loading a local file
- What is ‘xmlhttp.setRequestHeader();’ and in which situations is it used?
- Write / add data in JSON file using Node.js
- Set scroll position
- .filter is not a function
- Function overloading in Javascript – Best practices
- Wait until flag=true
- Adding javascript to child theme
- What does l10n.js do in WordPress 3.1? And how do I remove it?
- How to add javascript just before the closing body tag in the footer of WordPress
- Open media frame and select an attachment
- Loading different JS for http and https
- Loading Javascript Only When Specific Content Existing in a Post?
- How to pre-fill Google Forms URLs with logged-in WordPress user’s data
- Use of Javascript with Dojo/Dijit on a WordPress page
- WordPress loads whole jQuery UI library
- wp_register_script unable to link bootstrap JS
- Javascript that will execute on only child pages of a specific parent
- How do I change number of columns in a proper way in twentyfourteen child theme?
- How do I embed a Javascript form directly into a page?
- Can the index.asset.php file be used with the enqueue_block_editor_assets action?
- Using google graph api with wordpress
- Using wp.data.select get actual tags (not id’s) used in post
- JavaScript && operator in visual editor
- How to deal with the confliction between PHP-Markdown and MathJax?
- Programatically update posts in database from one block to another using transform
- Mouse wheel Auto scroll to anchor [closed]
- Gutenberg richtext block vaildation failed
- Custom Gutenberg-Block esnext pass variables
- Javascript only works if browser Developer Tools panel is open
- How to read inline-CSS from Gutenberg block?
- WP adds long version query strings to CSS and JS files
- javascript not loading
- How does WP determine the difference between a post and a page url
- Load content dynamically & resize event
- creating a static HTML/JS/PHP page
- Newest version of javascript
- wp_enqueue_script does not recognize my js file?
- ‘ajaxurl’ is undefined — wp-includes/js/wp-lists.js
- What to include to use jQuery UI Auto Complete
- create timestamp links to jump to specific times on rumble videos
- script not working anymore after saving widget settings
- Loading two versions of same JS libary
- Error handling for wpdb error – displaying an error message to the user
- load-scripts.php loads incorrect file names
- Don’t understand how to link Javascript files in WordPress
- Where to include JS library in gutenberg blocks
- Theme path of WordPress inside javascript file
- Error – Uncaught TypeError: e.dispatchEvent is not a function
- Is it possible to add javascript to template parts