Skip to content

Commit c86f762

Browse files
committed
docs: add ways to integrate pdf.js section
1 parent b08da06 commit c86f762

1 file changed

Lines changed: 20 additions & 6 deletions

File tree

docs/blog/how-to-develop-a-PDF-viewer.md

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,45 @@ head:
1111

1212
Developing a PDF viewer from scratch is a complex and very challenging task, your frontend skills alone will not be enough. You will need a good understanding of the PDF file format, rendering techniques, and performance optimization.
1313

14-
## Four Major ways to Develop a PDF Viewer
14+
## Four Major Ways to Develop a PDF Viewer
1515

1616
### Based on images
1717

1818
Convert each page of the PDF into an image (e.g., PNG or JPEG) on the server side. Then, display these images in a web application using HTML `<img>` tags or a JavaScript image viewer library. This approach is relatively simple but may not provide the best user experience, especially for large documents. It's not extensible and all other features like text selection, search, annotations, etc. will be limited to what you can do with images.
1919

2020
### Using PDF.js
2121

22-
[PDF.js](https://mozilla.github.io/pdf.js/) is an open-source project developed by Mozilla built using HTML5 technologies. It allows you to render PDF documents directly in the browser. The limitation of this approach is that PDF.js is not developer friendly, the official default viewer is not easy to integrate into existing applications, and customizing it can be challenging. The official packa#ge provided is `pdfjs-dist/`, which only includes the core PDF rendering library without the viewer UI. The default viewer is built on the top of this core library and the whole UI code is not published as a separate package. It's the source of chaos in the ecosystem, but the bad news is that it's on purpose. They try to avoid people customizing the viewer too much to reduce maintenance burden.
22+
[PDF.js](https://mozilla.github.io/pdf.js/) is an open-source project developed by Mozilla built using HTML5 technologies. It allows you to render PDF documents directly in the browser. The limitation of this approach is that PDF.js is not developer friendly, the official default viewer is not easy to integrate into existing applications, and customizing it can be challenging. The official package provided is `pdfjs-dist/`, which only includes the core PDF rendering library without the viewer UI. The default viewer is built on the top of this core library and the whole UI code is not published as a separate package. It's the source of chaos in the ecosystem, but the bad news is that it's on purpose. They try to avoid people customizing the viewer too much to reduce maintenance burden.
23+
24+
### Three ways to integrate PDF.js
25+
26+
#### Embedding with iframe
27+
28+
You can use the default viewer provided by PDF.js by embedding it in an `<iframe>`. This is the easiest way to get started, but it offers limited customization options.
29+
30+
#### Using `@document-kits/viewer`
31+
32+
[This](https://priestch.github.io/document-viewer/) project is an open-source PDF viewer built on top of PDF.js. It provides an out-of-the-box PDF viewer that is easy to integrate into any web application. It is framework-agnostic and supports multiple documents, custom toolbars, and easy synchronization with upstream PDF.js code. You can check the [Get Started Guide](https://priestch.github.io/document-viewer/docs/get-started.html) to learn how to use it.
33+
34+
#### Building your own viewer based on `pdfjs-dist/`
35+
36+
If you want full control over the viewer UI and functionality, you can build your own PDF viewer using the `pdfjs-dist/` package. This requires substantial effort, deep knowledge of PDF.js internals, strong frontend development skills, and performance optimization expertise. You'll need to implement navigation, zooming, text selection, annotations, and more from scratch.
2337

2438
### Using Compiled PDFium Wasm
2539

2640
> “Foxit is honored to be chosen as the PDF provider for the open-source PDFium project,” says Eugene Xiong – Founder and Chairman of the Board at Foxit. “Our high performance, highly accurate, and platform independent software technology will help developers everywhere to incorporate powerful PDF technology when creating innovative applications.”
2741
2842
[PDFium](https://pdfium.googlesource.com/pdfium/) is an open-source PDF rendering engine first developed by [Foxit](https://www.foxit.com/nl/company/press/5606.html), then acquired by Google. It is used in the Chrome browser and other applications. PDFium can be compiled to WebAssembly (Wasm), allowing it to run in web browsers. This approach provides an alternative to PDF.js for rendering PDF documents in the browser. However, integrating PDFium into a web application can be complex and may require significant effort to set up and optimize. The wasm only provides the rendering engine, and you still need to build the viewer UI and other features on top of it.
2943

30-
#### Related Projects
44+
### Related Projects
3145

32-
##### [PDFium Library](https://github.com/paulocoutinhox/pdfium-lib)
46+
#### [PDFium Library](https://github.com/paulocoutinhox/pdfium-lib)
3347

3448
A project that provides precompiled PDFium WebAssembly module for easy integration into web applications. It simplifies the process of using PDFium in the browser by providing a ready-to-use Wasm module. There is a [web demo](https://pdfviewer.github.io/) available to show how you can use it to display a PDF file.
3549

36-
##### [EmbedPDF](https://www.embedpdf.com/)
50+
#### [EmbedPDF](https://www.embedpdf.com/)
3751

38-
A Open Source PDF viewer also built using PDFium Wasm. It provides a polished, production-ready PDF viewer that drops into your app in seconds. Perfect for standard use cases. You can build you own custom viewer UI from scratch based on their render engine, or using their default viewer.
52+
An Open Source PDF viewer also built using PDFium Wasm. It provides a polished, production-ready PDF viewer that drops into your app in seconds. Perfect for standard use cases. You can build your own custom viewer UI from scratch based on their render engine, or using their default viewer.
3953

4054
![EmbedPDF Viewer](/assets/embed_pdf_viewer.png)
4155

0 commit comments

Comments
 (0)