PDF 阅读
约 531 字
概述
主题支持在 markdown 中嵌入 PDF 文件,它能够在页面中直接阅读 PDF 。
该功能由 vuepress-plugin-md-power 提供支持。
配置
该功能默认不启用。你需要在主题配置中开启。
.vuepress/config.ts
import { defineUserConfig } from 'vuepress'
import { plumeTheme } from 'vuepress-theme-plume'
export default defineUserConfig({
theme: plumeTheme({
markdown: {
pdf: true,
},
}),
})语法
最简单的语法如下:
@[pdf](url)指定页码
当需要打开特定页面时,使用 page 选项指定页码。为了兼容旧用法,也支持在 pdf 后直接跟随页码的简写形式 @[pdf 2](url)。
@[pdf page="2"](url) <!-- 推荐写法 -->
@[pdf 2](url)更多选项
可以添加更多的选项到 @[pdf] 中,更灵活的控制行为:
@[pdf page="2" no-toolbar width="100%" height="600px" zoom="75" ratio="16:9"](url)浏览器不支持内置 PDF 阅读器?
主题使用 <embed> 标签渲染 PDF 文件,但部分浏览器不支持内置 PDF 阅读器(通常在移动端浏览器中受限)。
对于不支持的浏览器,主题使用 PDF.js 作为降级兼容方案,默认从 https://static.pengzhanbo.cn/pdfjs/ 加载。
离线构建、内网部署或对第三方资源有合规要求时,可以通过 markdown.pdf.pdfjsUrl 指向自托管地址:
.vuepress/config.ts
import { defineUserConfig } from 'vuepress'
import { plumeTheme } from 'vuepress-theme-plume'
export default defineUserConfig({
theme: plumeTheme({
markdown: {
pdf: { pdfjsUrl: '/pdfjs/' },
},
}),
})示例
默认
输入:
@[pdf](https://plume.pengzhanbo.cn/files/sample-1.pdf)输出:
设置页码为 2
输入:
@[pdf page="2"](https://plume.pengzhanbo.cn/files/sample-1.pdf)输出:
指定高度
输入:
@[pdf height="400px"](https://plume.pengzhanbo.cn/files/sample-1.pdf)输出:
宽高比 21:29
输入:
@[pdf ratio="21:29"](https://plume.pengzhanbo.cn/files/sample-1.pdf)输出:
贡献者
更新日志
2026/10/13 15:56
查看所有更新日志
e4dae-docs: improve docs (#1071)于60619-docs: improve docs (#1069)于685a2-feat(plugin-md-power): enhance pdf embed syntax (#997)于1d04d-feat: add builtin auto-import-components (#932)于c4637-docs: update pdf assets于4d236-feat(theme)!: add collections support (#704)于0fd6c-refactor(theme): improve types and flat config (#524)于164e8-docs: improve docs于9a441-docs: update doc于
