1

When converting a webpage such as this using Print to Pdf in Chrome, or from various Share Sheet elements in iOS, the pdf output is formatted to a single page like this: Output from Print to Pdf or iOS Share Sheet

In Google Apps Script, converting the html to pdf using the code below results in a two page pdf: Output from blob.getAs("application/pdf")

function mwe() {
  var url = "https://www.theguardian.com/crosswords/quiptic/1102/print"
  var html = UrlFetchApp.fetch(url)
  var blob = html.getBlob();
  var pdf = blob.getAs("application/pdf");
  DriveApp.createFile(pdf).setName("example");
}

Is there either a way of controlling the formatting when using blob.getAs() to output as the former, or a better method I can use in Apps Script for converting a webpage to pdf?

TheMaster
  • 45,448
  • 6
  • 62
  • 85
Joe
  • 41
  • 4
  • Use options here: https://stackoverflow.com/questions/49197358 – TheMaster Jan 02 '21 at 04:53
  • 2
    Those paramaters seem to be part of the export link for a Google Sheet item, I don't understand how they can be applied to a generic webpage? – Joe Jan 02 '21 at 14:38

1 Answers1

0

Google Apps Script - Convert HTML with styling to PDF and attach to an email - Create a PDF blob from HTML

Shows how to create a PDF from a blob from HTML. I do not have enough points to add this as a comment rather than a standalone answer.

L.Klein
  • 56
  • 7