【发布时间】:2018-01-07 16:14:24
【问题描述】:
我设法让一个脚本运行,该脚本自动将 PDF 转换为 Google Doc 格式。我们似乎遇到的问题是 PDF 中也有图像。当我们将 PDF 转换为 Google Doc 时,Google Doc 没有图像,只有文本。我相信发生这种情况的原因是由于 OCR。我是否可以自动化脚本以将 PDF 上的图像也转换为 Google Docs?
这里是有问题的脚本:
GmailToDrive('0BxwJdbZfrRZQUmhldGQ0b3FDTjA', '"Test Email"');
function GmailToDrive(folderID, gmailSubject){
var threads = GmailApp.search('subject: ' + gmailSubject + ' -label: Imported'); // performs Gmail query for email threads
for (var i in threads){
var messages = threads[i].getMessages(); // finds all messages of threads returned by the query
for(var j in messages){
var attachments = messages[j].getAttachments(); // finds all attachments of found messages
var timestamp = messages[j].getDate(); // receives timestamp of each found message
var date = Utilities.formatDate(timestamp, "MST", "yyyy-MM-dd"); // rearranges the returned timestamp
for(var k in attachments){
var fileType = attachments[k].getContentType();
Logger.log(fileType);
if (fileType = 'application/pdf') { // if the application is a pdf then it will convert to a google doc.
var fileBlob = attachments[k].copyBlob().setContentType('application/pdf');
var resource = {
title: fileBlob.getName(),
mimeType: fileBlob.getContentType()
};
var options = {
ocr: true
};
var docFile = Drive.Files.insert(resource, fileBlob, options);
}
}
}
}
}
【问题讨论】:
标签: pdf google-apps-script google-drive-api gmail google-docs