由於某些原因,當在Google Apps腳本中將HTML文件轉換爲PDF時,PDF的文件大小最終比原始HTML大文件。使用谷歌應用程序腳本將html文件轉換爲Adobe PDF時文件大小增加
我用來運行測試的代碼如下:
function convertHTMLtoPDF() {
// convert a specific message with an attached HTML file to PDF,
// and save it to the root directory of Google Drive
var threads = GmailApp.search('subject:(Sample HTML)');
var message = threads[0].getMessages()[0];
var attachmentName = message.getAttachments()[0].getName();
var attachment = message.getAttachments()[0].getAs("application/pdf");
DriveApp.createFile(attachment).setName(attachmentName);
}
注意:您只需要採取樣本HTML文件,我在下面的共享,將其連接到與一封主題爲:樣本HTML ,併發送給自己,讓腳本找到它。
我轉換的sample HTML文件是133 KB。腳本運行後,轉換後的爲10 MB。
我的測試結果如下:
- 轉換與谷歌Apps腳本的sample.html文件導致133 KB的HTML文件,成爲一個10 MB PDF。
- 使用Adobe Acrobat XI Pro轉換sample.html文件會導致133 KB HTML文件變爲151 KB PDF。
有誰知道爲什麼通過Google Apps腳本轉換的PDF文件大小比使用Adobe轉換時大得多?有沒有辦法減小文件大小?
在此先感謝您的幫助!
如果您想通過Google Apps腳本查看轉換結果,示例PDF文件位於:https://drive.google.com/file/d/0B7LEHSedHuTxLUlKRnlWQ05sZWs/view?usp=sharing – user3330539