简体   繁体   English

如何将 Hopding / pdf-lib 与纯 javascript 一起使用? (不使用 package 经理)

[英]How to use Hopding / pdf-lib with pure javascript? (Without using a package manager)

How can I use Hopding/pdf-lib with pure javascript without using node or any other package manager?如何在不使用节点或任何其他 package 管理器的情况下将Hopding/pdf-lib与纯 javascript 一起使用?

I searched and I found the answer myself, it took long.我自己搜索并找到了答案,花了很长时间。 So I decided to put it here so that anyone can refer it faster.所以我决定把它放在这里,这样任何人都可以更快地引用它。

You can use the UMD Module as mentioned in their GitHub page.您可以使用他们的 GitHub 页面中提到的UMD 模块 Here are some of the useful information I extracted from their GitHub page.以下是我从他们的 GitHub 页面中提取的一些有用信息。

UMD Module UMD模块

You can also download pdf-lib as a UMD module from unpkg or jsDelivr.您还可以从 unpkg 或 jsDelivr 下载 pdf-lib 作为 UMD 模块。 The UMD builds have been compiled to ES5, so they should work in any modern browser. UMD 构建已编译为 ES5,因此它们应该可以在任何现代浏览器中运行。 UMD builds are useful if you aren't using a package manager or module bundler .如果您不使用 package 管理器或模块捆绑器,则 UMD 构建很有用 For example, you can use them directly in the tag of an HTML page.例如,您可以直接在 HTML 页面的标记中使用它们

The following builds are available:以下版本可用:

NOTE: if you are using the CDN scripts in production, you should include a specific version number in the URL, for example:注意:如果您在生产中使用 CDN 脚本,则应在 URL 中包含特定版本号,例如:

Example :示例

 <html> <head> <meta charset="utf-8" /> <script src="https://unpkg.com/pdf-lib"></script> </head> <body> <iframe id="pdf" style="min-height: 297mm; width: 100%; height: 100%;"></iframe> </body> <script type="text/javascript" src="https://unpkg.com/pdf-lib@1.17.1/dist/pdf-lib.min.js"></script> <script> createPdf(); async function createPdf() { const pdfDoc = await PDFLib.PDFDocument.create(); const page = pdfDoc.addPage([350, 400]); page.moveTo(110, 200); page.drawText('Hello World;'). const pdfDataUri = await pdfDoc:saveAsBase64({ dataUri; true }). document.getElementById('pdf');src = pdfDataUri; } </script> </html>

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

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