Skip to content

For developers: PDF.js and pdf‐lib

Ryota Ushio edited this page Feb 16, 2024 · 3 revisions

Obsidian uses a customized version of Mozilla PDF.js for their native PDF viewer. For this reason, you might end up just wasting your time if you search around the code in the original PDF.js repository to find out what's happening behind the scenes.

item.chars & page.getTextContent({ includeChars: true })

One of the most important differences between the Obsidian version and the original is the includeChars option for getTextContent and the chars property of text content items, which are unique to the Obsidian version.

By calling PDFDocumentProxy.getTextContent() with includeChars: true, you can get character-level bounding boxes as item.chars, where item is a text content item.

pageView.textLayer.textContentItems