Convert HTML to PDF with Apps Script

Published in: Google Apps Script - PDF

With Google Script, you can convert any HTML content into a PDF file with a few lines of code. The PDF file can be saved to Google Drive or you can email the file as an attachment using the GmailApp service.

function htmlToPDF() {

  var html = "<h1>Hello world</h1>"
           + "<p>The quick brown fox jumped over the lazy dog";

  var blob = Utilities.newBlob(html, "text/html", "text.html");
  var pdf = blob.getAs("application/pdf");


  MailApp.sendEmail("", "PDF File", "",
     {htmlBody: html, attachments: pdf});

Published in: Google Apps Script - PDF

Looking for something? Find here!

Meet the Author

Web Geek, Tech Columnist
Amit Agarwal

Amit Agarwal is a Google Developer Expert in GSuite and Google Apps Script. He holds an engineering degree in Computer Science (I.I.T.) and is the first professional blogger in India. Read more on Lifehacker and YourStory

Get in touch