将Google电子表格保存为PDF文件字体大小问题

问题描述

我正在尝试将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
  
}

解决方法

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

  • 如果删除空白或减少left_margin-您可以设置更大的字体。

  • 请注意,12并不大-您可能希望设置更大的字体大小。

  • 此外,请确保正确调整了列宽。