Get a .PDF link from Google Drive

152 Views Asked by At

I have been using App Script to export spreadsheet as PDF file. The pdf file is uploaded to Google Drive. Then, I want to send the PDF through Whatsapp API.

Problem is: I need the link to be somthing.pdf for the API to get its a pdf file and send it as documnent. The google drive url does not work as intended (user needs to open it and download it). Is there a way to do that with app script?

This is the code:

// construct the export URL
  let urll = 'https://docs.google.com/spreadsheets/d/' + sheetID + 
  '/export?format=pdf&' +
  'size=letter&' + 
  'portrait=true&' + 
  'fitw=true&' +
  'gridlines=false&' +
  'printtitle=false&' +
  'sheetnames=false&' +
  'pagenum=false&' +
  'fzr=false&' + 
  'gid=' + sh

  // parameters that will be use for the blob  
  let params = { method: "GET", headers: { "authorization": "Bearer " + ScriptApp.getOAuthToken() } };
  let blob_file = UrlFetchApp.fetch(urll, params).getBlob().setName(toddate);

  //call the folder
  let folder = DriveApp.getFolderById(folderId);

  //creates the PDF file in the folder
  let pdfFile = folder.createFile(blob_file);
  var pdfURL = pdfFile.getUrl();
0

There are 0 best solutions below