【问题标题】:Saving a google spreadsheet to a pdf file font size issue将谷歌电子表格保存到 pdf 文件字体大小问题
【发布时间】:2020-09-30 13:34:41
【问题描述】:

我正在尝试将 Google 电子表格保存为 pdf 文件。虽然下面的代码有效,但保存的 pdf 文件中的字体大小很小。可以在电子表格中更改字体大小:

  var cell = ts.getRange('A1:E7');
  cell.setFontSize(12);

但最终,在保存的 PDF 中,字体大小要小得多。除了字体大小问题之外,下面的代码完成了我正在尝试做的事情。有什么建议么?谢谢。

function savePDF() {

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var ts = ss.getSheetByName('common');
  var cell = ts.getRange('A1:E7');
  cell.setFontSize(12);
  
  var url = Drive.Files.get(ss.getId()).exportLinks['application/pdf'];
  var sheetID=ts.getSheetId();
  url = url + '&size=letter' + //paper size
  '&portrait=true' + //orientation, false for landscape
    '&fitw=true' + //fit to width, false for actual size
      '&sheetnames=false&printtitle=false&pagenumbers=false' + //hide optional
        '&gridlines=false' + //false = hide gridlines
          '&gid='+sheetID+
            '&fzr=false'+ //do not repeat row headers (frozen rows) on each page
              '&top_margin=0.30'+              //All four margins must be set!
                '&bottom_margin=5.00 '+         
                  '&left_margin=5.00'+            
                    '&right_margin=0.00'+ 
                      '&horizontal_alignment=RIGHT'+
                        '&vertical_alignment=BOTTOM'; 
  

  var token = ScriptApp.getOAuthToken();
  var response = UrlFetchApp.fetch(url, { headers: {'Authorization': 'Bearer ' + token}}).getBlob();
  DriveApp.getFolderById('URL ID is here').createFile(response).setName('testPDf');   //save the PDDF in Drive
  
}

【问题讨论】:

标签: javascript google-apps-script google-sheets urlfetch


【解决方案1】:

pdf 会调整字体以使所有内容都适合页面的宽度。

  • 如果您删除边距或减小left_margin - 您可以设置更大的字体。

  • 注意12 不大 - 您可能需要设置更大的字体大小。

  • 另外,请确保您的列宽调整正确。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-29
    • 1970-01-01
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    • 2014-04-13
    • 2018-01-07
    • 1970-01-01
    相关资源
    最近更新 更多