0

I am trying this code to generate a pdf file of my Apps script UI.It does not show the UI in PDF. Please assist.

function saveaspdf(frm) { 
    var htmlBody = HtmlService.createHtmlOutputFromFile('my1.html').getContent(); 
    var blob = Utilities.newBlob(htmlBody, 'text/html').getAs('application/pdf').setName('my_output_in_drive.pdf');
    DriveApp.createFile(blob);   
  }
Serge insas
  • 45,904
  • 7
  • 105
  • 131
BipinSasi
  • 187
  • 14

1 Answers1

0

the solution is simpler...

function saveAsPdf() { 
    var blobBody = HtmlService.createHtmlOutputFromFile('index.html').getAs('application/pdf'); // is a blob
    DriveApp.createFile(blobBody).setName('outputFile.pdf');   
  }
Serge insas
  • 45,904
  • 7
  • 105
  • 131
  • HI Serge Thanks for your reply ,Your code also give the pdf blank ,The background image and div elements are not showing up on pdf – BipinSasi Feb 27 '14 at 13:49
  • Any alternative ideas on how to print an Apps script UI will be appreciated . – BipinSasi Feb 27 '14 at 14:12
  • you could try to use the drive api to convert to pdf via urlfetch, there are plenty of examples on how to use it in combination with oAuth. search on the google apps script tag – Serge insas Feb 27 '14 at 15:09
  • see this post http://stackoverflow.com/questions/13570205/images-not-reproduced-when-converting-a-blob-from-html-to-pdf – Serge insas Feb 27 '14 at 17:31