javascript Angular use pdf.js and Elasticpdf tutorial - js as empty, otherwise the compressed

📅 2026-11-30 👤 拼多多助力营销技巧 📂 赚钱项目 👁️ 448 次阅读

Abstract: This article introduces how to use pdf.js and the pdf.js-based annotation development kit Elasticpdf in Angular. The integration can be completed in 5 simple steps, including cloud server. The sample code is simple and shared at the end of the article. You can complete the project integration by copying and pasting. 拼多多帮助力入口

1. Code package and Demo

1.1 Library Introduction

ElasticPDF is based on the open source pdf.js (Demo:https://mozilla.github.io/pdf.js/web/viewer.html) and adds a variety of out-of-the-box PDF annotation features. The code package continues the independent and completely offline structure style of pdf.js-dist, and only adds offline Javascript code to support annotations. It can be quickly and perfectly integrated into any project environment that can run Javascript, HTML, and CSS, and run perfectly in both public and intranet environments.

1.2 Online Demo

For the different features and budget requirements, there are two versions of the products, they are only differ in the final annotation saving stage, demos are as follows:

① Annotation synthesis version: https://demos.libertynlp.com/#/pdfjs-annotation

② Professional annotation version: https://www.elasticpdf.com/demo

2. Move to Angular project

Move pdf.js or Elasticpdf package to the src/assets folder of your Angular project.

Snapshot of pdf.js running in Angular project.

3. Import the viewer.html file

① Use

If error appears after importing viewer.html and the message is Uncaught SyntaxError: Cannot use import statement outside a module, then you need to change import module of viewer.js and pdf.js in viewer.html by adding type='module'. Otherwise, because Vite automatically injects code into js and create the above error.

// import pdf.js and viewer.js

// changed importing pdf.js and view.js

② Set the default value of defaultUrl in viewer.js as empty, otherwise the compressed.tracemonkey-pldi-09.pdf file will be loaded by default when viewer.html is imported in step ①, affecting the process of custom loading files. The viewer.js in the Elasticpdf code package has been modified already.

// original defaultUrl

defaultOptions.defaultUrl = {

value: "compressed.tracemonkey-pldi-09.pdf",

kind: OptionKind.VIEWER

};

// set as empty

defaultOptions.defaultUrl = {

value: "",

kind: OptionKind.VIEWER

};

③ Call the initialApp() function under the,javascript

标签: 拼多多助力网站平台 赚钱项目 拼多多助力网 首码项目 手赚APP
拼多多助力营销技巧