如何在 Google Script 中压缩 pdf 文件?
我已经使用 convertapi 来合并 pdf 文件,成功。但我尝试压缩最终的 pdf 文件,但未成功
合并代码OK
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([ https://v2.convertapi.com/convert/pdf/to/compress?Secret=XXXXXXX , {processData=false, method=post , data={File=Relance clients Celtys - 24/10/2019 08:33:59.pdf}, muteHttpExceptions=false}]) [0,087 seconds] [19-10-24 08:34:44:449 CEST] Échec脚本执行:Échec de la requête pour https://v2.convertapi。Code renvoyé : 400. Réponse tronquée du serverur : {"Code":4000,"Message":"参数验证错误。","InvalidParameters":{"File":["文件大小必须大于 0 字节。", “文件字段是要求...(Utilisez l'option muteHttpExceptions pour Examer la réponse entière.)(第 113 行,更详细的“代码”)[执行时间:45,