Local images ("Pasted image ...") not found during PDF export #13

Open
opened 2026-07-10 16:51:57 +02:00 by snrkl · 0 comments
snrkl commented 2026-07-10 16:51:57 +02:00 (Migrated from github.com)

Local images ("Pasted image ...") not found during PDF export

What we experienced

Embedded local images (e.g. Obsidian's default pasted-screenshot naming) failed to export, even though the file genuinely existed in the vault. This came in two stages as we dug in:

  1. First, exports silently dropped the image and inserted a placeholder like [⚠️ Image not found: <filename>] in the output.
  2. After a plugin patch (see below), the image was found, but the Typst compile step then failed with a "file not found" error, where the searched-for path looked like the vault path with a system temp directory oddly appended to it (something resembling <vault path>/<OS temp dir>/media-<hash>/<attachment folder>/<filename>).

What we think is happening

  • Stage 1: processImageEmbeds calls resolveLocalPath(...) with the "use Obsidian's metadataCache.getFirstLinkpathDest" flag hardcoded to false — unlike the PDF-embed and generic-file-embed code paths, which both pass true. This means image resolution only checks a literal attachments folder plus a couple of fixed relative paths, and never respects a vault's actual configured attachment folder or Obsidian's own link resolution.
  • Stage 2: once images resolve correctly, Pandoc appears to stage the referenced image through a system temp directory before invoking Typst. Since Typst treats any path starting with / as root-relative rather than OS-absolute (a deliberate sandboxing behavior), and no --root is ever passed to the Typst engine invocation, Typst ends up prepending its default root onto an already-absolute path — producing the doubled, malformed path in the error.

What we tried (worked, at least for our setup)

  • Flipped the hardcoded false to true in the resolveLocalPath call inside processImageEmbeds, so it uses the same link-resolution logic already used for PDF/file embeds.
  • Added --pdf-engine-opt=--root=/ to the Typst invocation in buildPandocArgs, so absolute-looking paths resolve as real filesystem paths instead of being treated as root-relative.

Both were quick local patches to the compiled main.js, not proper PRs — happy to share diffs if useful, but flagging this mainly so it's on the radar. We're not fully confident --root=/ is the right long-term fix (vs. controlling where Pandoc stages media, or avoiding staging altogether) — just what got us unblocked.

Possible solutions

  • Pass the same link-resolution flag (true) for image embeds as is already used for PDF/file embeds.
  • Either avoid Pandoc's temp media staging entirely for local images, or explicitly set Typst's --root to match wherever staging happens.
## Local images ("Pasted image ...") not found during PDF export **What we experienced** Embedded local images (e.g. Obsidian's default pasted-screenshot naming) failed to export, even though the file genuinely existed in the vault. This came in two stages as we dug in: 1. First, exports silently dropped the image and inserted a placeholder like `[⚠️ Image not found: <filename>]` in the output. 2. After a plugin patch (see below), the image was *found*, but the Typst compile step then failed with a "file not found" error, where the searched-for path looked like the vault path with a system temp directory oddly appended to it (something resembling `<vault path>/<OS temp dir>/media-<hash>/<attachment folder>/<filename>`). **What we think is happening** - Stage 1: `processImageEmbeds` calls `resolveLocalPath(...)` with the "use Obsidian's `metadataCache.getFirstLinkpathDest`" flag hardcoded to `false` — unlike the PDF-embed and generic-file-embed code paths, which both pass `true`. This means image resolution only checks a literal `attachments` folder plus a couple of fixed relative paths, and never respects a vault's actual configured attachment folder or Obsidian's own link resolution. - Stage 2: once images resolve correctly, Pandoc appears to stage the referenced image through a system temp directory before invoking Typst. Since Typst treats any path starting with `/` as root-relative rather than OS-absolute (a deliberate sandboxing behavior), and no `--root` is ever passed to the Typst engine invocation, Typst ends up prepending its default root onto an already-absolute path — producing the doubled, malformed path in the error. **What we tried (worked, at least for our setup)** - Flipped the hardcoded `false` to `true` in the `resolveLocalPath` call inside `processImageEmbeds`, so it uses the same link-resolution logic already used for PDF/file embeds. - Added `--pdf-engine-opt=--root=/` to the Typst invocation in `buildPandocArgs`, so absolute-looking paths resolve as real filesystem paths instead of being treated as root-relative. Both were quick local patches to the compiled `main.js`, not proper PRs — happy to share diffs if useful, but flagging this mainly so it's on the radar. We're not fully confident `--root=/` is the right long-term fix (vs. controlling where Pandoc stages media, or avoiding staging altogether) — just what got us unblocked. **Possible solutions** - Pass the same link-resolution flag (`true`) for image embeds as is already used for PDF/file embeds. - Either avoid Pandoc's temp media staging entirely for local images, or explicitly set Typst's `--root` to match wherever staging happens.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: AlexKucera/obsidian-typst-pdf-export#13