使用Google脚本编辑器将PDF转换为Doc [英] Convert PDF to Doc with Google Script Editor

查看:178
本文介绍了使用Google脚本编辑器将PDF转换为Doc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望使用Google脚本编辑器在Drive中将PDF转换为Google Doc.但是,不断收到错误消息不支持从应用程序/pdf转换为应用程序/doc".可以在脚本中进行此转换吗?我的尝试如下,很高兴听到任何建议.

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);

}

推荐答案

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);  
}

将Drive API添加到Google Apps脚本项目 https://developers.google.com/apps-script/guides/services/advanced#enabling_advanced_services

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

下载驱动器 http://i.imgur时,您会在Google驱动器上看到pdf文件ID. com/3pYvwjx.png

这篇关于使用Google脚本编辑器将PDF转换为Doc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆