有没有办法在以下脚本中设置 pdf 大小?

There is a way to set the pdf size in the following script?

如何在以下脚本中将 pdf 大小设置为 A4?另外,是否可以将 sheet 放入单个 pdf 页面?

function sendSheet() {
  var message = {
    to: "EMAIL",
    subject: "SUBJECT",
    body: "BODY",
    attachments: [SpreadsheetApp.openByUrl("URL").getAs(MimeType.PDF).setName("NAME.pdf")]
  }
  MailApp.sendEmail(message);

您可以像这样在工作表 url 参数中调整 PDF 的大小。

脚本:

function sendSheet() {
  EMAIL = '<EMAIL>'
  URL = 'https://docs.google.com/spreadsheets/d/<SPREADSHEET_ID>'
      + '/export?'
      + 'format=pdf'
      + '&size=A4' // size, (letter, legal, A4)
      + '&gid=0'; // sheetID

  // dummy call to get document access
  SpreadsheetApp.getActive();

  var response = UrlFetchApp.fetch(URL, {
    headers: {
      'Authorization': 'Bearer ' + ScriptApp.getOAuthToken()
    }
  });

  var message = {
    to: EMAIL,
    subject: "SUBJECT",
    body: "BODY",
    attachments: [response.getBlob().setName('NAME.pdf')]
  }

  MailApp.sendEmail(message);
}

似乎有一个选项可以让您将数据“适合”到一个页面中,但它会缩小您的数据(包括宽度)。

页面大小保留,但如果超过单页,它会将数据缩小为1页。请参阅预期 48 页的示例 pdf:

scale=1参数:

scale=3(适合高度)或scale=4(适合页面)参数:

如您所见,当处理大量页面并试图适应 1 时,它是不可读的。

我假设您想要的是 PDF 中的单个长页面,其中包含连续的数据,这在技术上是不可能的,因为您无法修改其页面高度(只能修改总大小)

更新:

我找到了这个完整的参数列表 here,请随意测试它们,看看您是否需要下面列表中的内容。

//All requests must include id in the path and a format parameter
//https://docs.google.com/spreadsheets/d/{SpreadsheetId}/export

//FORMATS WITH NO ADDITIONAL OPTIONS
//format=xlsx //excel
//format=ods //Open Document Spreadsheet
//format=zip //html zipped

//CSV,TSV OPTIONS***********
//format=csv // comma seperated values
// tsv // tab seperated values
//gid=sheetId // the sheetID you want to export, The first sheet will be 0. others will have a uniqe ID

// PDF OPTIONS****************
//format=pdf
//size=0,1,2..10 paper size. 0=letter, 1=tabloid, 2=Legal, 3=statement, 4=executive, 5=folio, 6=A3, 7=A4, 8=A5, 9=B4, 10=B5
//fzr=true/false repeat row headers
//fzc=true/false repeat column headers
//portrait=true/false false = landscape
//fitw=true/false fit window or actual size
//gridlines=true/false
//printtitle=true/false
//pagenum=CENTER/UNDEFINED CENTER = show page numbers / UNDEFINED = do not show
//attachment = true/false dunno? Leave this as true
//gid=sheetId Sheet Id if you want a specific sheet. The first sheet will be 0. others will have a uniqe ID. Leave this off for all sheets.
//printnotes=false Set to false if you don't want to export the notes embedded in a sheet
//top_margin=[number] Margins - you need to put all four in order fir it to works, and they have to be to
//left_margin=[number] 2DP. So 0.00 for zero margin.
//right_margin=[number]
//bottom_margin=[number]
//horizontal_alignment=CENTER Horizontal Alignment: LEFT/CENTER/RIGHT
//vertical_alignment=TOP Vertical Alignment: TOP/MIDDLE/BOTTOM
//scale=1/2/3/4 1= Normal 100% / 2= Fit to width / 3= Fit to height / 4= Fit to Page
//pageorder=1/2 1= Down, then over / 2= Over, then down
//sheetnames=true/false
//range=[NamedRange] Named ranges supported - see below

// EXPORT RANGE OPTIONS FOR PDF
//need all the below to export a range
//gid=sheetId must be included. The first sheet will be 0. others will have a uniqe ID
//ir=false seems to be always false
//ic=false same as ir
//r1=Start Row number - 1 row 1 would be 0 , row 15 wold be 14
//c1=Start Column number - 1 column 1 would be 0, column 8 would be 7
//r2=End Row number
//c2=End Column number