我正在使用我在此处找到的应用程序脚本从电子表格生成 PDF 文件。这个使用了很好的旧方法 getAs('application/pdf') 并且效果很好。
问题在于以这种方式生成的 PDF 文档具有不需要的不对称边距(右侧较大,左侧较窄)。我只是想让页面居中。奇怪的是,当我从 Google 菜单 File -> Print(或 Ctrl + P)打印时,文档显示正确居中。
我的代码如下所示:
function CreaPDF() {
  //The function prints an invoice to PDF. First it copies spreadsheet to a new document.
  //Deletes all sheet except the one to print. Saves it to PDF. 
  //It overwrites any existing doc with same name.
  var sourceSpreadsheet = SpreadsheetApp.getActive();          
  var sheetName = "Factura";
  var folderID = getParentFolder(); // Folder id to save in a folder.
  var sourceSheet = …Run Code Online (Sandbox Code Playgroud)