javascript 添加注解后如何从pdf中获取base 64或二进制数据?

hmtdttj4  于 2023-01-29  发布在  Java
关注(0)|答案(3)|浏览(560)

我正在使用mozilla pdf js查看器。最初我通过iframe将我的base 64字符串显示到我的页面中。

const base64 = 'JVBERi0xLjMNJcjIyMjIyMgNMSAwIG9iago8PC9UeXBlL0NhdGFsb2cvT3V0bGluZXMgMiAwIFIvUGFnZXMgMyAwIFIvTWV0YWRhdGEgMTEgMCBSPj4NCmVuZG9iagoyIDAgb2JqCjw8L1R5cGUvT3V0bGluZXMvQ291bnQgMD4+DQplbmRvYmoKMyAwIG9iago8PC9UeXBlL1BhZ2VzL0NvdW50IDIvS2lkc1s0IDAgUiA2IDAgUl0+Pg0KZW5kb2JqCjQgMCBvYmoKPDwvVHlwZS9QYWdlL1BhcmVudCAzIDAgUi9SZXNvdXJjZXM8PC9Gb250PDwvRjEgOSAwIFI+Pi9Qcm9jU2V0IDggMCBSPj4vTWVkaWFCb3hbMCAwIDYxMiA3OTJdL0NvbnRlbnRzIDUgMCBSL0Fubm90c1sxNiAwIFIgMTcgMCBSIDE4IDAgUiAxOSAwIFJdPj4NCmVuZG9iago1IDAgb2JqCjw8L0ZpbHRlci9GbGF0ZURlY29kZS9MZW5ndGggMzAyPj5zdHJlYW0NCnicvVPRSsMwFH3PV5xHBb22WdOmj5tuD8JAsfge1nTLaNPZpCJ+va3bXgZmE8EkcHMezjncc7nsjXE8slnBIoy3W7O7RQyeoaiYyGiSCWScE5coSnaFKV5Ms6s1nh4WWJjhc41iy+bFKDEy42hkpjlxgVRKSqMDs9gYh+EpuEbVNUrdtNb5TnnTWtCurFCNerdBxTShLEr2itveeVRth95pGAu/0Xg1ne9VjaVebZQ1Kwff+7YzqnaEZdtpeP3hCVNbohlhyExwygTfm53QLoEhaS5JJsdMfyP6EwyZxSnJPA30MRsSsusbfI7nEsuQW5RQnhxG9Oe2ziYpck55zi9JMqQylEj+0zzEsFfxJDSPEzh/1/YbE+5b643tdYlhaXZqrcFBREe35y8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9Sb290IDEgMCBSL0luZm8gMTAgMCBSL0lEWzwzMDMyMkQzODQ0MkQ0NjMxMkQzMDM4MkQzNzM4MkQ0ND48NDE0NTJENDU0MzJEMzUzNjJEMzEzMzJEMzEzMjJEMzQ+XS9TaXplIDIwPj4Kc3RhcnR4cmVmCjY1MjUKJSVFT0YK'

function base64ToBlob(base64, type = "application/octet-stream") {
    const binStr = atob(base64);
    const len = binStr.length;
    const arr = new Uint8Array(len);
    for (let i = 0; i < len; i++) {
        arr[i] = binStr.charCodeAt(i);
    }
    return new Blob([arr], { type: type });
}
const blob = base64ToBlob(base64, 'application/pdf');
const blobUrl = URL.createObjectURL(blob);
var url = "/web/viewer.html?file=" + blobUrl;
var iframe = document.getElementById('pdf-viewer');
iframe.src = url;
iframe.addEventListener("load", function () {
    setTimeout(() => {
        let PDFViewerApplication = window.iframe.contentWindow.PDFViewerApplication;
        console.log('PDFViewerApplication', PDFViewerApplication);
    })
});
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>'Hello, world!' example</title>
  <link rel="stylesheet" href="index.css">
</head>
<body>
<iframe id="pdf-viewer"></iframe>
<button class="download-btn">Download</button>
<script src="index.js"></script>
</body>
</html>

加载PDF后,我可以选择添加一些其他注解,例如自由文本功能或自绘制

但我找不到访问此文件的引用并将其转换为base 64的方法。因此,在用户进行所有修改后,我将获得base 64以及旧pdf和新pdf中的所有注解。
我找不到这样的例子。
我通过PDFViewerApplication属性访问pdf查看器引用。我有这样一个变量,并且有一堆属性和方法可从pdf js查看器库中获得。
我怎样才能得到base 64和所有的注解或者二进制格式?

8hhllhi2

8hhllhi21#

我通过查看器js库的源代码进行了调查,有一个save方法可以将文档与注解一起保存。我正在使用这个库的一些内部方法来获取pdf文件的示例,获取它的二进制数据,然后将其转换为base64

let binary;
async function save() {
    let PDFViewerApplication = window.iframe.contentWindow.PDFViewerApplication;
    if (PDFViewerApplication._saveInProgress) {
      return;
    }
    PDFViewerApplication._saveInProgress = true;
    await PDFViewerApplication.pdfScriptingManager.dispatchWillSave();
    const url = PDFViewerApplication._downloadUrl,
      filename = PDFViewerApplication._docFilename;
    try {
      PDFViewerApplication._ensureDownloadComplete();
      const data = await PDFViewerApplication.pdfDocument.saveDocument();
      console.log('save binary', data);
      const blob = new Blob([data], {
        type: "application/pdf"
      });
      binary = data;
      convertBinaryToBase64(data);
    //   await PDFViewerApplication.downloadManager.download(blob, url, filename);
    } catch (reason) {
      console.error(`Error when saving the document: ${reason.message}`);
      await PDFViewerApplication.download();
    } finally {
      await PDFViewerApplication.pdfScriptingManager.dispatchDidSave();
      PDFViewerApplication._saveInProgress = false;
      console.log('finally', binary);
    }
    if (PDFViewerApplication._hasAnnotationEditors) {
      PDFViewerApplication.externalServices.reportTelemetry({
        type: "editing",
        data: {
          type: "save"
        }
      });
    }
  }
igetnqfo

igetnqfo2#

这是绝对没有问题的。这就是Adobe PDF如何使用PDF字段注解将信息发送回Acroforms中的母服务器(通过提交邮件按钮),但由于不安全和笨拙,除了一些政府/组织表单,坚持使用Acrobat Reader来控制修改后数据的上传。

  • 您(作为用户)修改下载的PDF的html指令,添加文本或行在浏览器PDF二进制扩展,如Acrobat Reader或SumatraPDF插件或Chrome(Foxit)或FireFox(Mozilla PDF.js).他们都做大致相同的一个或两个奇怪的差异.例如,他们都使用不同的临时存储文件名,因此没有一个共同的.

  • 您保存注解修改,通过重命名文件到CPU(设备)文件系统上的文件夹中。(如果用户同意,您可以设置相同的名称)。请参见上面的文件名只是临时本地名称。因此需要重命名为drive:\folder\file. pdf
  • 然后运行该OS(本机系统)Base64应用工具,对于Windows用户,该应用工具通过certutil.exe运行。对于Linux或Mac,该应用工具应该是base64 -e
  • 然后要求用户从他们的文件系统上传base64文件(使用NEW.PDF的文件选择器要容易得多。
lg40wkob

lg40wkob3#

要从带注解的PDF文件获取二进制数据,您可以使用PDF库或允许以编程方式操作PDF的工具。提取二进制数据,添加注解,保存并再次提取数据。有关特定方法,请查看库的文档。

相关问题