Color mode

PDF

Inline PDF attachment viewing for Obsidian wikilinks.

日本語

Overview

pdf() renders embedded PDF attachments (![[report.pdf]]) with the browser-native PDF viewer instead of a download-only card. The renderer is SSR/build-time only; no client JavaScript is required.

@riebeckite/plugin-obsidian-markdown resolves a non-image, non-Markdown wikilink target to the generic attachment render kind, so PDFs are detected by their .pdf extension. A literal kind: "pdf" target is also accepted, so the plugin keeps working if a producer reports a PDF-specific kind later.

The renderer runs before @riebeckite/plugin-attachment and @riebeckite/plugin-media (plugin order: -20), so a PDF embed is never captured by the generic attachment card. Register attachment() alongside to keep download links for non-PDF files.

Usage

ts
import { defineConfig } from "@riebeckite/core";
import { attachment } from "@riebeckite/plugin-attachment";
import { obsidianMarkdown } from "@riebeckite/plugin-obsidian-markdown";
import { pdf } from "@riebeckite/plugin-pdf";
 
export default defineConfig({
  // ...
  plugins: [obsidianMarkdown(), attachment(), pdf()],
});

Rendering

Embed (![[report.pdf]]):

html
<figure class="rr-pdf" data-pdf-path="..." style="--rr-pdf-height: 640px">
  <object
    class="rr-pdf__viewer"
    data="/assets/attachments/report.pdf#page=1"
    type="application/pdf"
    aria-label="report.pdf"
  >
    <a class="rr-pdf__fallback" href="..." download>Download PDF</a>
  </object>
  <figcaption class="rr-pdf__meta">
    <span class="rr-pdf__format">PDF</span>
    <span class="rr-pdf__name">report.pdf</span>
    <span class="rr-pdf__size">1.2 MB</span>
    <a class="rr-pdf__download" href="..." download>Download PDF</a>
  </figcaption>
</figure>
  • The <object> uses the browser's built-in PDF viewer; its nested link is the graceful fallback for clients without PDF support.
  • A visible download link and the format badge, file name, and size are always available below the viewer. Size is read from config.content.directory and omitted when the file cannot be read.
  • initialPage and toolbar are encoded as the viewer URL fragment (#page=2&toolbar=0). This is the cross-browser convention; individual PDF viewers may ignore parts of it.
  • The embed carries the stable rr-pdf root hook that themes may target.

Plain links ([[report.pdf]]) are left to @riebeckite/plugin-attachment (or the Markdown fallback), which renders the existing download link.

Options

Option Type Default Description
height string | number "640px" Viewer height. Numbers become pixels; strings are CSS lengths.
initialPage number 1 First page the native viewer opens.
toolbar boolean true false appends #toolbar=0 to hide the viewer toolbar.
showMetadata boolean true Show the format badge, file name, and size under the viewer.
downloadLabel string "Download PDF" Label for the download links.

Styles ship in style.css.

Exports

  • pdf(options?) / pdfPlugin — plugin factory
  • buildPdfViewerUrl(url, options) — viewer URL builder
  • isPdfRenderTarget(context) — PDF target predicate
  • renderPdf(context, options) — renderer implementation
  • Types: PdfOptions, ResolvedPdfOptions

See also

History

1 changesCollapseExpand
1 + <!-- Generated from packages/plugins/pdf/README.md. Do not edit this page directly; edit the package README and run `pnpm docs:sync`. -->
2 +
3 + # PDF
4 +
5 + Inline PDF attachment viewing for Obsidian wikilinks.
6 +
7 + [日本語](./pdf.md)
8 +
9 + ## Overview
10 +
11 + `pdf()` renders embedded PDF attachments (`![[report.pdf]]`) with the
12 + browser-native PDF viewer instead of a download-only card. The renderer is
13 + SSR/build-time only; no client JavaScript is required.
14 +
15 + `@riebeckite/plugin-obsidian-markdown` resolves a non-image, non-Markdown
16 + wikilink target to the generic `attachment` render kind, so PDFs are detected
17 + by their `.pdf` extension. A literal `kind: "pdf"` target is also accepted, so
18 + the plugin keeps working if a producer reports a PDF-specific kind later.
19 +
20 + The renderer runs before `@riebeckite/plugin-attachment` and
21 + `@riebeckite/plugin-media` (plugin `order: -20`), so a PDF embed is never
22 + captured by the generic attachment card. Register `attachment()` alongside to
23 + keep download links for non-PDF files.
24 +
25 + ## Usage
26 +
27 + ```ts
28 + import { defineConfig } from "@riebeckite/core";
29 + import { attachment } from "@riebeckite/plugin-attachment";
30 + import { obsidianMarkdown } from "@riebeckite/plugin-obsidian-markdown";
31 + import { pdf } from "@riebeckite/plugin-pdf";
32 +
33 + export default defineConfig({
34 + // ...
35 + plugins: [obsidianMarkdown(), attachment(), pdf()],
36 + });
37 + ```
38 +
39 + ## Rendering
40 +
41 + Embed (`![[report.pdf]]`):
42 +
43 + ```html
44 + <figure class="rr-pdf" data-pdf-path="..." style="--rr-pdf-height: 640px">
45 + <object
46 + class="rr-pdf__viewer"
47 + data="/assets/attachments/report.pdf#page=1"
48 + type="application/pdf"
49 + aria-label="report.pdf"
50 + >
51 + <a class="rr-pdf__fallback" href="..." download>Download PDF</a>
52 + </object>
53 + <figcaption class="rr-pdf__meta">
54 + <span class="rr-pdf__format">PDF</span>
55 + <span class="rr-pdf__name">report.pdf</span>
56 + <span class="rr-pdf__size">1.2 MB</span>
57 + <a class="rr-pdf__download" href="..." download>Download PDF</a>
58 + </figcaption>
59 + </figure>
60 + ```
61 +
62 + - The `<object>` uses the browser's built-in PDF viewer; its nested link is the
63 + graceful fallback for clients without PDF support.
64 + - A visible download link and the format badge, file name, and size are always
65 + available below the viewer. Size is read from `config.content.directory` and
66 + omitted when the file cannot be read.
67 + - `initialPage` and `toolbar` are encoded as the viewer URL fragment
68 + (`#page=2&toolbar=0`). This is the cross-browser convention; individual PDF
69 + viewers may ignore parts of it.
70 + - The embed carries the stable `rr-pdf` root hook that themes may target.
71 +
72 + Plain links (`[[report.pdf]]`) are left to `@riebeckite/plugin-attachment` (or
73 + the Markdown fallback), which renders the existing download link.
74 +
75 + ## Options
76 +
77 + | Option | Type | Default | Description |
78 + | --------------- | ------------------ | ---------------- | ----------------------------------------------------------------- |
79 + | `height` | `string \| number` | `"640px"` | Viewer height. Numbers become pixels; strings are CSS lengths. |
80 + | `initialPage` | `number` | `1` | First page the native viewer opens. |
81 + | `toolbar` | `boolean` | `true` | `false` appends `#toolbar=0` to hide the viewer toolbar. |
82 + | `showMetadata` | `boolean` | `true` | Show the format badge, file name, and size under the viewer. |
83 + | `downloadLabel` | `string` | `"Download PDF"` | Label for the download links. |
84 +
85 + Styles ship in `style.css`.
86 +
87 + ## Exports
88 +
89 + - `pdf(options?)` / `pdfPlugin` — plugin factory
90 + - `buildPdfViewerUrl(url, options)` — viewer URL builder
91 + - `isPdfRenderTarget(context)` — PDF target predicate
92 + - `renderPdf(context, options)` — renderer implementation
93 + - Types: `PdfOptions`, `ResolvedPdfOptions`
94 +
95 + ## See also
96 +
97 + - [Plugin guide](../reference/plugin-api.en.md)
98 + - [`@riebeckite/plugin-obsidian-markdown`](./obsidian-markdown.en.md)
99 + - [`@riebeckite/plugin-attachment`](./attachment.en.md)
100 +