【问题标题】:Control formatting of blob.getAs("application/pdf") in Google Apps Script在 Google Apps 脚本中控制 blob.getAs("application/pdf") 的格式
【发布时间】:2021-04-08 14:43:20
【问题描述】:

当使用 Chrome 中的 Print to Pdf 或 iOS 中的各种 Share Sheet 元素将网页(例如 this)转换为单个页面时,pdf 输出会被格式化为单个页面,如下所示:Output from Print to Pdf or iOS Share Sheet@ 987654323@

在 Google Apps 脚本中,使用以下代码将 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?

【问题讨论】:

标签: pdf google-apps-script html-to-pdf


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-15
    • 1970-01-01
    • 2022-01-26
    • 2012-09-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多