Export Google Sheets to a landscape PDF

1,530 views
Skip to first unread message

Chris Robson

unread,
Jan 13, 2022, 11:25:00 AM1/13/22
to Google Apps Script Community
Hello,

I was wondering would it be possible to export a Google Sheets as a PDF that has a landscape orientation so that all the data on the page has not been shrunk to fit an A4 document with an orientation of portrait. 

Currently my GS code: 

let blob = ss.getAs('application/pdf');
  let pdf = DriveApp.getFolderById('#########################')
    .createFile(blob)
    .setName(currentMonth + 'Installs')

sets it to a portrait pdf.
    

Thanks in advance. 

Jonathan Butler

unread,
Jan 13, 2022, 2:13:41 PM1/13/22
to google-apps-sc...@googlegroups.com
This was the first result from Google I got. I think this is the one I used about a year ago.

--
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/c13b1654-2e54-4feb-8bd3-c7694f3af33fn%40googlegroups.com.

Michael O'Shaughnessy

unread,
Jan 13, 2022, 7:46:29 PM1/13/22
to google-apps-sc...@googlegroups.com
Well... I don't have a quick answer... However I did need a solution that would save each tab of a Google spreadsheet as a PDF.  Searching and digging for an "easy" way did not help.  Mostly because I needed to make sure only the right range on each tab is used as well as margins.  

I did find this site: https://kandiral.ru/googlescript/eksport_tablic_google_sheets_v_pdf_fajl.html Even though it is in Russian you can use Chrome to translate it.  I translated it to English and it worked great.  

He did a very cool thing.  He looked at the "console" of what happens when you "print" a tab to PDF.  Even though there are a lot of "parts" to the code you can focus on just what you need.

Take a look and see if it can work for you.  In the meantime I will try to get a copy of my working code up to GitHub so I can share it.

Hope this helps.

Michael

Reply all
Reply to author
Forward
0 new messages