PDF.js for NexT
Introduce
This is a plugin that allows to preview PDF files in the blog pages.
If the browser supports embedded PDFs natively, NexT will create a <embed>
tag and include the PDF file on your website. Otherwise, it will create a <iframe>
tag and uses PDF.js by @mozilla to render the pdf file.
Follow the guide below to install the plugin.
Installation
Step 1 → Go to Hexo dir
Change dir to Hexo directory. There must be source
, themes
and other directories:
1 | $ cd hexo-site |
Step 2 → Install plugin
If you have already added the Hexo directory to a git repository, then install this plugin as a git submodule:
1 | $ git submodule add https://github.com/next-theme/theme-next-pdf source/lib/pdf |
Otherwise, install the plugin to source/lib
directory via git clone
:
1 | $ git clone https://github.com/next-theme/theme-next-pdf source/lib/pdf |
Step 3 → Set it up
Enable the plugin in NexT _config.next.yml
file:
1 | # PDF tag |
Find and edit skip_render
settings in Hexo _config.yml
file:
1 | skip_render: |
Usage
In order to embed PDF files in the article, you just need to create pdf
tags with the URL of your local PDF file, e.g.
1 | {% pdf /path/to/your/file.pdf %} |
Notice: Do not use cross-origin PDF files, it might be blocked by the CORS policy.
Enjoy it!
Update
1 | $ cd hexo-site/source/lib/pdf |