html to pdf code code example

Example 1: python html to pdf

# Shell
pip install pdfkit
sudo apt-get install wkhtmltopdf

# Python
import pdfkit 
pdfkit.from_file('input.html','shaurya.pdf') # .from_url and .from_string also exist

# Source: https://www.geeksforgeeks.org/python-convert-html-pdf/

Example 2: html to pdf javascript

var doc = new jsPDF();          
var elementHandler = {
  '#ignorePDF': function (element, renderer) {
    return true;
  }
};
var source = window.document.getElementsByTagName("body")[0];
doc.fromHTML(
    source,
    15,
    15,
    {
      'width': 180,'elementHandlers': elementHandler
    });

doc.output("dataurlnewwindow");

Example 3: html to pdf

html2pdf.com is a great resource, web-based converter, super simple to use also.