-
-
Notifications
You must be signed in to change notification settings - Fork 15
For developers: How Obsidian loads PDF files
First, I will explain what happens when Obsidian opens a file in general, not limited to PDFs.
When Obsidian tries to open a file, first a WorkspaceLeaf
's openFile
method is called.
In turn, it triggers WorkspaceLeaf.prototype.setViewState
.
In setViewState
, Obsidian identifies which view type to use to open the file.
For example, PDFView
is selected for PDF files.
Note
PDFView
is not included in the public API. See typings.d.ts to see what it looks like.
Then, Obsidian instantiates a view object of the type and calls its open
method (undocumented), which in turn calls the load
method.
At this point, the file is not opened in that view. After that, the view's setState
method is triggered, in which loadFile
(undocumented) is executed in the case of FileView
s.
Next, I will describe the processes specific to PDF files.
class PDFView extends EditableFileView
Registers a vault.on("modify", ...)
event handler, which calls the onLoadFile
method of the associated PDFViewerComponent
.
Calls the loadFile
method of the associated PDFViewerComponent
.
class PDFViewerComponent extends Component
Creates a PDFViewerChild
object and calls its load
method.
Calls the loadFile
method of the child: PDFViewerChild
.
Wraps PDF.js viewer and bridges between PDF.js and Obsidian.