3
我設法讓腳本在腳本自動將PDF轉換爲Google Doc格式的情況下運行。我們似乎遇到的問題是PDF文件中也有圖像。當我們將PDF轉換爲Google文檔時,Google文檔沒有圖片,只有文字。我相信這種情況發生的原因是由於OCR。是否有可能將腳本自動化以將PDF上的圖像轉換爲Google Docs?將PDF轉換爲Google文檔
這裏是腳本問題:
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);
}
}
}
}
}
我已經註釋掉了'ocr'選項並將'convert'選項設置爲true。轉換後,我們仍然會收到Google文檔中的文字,但圖像仍無處可查。 – CoreyG