Downloaded pdf file using appscript results in different pdf as if downloaded manually

55 views
Skip to first unread message

Ramzi Djauhari

unread,
Jun 3, 2023, 10:36:47 PM6/3/23
to Google Apps Script Community
Can someone give an advice? I have written appscript to download a report into pdf file. I used to download manually, and all this time it shows as I expected. Recently, I tried to use appscript to download automatically, but the result is different from downloaded-manually. Thank you in advanced for helping me.

function onOpen() { var ui = SpreadsheetApp.getUi() ui.createMenu("JP Ranap") .addItem("Keperawatan-PDF","keperawatan") .addToUi(); } 

function displaytoast(berita,judul,lama){ SpreadsheetApp.getActiveSpreadsheet().toast(berita,judul,lama); } 

function getFileAsBlob(exportUrl) { let response = UrlFetchApp.fetch(exportUrl, { muteHttpExceptions: true, headers: { Authorization: 'Bearer ' + ScriptApp.getOAuthToken(), }, }); return response.getBlob(); } 

function keperawatan(){ var bulanrekap = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('REKAP').getRange('S2:W2').getValue(); var tahunrekap = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('REKAP').getRange('S3:U3').getValue(); let blobpdf = getFileAsBlob("https://docs.google.com/spreadsheets/d/1i0lJ8dyeAUXvdEsPIPvMgO5cUfYF5e0LG6h7RLzpwpM/export?format=pdf&gid=616353764&potrait=false"); 

MailApp.sendEmail({ to: "xx...@gmail.com", subject:"JP RANAP "+bulanrekap+" "+ tahunrekap+" [Unit DAMIANUS-GORETTY]", body: "Yth SDM, \n\nberikut kami lampirkan laporan JP RANAP Unit DAMIANUS-GORETTY bulan "+bulanrekap+" "+ tahunrekap+". \n\nAtas perhatiannya kami ucapkan banyak terima kasih. \n\nHormat kami, \n\ndr. Ramzi, SpAn. \n\n", attachments: [blobpdf.setName("JP RANAP "+bulanrekap+" "+ tahunrekap+" Unit DAMIANUS-GORETTY.pdf")] }) 

displaytoast("JP RANAP sudah dikirim.","BERHASIL",15); }  
Below is pdf from downloaded using appscript, result in only 1 page.
PDF from downloaded using appscript only 1 page.png

Below is pdf from downloaded from the menu in googlesheet, result in 2 pages.


PDF from downloaded manual resulit in 2 pages, this is first page.png
PDF from downloaded manual result in 2 pages, this is second page.png

cwl...@gmail.com

unread,
Jun 4, 2023, 7:44:15 AM6/4/23
to Google Apps Script Community
In your "getFileAsBlob()" call, look at some of these additional options you can add to the URL.
https://gist.github.com/Spencer-Easton/78f9867a691e549c9c70

Good luck!

Ramzi Djauhari

unread,
Jun 4, 2023, 10:25:51 AM6/4/23
to google-apps-sc...@googlegroups.com
Thanks a lot Sir! I’ll check it out. 

Regards,
Ramzi

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/56a14545-96ac-4b0a-b569-27686f3c8c1an%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages