Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Apps Script print sheet with margins

There is a nice GAS script to print a Google sheet in google app script print button

As discussed on the Google Cloud Connect (https://www.cloudconnect.goog/message/77627), we are trying to identify a way to control the margins.

There is also a similar question over on the Google Product Forums at https://productforums.google.com/forum/#!topic/docs/DQxnJwoDn0c

like image 603
Kevin A. McGrail Avatar asked Dec 07 '25 08:12

Kevin A. McGrail


2 Answers

You might find this script useful.

I think that it might answer your question on the margins plus it has a few other helpful settings that you can play with.

function printPdf() {
    SpreadsheetApp.flush();
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheet = ss.getActiveSheet();
    var gid = sheet.getSheetId();
    var pdfOpts = '&size=A3&fzr=true&portrait=false&fitw=true&gridlines=false&printtitle=true&sheetnames=true&pagenumbers=true&attachment=false&gid='+gid;
    var url = ss.getUrl().replace(/edit$/, '') + 'export?format=pdf' + pdfOpts
    var app = UiApp.createApplication().setWidth(300).setHeight(100);
    app.setTitle('Your Print Preview is Ready');
    var link = app.createAnchor('Open Print Preview', url).setTarget('_new');
    app.add(link);
    ss.show(app);
}

See also: Printing a sheet to PDF

like image 155
Peter Clarke Avatar answered Dec 10 '25 00:12

Peter Clarke


This was also reported in this thread. I suggest to file a feature request for this.

like image 24
abielita Avatar answered Dec 10 '25 00:12

abielita



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!