使用Google Apps脚本将包含图片的网页/ html转换为pdf

时间:2019-04-22 23:24:52

标签: javascript html image pdf google-apps-script

我正在尝试使用Google Apps脚本将网站转换为pdf,但是由于某种原因,该网页中的图像未正确嵌入到输出pdf中。

出于示例目的,假设我正在尝试使用以下应用程序脚本将www.google.com转换为pdf文件。


function myFunction() {
  var url = "https://www.google.com/" ;

  // call the url using URLfetchApp 
  var response = UrlFetchApp.fetch(url);  
  var htmlBody = response.getContentText();

  var blob = Utilities.newBlob(htmlBody, "text/html", "text.html")
  var pdf = blob.getAs('application/pdf');
  DriveApp.createFile(pdf).setName('googlePage.pdf');  
  }


输出的pdf应该类似于: enter image description here


但是,我得到的输出就像: enter image description here

没有图像,也不是很漂亮。

0 个答案:

没有答案