pdf.js 相关问题

pdf.js是一个基于HTML5的可移植文档格式(PDF)渲染器。

我想从 PDF 中提取孟加拉语文本

我想将孟加拉语 PDF 转换为文本文件。我当前使用的工具 poppler-utils 的 pdftotext 无法提供准确的结果,因为 PDF 使用 Kalpurush 字体。有没有什么工具可以...

回答 1 投票 0

在pdf.js中恢复和渲染注释

我正在使用 pdf.js 查看器。我能够创建注释、检索它们并将它们存储为 json。 为了从控制台获取注释,我使用这个; PDFViewerApplication.pdfDocument._transport.annotationS...

回答 2 投票 0

使用 open 方法打开新文件后,PDF.js 丢失事件监听器

我正在使用 PDF.js 直接添加参考文献 <p>我正在使用 <a href="https://mozilla.github.io/pdf.js/" rel="nofollow noreferrer">PDF.js</a></p> <p>直接添加参考文献</p> <p><pre><code> &lt;link rel=&#34;resource&#34; type=&#34;application/l10n&#34; href=&#34;/locale/locale.json&#34;&gt; &lt;script src=&#34;build/pdf.js&#34; type=&#34;module&#34;&gt;&lt;/script&gt; &lt;link rel=&#34;stylesheet&#34; href=&#34;/viewer.css&#34;&gt;</code></pre></p> <p>我想使用另一个插件名称删除特定页面<a href="https://pdf-lib.js.org/" rel="nofollow noreferrer">pdf-lib</a></p> <p>我执行以下操作</p> <p>1- 从 <a href="https://mozilla.github.io/pdf.js/" rel="nofollow noreferrer">PDF 查看器</a></p> 将 PDF 文件读取为 Base64 <pre><code>async function ReadPDFFromViewer() { var pdfFileBytes = await PDFViewerApplication.pdfDocument.saveDocument(); var b64encoded = _arrayBufferToBase64(pdfFileBytes); return b64encoded; } function _arrayBufferToBase64(buffer) { var binary = &#39;&#39;; var bytes = new Uint8Array(buffer); var len = bytes.byteLength; for (var i = 0; i &lt; len; i++) { binary += String.fromCharCode(bytes[i]); } return window.btoa(binary); } </code></pre> <p>2- 使用 <a href="https://pdf-lib.js.org/" rel="nofollow noreferrer">pdf-lib</a></p> 加载和删除目标页面 <pre><code> var currentFilePDFBase64 = await ReadPDFFromViewer(); let pdfDoc = await PDFLib.PDFDocument.load(currentFilePDFBase64); pdfDoc.removePage(currentPage) var pdfBytes = await pdfDoc.save(); </code></pre> <p>3- 在 <a href="https://mozilla.github.io/pdf.js/" rel="nofollow noreferrer">PDF Viewer</a></p> 上重新打开编辑后的文件 <pre><code> PDFViewerApplication.open({ data: pdfBytes }); PDFViewerApplication.pdfViewer.refresh(false, &#34;&#34;); </code></pre> <p>在此代码之前它可以正常工作</p> <p>问题</p> <p>重新打开已编辑的 PDF 后,编辑器上的“打开”操作不再加载新选定的文件 当我单击“打开”并选择新文件时,查看器上没有显示任何文件<strong> </strong></p>在此输入图片描述<p><a href="https://i.sstatic.net/AVPPTS8J.png" rel="nofollow noreferrer"> </a>我读取了viewer.js中的事件并到达了这行代码文件</p> <p><code> var fileInput = this._openFileInput = document.createElement(&#34;input&#34;); fileInput.id = &#34;fileInput&#34;; fileInput.hidden = true; fileInput.type = &#34;file&#34;; fileInput.value = null; document.body.append(fileInput); fileInput.addEventListener(&#34;change&#34;, function (evt) { debugger; const { files } = evt.target; if (!files || files.length === 0) { return; } eventBus.dispatch(&#34;fileinputchange&#34;, { source: this, fileInput: evt.target }); }); </code></p> <pre>我注意到在执行之前的操作后,侦听器停止触发</pre> <p>fileInput.addEventListener("更改", 函数(evt)</p> <p>我尝试再次添加事件侦听器,但 PDF 查看器仍然没有加载文件</p> <p> </p> </question>我在这段代码之后解决了这个问题<answer tick="false" vote="0"> <p><code> PDFViewerApplication.open({ data: pdfBytes }); PDFViewerApplication.pdfViewer.refresh(false, &#34;&#34;); </code></p> <pre>我必须使用 </pre><code>PDFViewerApplication</code><p><pre> 再次添加事件侦听器 </pre><code> var fileInput = PDFViewerApplication._openFileInput = document.createElement(&#34;input&#34;); fileInput.id = &#34;fileInput&#34;; fileInput.hidden = true; fileInput.type = &#34;file&#34;; fileInput.value = null; document.body.append(fileInput); fileInput.addEventListener(&#34;change&#34;, function (evt) { const { files } = evt.target; if (!files || files.length === 0) { return; } PDFViewerApplication.pdfViewer.eventBus.dispatch(&#34;fileinputchange&#34;, { source: PDFViewerApplication, fileInput: evt.target }); }); </code></p> <pre> </pre></answer>

回答 0 投票 0

如何在Apps脚本中使用外部Javascript库(PDF库)?

我需要在 Apps 脚本应用程序上修改 PDF。为此,我想使用 JS 库:PDF-LIB 我的代码: eval(UrlFetchApp.fetch("https://unpkg.com/pdf-lib/dist/pdf-lib.js").

回答 1 投票 0

PDF.js 中 isEvalSupported 选项的安全隐患是什么

PDF.js库有一个选项isEvalSupported,其说明如下: (可选)确定我们是否可以将字符串作为 JS 进行评估。主要用于 提高字体渲染性能,...

回答 2 投票 0

如何使用pdf.js在pdf文件中一次突出显示多个单词

我正在尝试使用 pdf.js 库突出显示 pdf 文件中的单词。我想要的是突出显示不按序列格式的单词。就像pdf文件中的一句话是“打印文本...

回答 1 投票 0

如何将 pdfjs 与 vue3 和 vite 一起使用?

我正在尝试使用 Vite 将我的 vue2 应用程序转换为 vue3。因为没有 webpack,所以我的 pdfjs 实现失败了。我能够渲染 pdf,但 renderTextLayer 无法正常工作(参见图片贝尔...

回答 2 投票 0

pdf.js pdfjs-dist Promise.withResolvers 不是函数

我正在尝试从pdf文件中提取数据并将其返回。这是 astro 服务器端的代码 从“pdfjs-dist”导入 * 作为 pdfjsLib; pdfjsLib.GlobalWorkerOptions.workerSrc = "...

回答 1 投票 0

使绝对定位的子项随其上升项动态调整大小

(请忽略空方块。) 没有CSS视图{高度:45em; },我得到:(位置重叠) 使用 CSS 视图 { height: 45em; },我得到:(不需要,位置不匹配) 我怎样才能拥有蓝色&l...

回答 3 投票 0

如何在PDF.js中使用注释层?

一些 PDF.js 代码提到了“注释层”,例如此处的 AnnotationLayerBuilder: https://github.com/mozilla/pdf.js/blob/95e102c07bc257c2120fd7fd9141762b2c813a1c/web/

回答 2 投票 0

pdf.js - 获取修改后的pdf文件的数据

我正在使用 https://mozilla.github.io/pdf.js/getting_started/#download 中的 pdf.js (v3.10.111) 稳定版本(适用于现代浏览器)。 我能够加载 pdf 文件并进行图形修改...

回答 1 投票 0

MAUI Blazor - .mjs 文件被分类为“application/octet-stream”

我正在尝试将预构建的 PDFjs 文件包含到我们的项目中。 我按照库的建议通过脚本标签包含它们,如下所示: <p>我正在尝试将 <a href="https://mozilla.github.io/pdf.js/getting_started/" rel="nofollow noreferrer">Prebuilt PDFjs</a> 文件包含到我们的项目中。 我按照图书馆的建议通过脚本标签包含它们,如下所示:</p> <pre><code>&lt;script src=&#34;pdfjs/build/pdf.mjs&#34; type=&#34;module&#34;&gt;&lt;/script&gt; &lt;script src=&#34;pdfjs/web/viewer.mjs&#34; type=&#34;module&#34;&gt;&lt;/script&gt; </code></pre> <p>问题是无法加载:</p> <pre><code>pdf.mjs:1 Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of &#34;application/octet-stream&#34;. Strict MIME type checking is enforced for module scripts per HTML spec. </code></pre> <p>只需使用 <pre><code>pdfjs/build/pdf.mjs</code></pre> 并将文件扩展名更改为 <pre><code>js</code></pre> 即可显示文件。 更改 <pre><code>pdfjs/web/viewer.mjs</code></pre> 上的扩展以获取更深入的功能不再起作用。</p> <p>我想遵循 <a href="https://github.com/mozilla/pdf.js/blob/master/examples/components/simpleviewer.mjs" rel="nofollow noreferrer">this</a> 示例,但我需要在 MAUI Blazor 中启用 <pre><code>.mjs</code></pre> 文件。</p> <p>有解决方法吗?</p> </question> <answer tick="false" vote="1"> <p>此错误消息表明您的 Web 服务器配置不正确,因为它为 *.mjs 文件返回了不正确的 MIME 类型。您需要更新服务器配置以返回此类文件的文本/javascript。</p> <p>这里是关于 <a href="https://github.com/mozilla/pdf.js/issues/17296" rel="nofollow noreferrer">获取阻止 PDF 显示的“MIME 类型”错误</a>的 GitHub 问题,您可以查看答案来解决该问题。</p> <p><strong>更新</strong></p> <p>我检查了blazor文档,终于发现了一些有用的东西。您可以阅读这篇关于 <a href="https://learn.microsoft.com/en-us/iis/manage/configuring-security/configure-request-filtering-in-iis" rel="nofollow noreferrer">在 IIS 中配置请求过滤</a> 的文档来设置配置。此外,我找到了<a href="https://learn.microsoft.com/en-us/iis/configuration/system.webserver/staticcontent/mimemap#configuration-sample" rel="nofollow noreferrer">配置示例</a>。</p> </answer> <answer tick="false" vote="1"> <p>我已经将.js中的所有.mjs重命名为 我已经修改了里面的所有参考文献:</p> <ul> <li>pdf/构建</li> <li>pdf/网页</li> </ul> <p>文件夹。 现在我有了一个可以使用的 MAUI blazor 混合解决方案。 显然这不是最佳解决方案,但它是一种解决方法,但我在网上搜索了几天,但什么也没找到。</p> </answer> </body></html>

回答 0 投票 0

PDFJS 在转换为文本的 pdf 表单上丢失复选标记

我一直在使用这些帖子中的代码改编版: Nodejs 中的 PDF 到文本提取器,无需操作系统依赖 pdfjs:使用正确的换行符/空格从pdf中获取原始文本 将 pdf 转换为文本:

回答 2 投票 0

PDF.js v4-默认打开findBar

我使用pdfjs-4.0.379嵌入了PDF,在之前的版本(版本2)中我有类似的内容: ... 键:“setHash”, 值:函数 setHash(hash) { //阿奎 ...

回答 1 投票 0

如何正确将multer文件数据传入LangChain.js WebPDFLoader?

我在nodejs中使用multer来处理文件上传。上传 PDF 文件时,我想将其拆分为块并将这些块存储到 RAG 应用程序的矢量存储中(使用 langchain.js)。 ...

回答 1 投票 0

使用 PDF.js 添加注释

PDF.js 目前正在添加向 PDF 添加注释的功能,预计于 5 月 23 日发布,几乎没有任何文档,也没有示例......我很难把它放出来。 ..

回答 1 投票 0

在节点上运行的 pdf.js 会引发错误,因为 HTMLElement 和 Image 未定义

我正在开发一个节点函数,它读取pdf文件并从第一页生成图像。 为了实现这一点,我使用 pdf.js 库,我已经使用命令 npm install pd...

回答 1 投票 0

如何在Vue项目中导入Mozilla PDF.js?

问题很简单。如何正确地将 PDF.js 库导入到 Vuejs 项目中? 当我记录它时,该库是未定义的。 请在此处的 codeandbox 中查看我的问题。 这就是我正在尝试的方法...

回答 7 投票 0

如何将Rangy与PDFjs文本图层一起使用?

我正在使用 Rangy 库选择文本并对其应用突出显示类,问题是何时选择部分文本,其余部分变得不可选择! 我的亮点功能: 应用突出显示(){ ...

回答 1 投票 0

如何将 Base64 编码的 pdf 与 PDF.js 中的预构建查看器一起使用?

我想使用 PDF.js 附带的预构建查看器,但我要求 PDF 必须从 Base64 编码的有效负载而不是 URL 加载。 查看器预先构建了默认值...

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.