Convert PDF to Doc with Google Script Editor

China☆狼群 提交于 2019-12-07 08:45:59

问题


I'm looking to convert PDF to google Doc in Drive using Google Script Editor. However keep getting error message "Converting from application/pdf to application/doc is not supported". Is this conversion possible in script? My attempt as below, would be great to hear any advice.

function convertdPDF2doc() {
  var pdffile = DriveApp.getFileById();
  var pdfblob = pdffile.getAs('application/doc');

  pdfblob.setName(doc.getName() + ".doc");
  DriveApp.createFile(docblob);

}

回答1:


function pdfToDoc() {  
  var fileBlob = DriveApp.getFileById('0B3m2D6239t6aWHo5TVpyYzhxV1U').getBlob();  
  var resource = {
    title: fileBlob.getName(),
    mimeType: fileBlob.getContentType()
  };
  var options = {
    ocr: true
  };
  var docFile = Drive.Files.insert(resource, fileBlob, options);  
  Logger.log(docFile.alternateLink);  
}

Add Drive API to google apps script project https://developers.google.com/apps-script/guides/services/advanced#enabling_advanced_services

You can see you pdf file id on google drive when you download it http://i.imgur.com/3pYvwjx.png



来源:https://stackoverflow.com/questions/36053198/convert-pdf-to-doc-with-google-script-editor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!