简体   繁体   English

在 Google Apps 脚本中将带有图像的 PDF 转换为 Google Doc

[英]Convert PDF with images to Google Doc in Google Apps Script

I'm using Google Apps Script and Google Drive API to convert a PDF file which is stored in my drive to Google Doc.我正在使用 Google Apps Script 和 Google Drive API 将存储在我的驱动器中的 PDF 文件转换为 Google Doc。 The problem is, the PDF is converting to Google Doc but images and table formats are not coming in the newly generated doc, only texts and texts with colors are appearing.问题是,PDF 正在转换为 Google Doc,但图像和表格格式没有出现在新生成的文档中,只有带有 colors 的文本和文本出现。

My codes are given below:我的代码如下:

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

Am I doing something wrong here?我在这里做错了吗? I've been searching for solution in web but no luck.我一直在 web 中寻找解决方案,但没有运气。 How can I convert a PDF perfectly to a Google Doc?如何将 PDF 完美地转换为 Google Doc?

At the moment, this is not possible.目前,这是不可能的。 Google Drive uses basic OCR in order to transform the PDF into Docs, but it does not handle images - only text. Google Drive 使用基本的OCR将 PDF 转换为 Docs,但它不处理图像 - 仅处理文本。 If you are still interested in keeping the images you can:如果您仍然对保留图像感兴趣,您可以:

  • Call an external API that transforms PDF into DOC/DOCX files, and then upload it using {convert:true} to convert it into a Docs file.调用外部 API 将 PDF 转换为 DOC/DOCX 文件,然后使用{convert:true}上传转换为 Docs 文件。 You can use URLFetchApp for that (in this case, the conversion would work properly since it's from DOC/DOCX type to Docs type, not from PDF which is structured differenly).您可以为此使用URLFetchApp (在这种情况下,转换将正常工作,因为它是从 DOC/DOCX 类型到 Docs 类型,而不是从结构不同的 PDF )。
  • File a feature request within Google's Public issue tracker , so that this feature may be considered to be implemented.在 Google 的公共问题跟踪器中提交功能请求,以便可以考虑实施此功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM