generated from RyotaUshio/obsidian-sample-plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 22
For developers
Ryota Ushio edited this page Feb 22, 2024
·
11 revisions
PDF++ exposes the plugin (PDFPlus
) instance as the pdfPlus
global variable.
You can access various functions from pdfPlus.lib
. Its methods include:
-
getPDFDocument
: get the reference to PDF.js'sPDFDocumentProxy
object -
getPage
: get the reference to PDF.js'sPDFPageProxy
object -
getPDFView
: get Obsidian's native PDF view -
getPDFViewerComponent
: getPDFViewerComponent
instance (see typings.d.ts) -
getPDFViewerChild
: getPDFViewerChild
instance (see typings.d.ts) -
getObsidianViewer
: getObsidianViewer
instance (see typings.d.ts) -
getPDFViewer
: getPDFViewer
instance (see typings.d.ts) -
getToolbar
: getPDFToolbar
instance (see typings.d.ts)
You can listen to the pdf-menu
workspace event to add your own custom menu item to the PDF++'s custom context menu that pops up when you right-click in a PDF viewer.
on(name: "pdf-menu", callback: (menu: Menu, data: { pageNumber: number, selection: text, annot?: AnnotationElement }) => any): EventRef;
// in the dev console
const pageNumber = 2 // 1-based
const annotationId = '1251R' // the string you get when copying a link to the annotation
const annot = pdfPlus.lib.getPDFViewerChild().getPage(pageNumber).annotationLayer.annotationLayer.getAnnotation(annotationId);
console.log(annot)
console.log(annot.data)
- The PDF specification (PDF 1.7, PDF 2.0).
- pdfAnnotate's README is a great resource for how PDFs work. Especially, it mentions an error in the PDF specification, which was very helpful.
- Mozilla PDF.js's recommendations: https://github.com/mozilla/pdf.js?tab=readme-ov-file#learning