How to realize PDF preview and download?

Foreword

Preview and Download for PDF type invoices were requested during development, **PDF ** type file sources include H5 mobile terminal and **PC terminal**, and for these two different The processing of the terminal will be slightly different, which will be mentioned below.

There are many articles about PDF preview, but none of them seem to mention the possible problems, or how to choose the corresponding specific demand scenarios. Therefore, the article The core is to see which of the current implementation solutions is more suitable in combination with the actual demand scenario. Of course, I hope that everyone can correct the content in the article in the comment area, or provide a better solution.

Basic Requirements:

  • Support for full preview of the content of pdf files

  • Multi-page pdf files support page view

  • PC and mobile need to support download and preview< /strong>

Product Requirements:

  • The PC preview should support previewing on the current page

  • pdf file The font in the preview should be consistent with the font of the actual file

1461b9b544c1ae98828397eb1d42c727.jpeg

9E27229A.gif

PDF preview

Putting aside the various requirements above, let’s first summarize several common ways to realize PDF preview:

  • With the help of various class libraries, code-based preview, such as the package based on **`pdfjs-dist`**[1]

  • Directly based on the built-in PDF preview plugin of each browser, such as