从 Google 中的 PDF 中获取文本

Get text from PDF in Google

我有一个 PDF 文档保存在 Google 驱动器中。我可以使用 Google Drive Web UI 搜索来查找文档中的文本。

如何使用 Google Apps 脚本以编程方式提取文档中的部分文本?

参见 this gist 中的 pdfToText()

在 PDF 文件上调用 Google Drive 内置的 OCR,例如myPDF.pdf,这是你要做的:

function myFunction() {
  var pdfFile = DriveApp.getFilesByName("myPDF.pdf").next();
  var blob = pdfFile.getBlob();

  // Get the text from pdf
  var filetext = pdfToText( blob, {keepTextfile: false} );

  // Now do whatever you want with filetext...
}