Google apps script 在Google脚本中压缩PDF文件

Google apps script 在Google脚本中压缩PDF文件,google-apps-script,convertapi,Google Apps Script,Convertapi,如何在Google脚本中压缩pdf文件 我已经使用convertapi成功地合并了pdf文件。 但我尝试压缩最终的pdf文件,但没有成功 合并代码确定 var file = DriveApp.getFileById(idPDF1); formData['Files[' + index + ']'] = file.getBlob(); index++; var options = { 'method' : 'post', 'payload' : formData, 'muteHttpExcep

如何在Google脚本中压缩pdf文件

我已经使用convertapi成功地合并了pdf文件。 但我尝试压缩最终的pdf文件,但没有成功

合并代码确定

var file = DriveApp.getFileById(idPDF1);
formData['Files[' + index + ']'] = file.getBlob();
index++;


var options = {
'method' : 'post',
'payload' : formData,
'muteHttpExceptions': true
};

var global_pdf_name = nom_fichier + " - " + dateJour + ".pdf";
var response_glob = UrlFetchApp.fetch('https://v2.convertapi.com/pdf/to/merge?Secret=XXXXXXXXXX', options);
if(response_glob.getResponseCode() == 200) {
var contentText = JSON.parse(response_glob.getContentText());
var blob_glob = Utilities.base64Decode(contentText.Files[0].FileData);
var link_fact = destination.createFile(Utilities.newBlob(blob_glob, 'application/pdf', global_pdf_name));
//压缩代码NOK

    var formDataC = {};
    var fileC = DriveApp.getFileById(id_mergepdf);
    formDataC['File'] = fileC;
    var options = {
    'method' : 'post',
    'data' : formDataC,
    'muteHttpExceptions': false,
    'processData': false
    };

    var global_pdf_compresse = nom_fichier + " - " + dateJour + ".pdf";
    var response_globC = UrlFetchApp.fetch('https://v2.convertapi.com/convert/pdf/to/compress?Secret=XXXXXX', options);
    if(response_globC.getResponseCode() == 200) {
    var contentTextC = JSON.parse(response_globC.getContentText());
    var blob_globC = Utilities.base64Decode(contentTextC.Files[0].FileData);
    var link_factC = destination.createFile(Utilities.newBlob(blob_globC, 'application/pdf', global_pdf_compresse));
//跟踪中的错误消息

[19-10-24 08:34:44:348 CEST] UrlFetchApp.fetch([,, {processData=false,method=post,data={File=Relance-clients-Celtys- 2019年10月24日08:33:59.pdf},muteHttpExceptions=false}])[0087秒] [19-10-24 08:34:44:449 CEST]执行脚本:执行脚本 拉雷奎特倒。代码:400。Réponse Tronqueée du serveur:{“代码”:4000,“消息”:“参数验证” 错误。“,”InvalidParameters:{“文件”:[“文件大小必须大于0” 字节。“,”文件字段为requ…(使用Z l'选项 (第113页, 费希尔“代码”)[执行期间:45,23秒]


这次修改怎么样

修改脚本: 发件人: 致: 参考资料:
    • 此线程还使用ConvertAPI。因此此示例脚本可能对您有用

如果我误解了您的问题,并且这不是您想要的结果,我很抱歉。

您现在需要撤销您的convertapi令牌,您已经在原始问题中发布了它们。DriveApp.getFileById(id\u mergepdf)结果是URL还是文件数据?
var fileC = DriveApp.getFileById(id_mergepdf);
formDataC['File'] = fileC;
var options = {
'method' : 'post',
'data' : formDataC,
'muteHttpExceptions': false,
'processData': false
};
var fileC = DriveApp.getFileById(id_mergepdf).getBlob(); // Modified
formDataC['File'] = fileC;
var options = {
'method' : 'post',
'payload' : formDataC, // Modified
};