控制 Google Apps 脚本中 blob.getAs("application/pdf") 的格式

问题描述

在 Chrome 中使用 Print to Pdf 或 iOS 中的各种 Share Sheet 元素转换 this 等网页时,pdf 输出格式为单个页面,如下所示:Output from Print to Pdf 或 iOS Share工作表

在 Google Apps Script 中,使用以下代码将 html 转换为 pdf 会生成一个两页的 pdf:输出来自 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");
}

在使用 blob.getAs() 输出为前者时,是否有一种控制格式的方法,或者我可以在 Apps 脚本中使用更好的方法将网页转换为 pdf?

解决方法

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

展示如何从 HTML 的 blob 创建 PDF。我没有足够的分数将其添加为评论而不是独立的答案。