Skip to content

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's PDFDocumentProxy object
  • getPage: get the reference to PDF.js's PDFPageProxy object
  • getPDFView: get Obsidian's native PDF view
  • getPDFViewerComponent: get PDFViewerComponent instance (see typings.d.ts)
  • getPDFViewerChild: get PDFViewerChild instance (see typings.d.ts)
  • getObsidianViewer: get ObsidianViewer instance (see typings.d.ts)
  • getPDFViewer: get PDFViewer instance (see typings.d.ts)
  • getToolbar: get PDFToolbar instance (see typings.d.ts)

Tips

Listen to PDF context menus

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;

Get PDF.js AnnotationElement instance from a page number & an annotation ID

// 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)

Resources