首页 > 解决方案 > Google Doc OCR 阅读横向 PDF 颠倒

问题描述

目前正在尝试编写 PDF 提取器以从 PDF 中提取特定数据并输入到 Google 表格中。我可以使用下面的代码通过 gscript 将 PDF 文本提取到 Google Doc 中,但似乎因为 PDF 是横向的,所有文本都在反向转换?即 PDF 中 blob 的最后一行转换为 Google Docs 上的第一行文本。

任何人都知道是否有办法告诉谷歌方向或对其进行编码,以便在提取时将其固定在每个页面上?

function getTextFromPDF(fileID) {
    var blob = DriveApp.getFileById(fileID).getBlob()
    var resource = {
        title: blob.getName(),
        mimeType: blob.getContentType()
    };
    var options = {
        ocr: true, 
        ocrLanguage: "en"
    };
    // Convert the pdf to a Google Doc with ocr.
    var file = Drive.Files.insert(resource, blob, options);

    // Get the texts from the newly created text.
    var doc = DocumentApp.openById(file.id);
    var text = doc.getBody().getText();
  
    // Deleted the document once the text has been stored.
    Drive.Files.remove(doc.getId());
  
    return text;
}

标签: pdfgoogle-apps-scriptgoogle-sheetsocrgoogle-docs

解决方案


推荐阅读