Use PDF.js offline

前端 未结 1 1382
南笙
南笙 2020-12-17 03:02

Is it possible to use PDF.js without having the website online? I\'m trying to do a simple offline website that reads pdf using pdf.js but it won\'t work without being onlin

相关标签:
1条回答
  • 2020-12-17 03:32

    Yes absolutely you can use it offline. Download the latest version here.

    Now extract the zip file and put it on a server(use xampp/wamp/lamp or any other localhost) because the worker is not enabled for file:// urls.

    To show the pdf files traverse to web/viewer.html from the localhost and it should load its default pdf.

    As to the question about how to show your pdf's use: viewer.html?file=relative/path/to/your/pdf

    Say for example inside the web folder(the one in which viewer.html is there) of your pdf.js you create a directory say named pdfFiles and in it you add a pdf named say mypdf.pdf in it then to display it use: viewer.html?file=pdfFiles/mypdf.pdf and it will display it.

    Look here for more details on how to dynamically assign PDF file paths to the viewer. If you have any other queries let me know. I have used pdf.js offline and it works wonderfully on almost all the browsers I know.

    0 讨论(0)
提交回复
热议问题