Markpad icon indicating copy to clipboard operation
Markpad copied to clipboard

输出pdf时,markdown的标题没有转成PDF章节标签

Open hitbuyi opened this issue 2 weeks ago • 2 comments

What problem would this solve?

希望增加这一功能

What would you like?

No response

Has another app got this right?

No response

Which platform is this for?

All platforms

Your Markpad version and how you installed it

No response

hitbuyi avatar Nov 19 '26 01:11 hitbuyi

记下了,以后会考虑实现。目前 PDF 是通过打印导出的,这条路默认不会生成书签,要做需要额外处理,暂时没有排期。

(Noted, we'll consider it. PDF export currently goes through printing, which does not produce bookmarks by itself, so this needs extra work and is not scheduled yet.)

The technical side — you can skip this

How other editors do it. Every editor checked prints through Chromium:

  • MarkText calls Electron's printToPDF with generateTaggedPDF: true and generateDocumentOutline: true; the outline is built from the tagged h1–h6 structure, so both flags are needed.
  • Zettlr's main PDF route is Pandoc + XeLaTeX, where LaTeX makes the bookmarks. Its Chromium fallback has none.
  • Markdown Preview Enhanced (Puppeteer page.pdf) has none by default; users can pass Puppeteer's outline: true in its config.
  • The Markdown PDF extension for VS Code and Joplin produce no outline.
  • Obsidian has none built in as far as we know; the Better Export PDF plugin adds it by printing, then editing the PDF (see below).

None of them deal with WebKit, which is what Markpad uses on macOS and Linux.

Windows. Markpad exports through WebView2, which is Chromium. It can call the DevTools method Page.printToPDF with generateTaggedPDF and generateDocumentOutline, so the change stays inside the Windows export command. The options are marked experimental, but MarkText ships them.

macOS. Tested with a small WKWebView program: printing with no dialog straight to a file gives a paginated PDF, and placeholder links wrapped around each heading survive as link annotations with their page and y position. So: wrap headings in placeholder links, print silently to a file, read the annotations back with PDFKit, build the outline with PDFOutline, and turn the placeholders back into plain headings. All system frameworks, no new dependency. The print has to run modally; running it otherwise is reported to give blank pages.

Linux. WebKitGTK writes no link annotations into printed PDFs (WebKit bug 302265, open, no patch), so the placeholder trick does not work. The fallback is to print silently to a file, then find each heading's text page by page in document order; bookmarks would point to the page, not the exact position. Untested, and text extraction from CJK PDFs may be unreliable.

On macOS and Linux the PDF is currently saved by the user from the system print dialog, so Markpad never holds the file. Both routes above first need the export to write the file itself.

Not verified: how Typora does it (closed source); Obsidian's built-in export; the Linux text search.

PathGao avatar Nov 19 '26 07:11 PathGao

大概率只有win能做到,我们的技术走的tauri,不是自带chrome的electron,而这个功能的实现基于chrome内核

PathGao avatar Nov 19 '26 07:11 PathGao