Custom page size when exporting to PDF?

3,737 views
Skip to first unread message

Google Apps Script Community

unread,
Sep 16, 2021, 5:58:07 PM9/16/21
to Google Apps Script Community
I'm exporting a sheet to a PDF file using app script and I need to set a custom page size. Is this possible with app script?

var exportUrl = url_base + 'export?exportFormat=pdf&format=pdf' +
'&gid=' + sheetTabId +
'&id=' + ssID +
'&range=' + range +
'&size=A3' + // paper size - How do I use a custom size and specify the dimensions?
'&scale=4' +
'&portrait=false' +
'&sheetnames=false' +
'&printtitle=false' +
'&pagenumbers=false' +
'&gridlines=false' +
'&fzr=false' +
'&top_margin=0.0' +
'&bottom_margin=0.0' +
'&left_margin=0.0' +
'&right_margin=0.0' +
'&horizontal_alignment=CENTER' +
'&vertical_alignment=MIDDLE';

Michael O'Shaughnessy

unread,
Sep 16, 2021, 7:00:33 PM9/16/21
to google-apps-sc...@googlegroups.com
I needed to export numerous tabs from a Google sheet and I really did not want to go to each tab individually.  So I too sought out a GAS solution.  I found this site to be very informative:

It is in Russian but Chrome translated it to English no problem.  He does a great job of explaining how he came up with his solution.  He did this by setting all the settings in the Print dialog and printed it to a PDF.  He then used the Chrome developer tools to capture the URL that did the printing.

My solution was easy, just needed the same range of cells on each tab printed to each own PDF page so I have no help with the custom page size. BUT, if you follow his logic you might be able to figure out what you need to do.

By the way, it looks like you are following the same patterns found here https://gist.github.com/Spencer-Easton/78f9867a691e549c9c70.  I did try that but I found it difficult.  When I found the Russion site, it all just seemed to "click" and I understood the "flow of his code".  So, give it a shot!

Hope this helps...

--
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/167904ed-723a-4d0d-be7e-03946875093dn%40googlegroups.com.

Darren D'Mello

unread,
Sep 17, 2021, 5:08:41 AM9/17/21
to Google Apps Script Community
Follow this video for getting the custom page size - https://www.youtube.com/watch?v=SMDmTIAfzzc
Then use the URL to hard code to your apps script code

exportUrl - 'your_obtained_url'

--
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/167904ed-723a-4d0d-be7e-03946875093dn%40googlegroups.com.


--
Best,
Darren

Hacı Bayram TAĞ

unread,
Nov 9, 2021, 10:02:04 AM11/9/21
to Google Apps Script Community
Below is the example for setting up custom size pages.

var exportUrl = url_base + 'export?exportFormat=pdf&format=pdf' +
'&gid=' + sheetTabId +
'&id=' + ssID +
'&range=' + range +
//'&size=A3' + custom paper size  (width x hegiht) unit INCH   Example : Widht 7,2 CM X Hegiht 11CM        7,2 /2,54=2.8346456692913384 INCH X 11/2,54=4.330708661417321 INCH
'&size= 2.8346456692913384 X 4.330708661417321'
'&scale=4' +
'&portrait=false' +
'&sheetnames=false' +
'&printtitle=false' +
'&pagenumbers=false' +
'&gridlines=false' +
'&fzr=false' +
'&top_margin=0.0' +
'&bottom_margin=0.0' +
'&left_margin=0.0' +
'&right_margin=0.0' +
'&horizontal_alignment=CENTER' +
'&vertical_alignment=MIDDLE';

Regards
Bayram 

17 Eylül 2021 Cuma tarihinde saat 13:08:41 UTC+4 itibarıyla miscellan...@gmail.com şunları yazdı:

Elhanan Ben

unread,
Apr 6, 2022, 2:11:20 PM4/6/22
to Google Apps Script Community

Link Computer

unread,
May 11, 2022, 7:53:54 PM5/11/22
to Google Apps Script Community
'&size=A3' + // paper size - How do I use a custom size and specify the dimensions?
Solution for me:
'&size=AxB' //A = Width you gonna use (inch); B = Height you gonna use (inch)
//Don't use mayus and space.  Put both together with the "x" Example: '&size=2.8363636363x5.9055118110' equivalent to 7.2cm and 15cm

yan wkcfamily

unread,
May 29, 2022, 12:49:03 AM5/29/22
to Google Apps Script Community
It works. Thank you very much all for your contribution.
Best regards.
Richard Yan

Reply all
Reply to author
Forward
0 new messages