0
votes

Is it possible to open a PDF file right after its creation with Apps Script in Google Sheets?

My script is generating a pdf based on a Google Sheet and saving it on Google Drive. I would love to be able to automatically open it to print it.

Would spare some time for the user, not having to find the file and open it manually.

Thanks a lot for your help :)

2

2 Answers

1
votes

Well, if you are opening just it to print it; Most modern printers can be WiFi connected with custom email addresses. Then you can just email the file as an attachment to the printer.

0
votes

It's not the perfect solution but you could present them with a dialog that has a Url to the file. If you right click on it you'll get a menu that gives you the option to open in a new tab or a new window.

function createPDFofSheet() {
  var ss=SpreadsheetApp.getActive();
  var file=DriveApp.createFile(ss.getBlob());
  var url=file.getUrl();
  var html=Utilities.formatString('<a href="%s">Right Click on this link and chose open in new tab</a>',url);
  var ui=HtmlService.createHtmlOutput(html);
  SpreadsheetApp.getUi().showModelessDialog(ui, 'title'); 
}

Here's the output of this simple script

enter image description here