0

I am trying to convert a website to a pdf using google apps script but for some reason the images in that webpage are not properly embedded into the output pdf.

For example purposes, say I am trying to convert the www.google.com to a pdf file using the following apps script.


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');  
  }


The output pdf should be like : enter image description here


But, the output I am getting is like : enter image description here

which doesn't have the image and isn't also really pretty.

everestial007
  • 6,665
  • 7
  • 32
  • 72
  • Is this information useful for your situation? https://stackoverflow.com/q/49244622 – Tanaike Apr 22 '19 at 23:46
  • I had come across this example, which references the actual url of the image. But, that creates a problem coz some websites are dynamic and also can contain lots of images. So, the best idea I was think is to just convert the website directly into pdf like browsing in a chrome or headless chrome browser. – everestial007 Apr 23 '19 at 00:13
  • Thank you for replying. I apologize my comment was not useful for your situation. – Tanaike Apr 23 '19 at 02:16
  • Thanks for providing some tips though. You were helpful. :) – everestial007 Apr 23 '19 at 02:27
  • Thank you for replying. For example, as a workaround, if the external API for getting a screen shot of a page as PDF file, that might be useful. – Tanaike Apr 23 '19 at 02:33

0 Answers0