[Hexo] Use theme-next-pdf plugin and hexo-theme-next (NexT) theme to download or preview PDF files in Hexo
Download or preview PDF files
Hexo is a fast, simple & powerful blog framework. It use plugins to provide features powerful APIs for limitless extensibility. Various plugins are available to support most template engines (EJS, Pug, Nunjucks, and many others). Easily integrate with existing NPM packages (Babel, PostCSS, Less/Sass, etc).
This article is about how to download or preview PDF files in Hexo.
PDF Folders
Global PDF Folder
Hexo Assets are non-post files in the source folder, such as images, CSS or JavaScript files. For instance, If you are only going to have a few PDF files in the Hexo project, then the easiest way is to keep them in a source/pdfs directory. Then, you can preview(by Browser preview) or download them using something like
1 | [pdf demo](/pdfs/pdf-demo.pdf). |
Post PDF Folder
For users who expect to regularly serve PDF files, and for those who prefer to separate their PDF files on a post-per-post basis, Hexo also provides a more organized way to manage assets. This slightly more involved, but very convenient approach to asset management can be turned on by setting the post_asset_folder setting in _config.yml to true.
1 | # _config.yml |
With asset folder management enabled, Hexo will create a folder every time you make a new post with the hexo new [layout]
For example,
1 | [pdf demo](pdf-demo.pdf). |
or
1 | [pdf demo](./pdfs/pdf-demo.pdf). |
Preview PDF Embed
theme-next-pdf
is a plugin that allows to preview PDF files embed in the blog pages.
Installation
Install module to source/lib directory.
Ihis installation is optional if youe just want to preview external PDF files.
1 | Use git submodule add |
Configuration
Enable module in NexT ./_config_next.yml file:
1 | # _config_next.yml |
Usage
In order to embed PDF files in the article, you just need to create an pdf
tag with the URL of your local PDF file, e.g.
-
Local PDF files
Remember to put
file.pdf
into thesource/path/to/your/file.pdf
, such assource/pdfs/file.pdf
.1
{% pdf /path/to/your/file.pdf %}
-
External PDF files:
1
{% pdf http://www.africau.edu/images/default/sample.pd %}
Notice: Do not use cross-origin PDF files, it might be blocked by the CORS policy, unless you have resoved it.
Enjoy it!
References
[1] next-theme/theme-next-pdf: PDF.js for NexT. - https://github.com/next-theme/theme-next-pdf
[2] Tag Plugins | Hexo - https://hexo.io/docs/tag-plugins
[3] Asset Folders | Hexo - https://hexo.io/docs/asset-folders.html