An Obsidian plugin that displays PDF outlines (table of contents) in a sidebar view, allowing users to navigate through PDF documents efficiently.
- Automatic PDF Outline Detection: Automatically detects when a PDF file is opened and parses its outline structure
- Sidebar View: Displays the outline in a dedicated sidebar tab that matches Obsidian's native outline appearance
- Collapsible Tree Structure: Hierarchical outline with expand/collapse functionality for nested sections
- Page Navigation: Click on any outline item to jump to the corresponding page in the PDF viewer
-
Search Functionality: Real-time filtering of outline items by title
- Case-insensitive search
- Recursive filtering (shows parent items if children match)
- Instant results as you type
-
Expand/Collapse All: Toggle button to expand or collapse all outline sections at once
- Button text dynamically changes based on current state
- Works with filtered search results
The plugin is built using TypeScript and follows Obsidian's plugin development best practices:
src/
main.ts # Plugin lifecycle, view registration, event listeners
view.ts # PDFOutlineView class implementing ItemView
pdf-parser.ts # PDF outline parsing using PDF.js
types.ts # TypeScript interfaces for outline structure
settings.ts # Plugin settings configuration
- PDF.js Integration: Uses Obsidian's built-in
loadPdfJs()function to ensure compatibility and proper worker configuration - Outline Extraction: Recursively parses PDF outline structure using PDF.js
getOutline()API - Destination Resolution: Resolves PDF destinations to page numbers for navigation
- Error Handling: Comprehensive error handling with fallbacks
Key Functions:
parsePDFOutline(): Main function that loads PDF and extracts outlineconvertOutlineItemAsync(): Recursively converts PDF.js outline items to our structureresolveDestination(): Resolves PDF destinations to page numbers
- ItemView Extension: Extends Obsidian's
ItemViewclass for sidebar integration - Tree Structure: Uses Obsidian's native
tree-itemCSS classes for consistent UI - State Management: Tracks expand/collapse state of all outline items
- Search Filtering: Real-time filtering with recursive matching
Key Features:
displayOutline(): Updates view with new outline datarenderOutlineItems(): Recursively renders outline as collapsible treefilterOutline(): Filters outline items based on search querytoggleItem(): Handles individual item expand/collapsetoggleAll(): Expands or collapses all itemsjumpToPage(): Navigates to PDF page when outline item is clicked
- View Registration: Registers the PDF Outline view with Obsidian
- Event Listeners: Listens for file-open events to detect PDF files
- Automatic Updates: Updates outline when PDF files are opened or switched
Key Functionality:
- Registers view in right sidebar on plugin load
- Monitors file-open events for PDF files
- Automatically parses and displays outline when PDF is opened
- Native Obsidian Styling: Uses Obsidian's built-in CSS classes (
tree-item,tree-item-self, etc.) for seamless integration - Collapsible Icons: SVG icons matching Obsidian's native outline appearance
- Responsive Layout: Header with search and controls, scrollable content area
-
Search Input:
- Positioned at top of view
- Search icon for visual clarity
- Real-time filtering as user types
-
Toggle All Button:
- Located next to search input
- Text changes based on state ("Alles einklappen" / "Alles ausklappen")
- Uses Obsidian's
mod-ctaclass for consistent button styling
-
Outline Tree:
- Hierarchical structure with proper indentation
- Collapse icons for items with children
- Page numbers displayed as tags
- Clickable items for navigation
The plugin implements multiple navigation methods to ensure compatibility:
-
Primary Methods:
goToPage(): Most common PDF viewer methodjumpToPage(): Alternative navigation methodnavigateToPage(): Additional fallback
-
Internal API Access:
- Direct access to PDF.js viewer instance
- Page number manipulation via
currentPageNumber
-
DOM Manipulation:
- Fallback to DOM-based navigation if APIs unavailable
- Input field manipulation for page navigation
- Graceful Degradation: Falls back to page-based navigation if destination-based navigation fails
- Console Logging: Debug information for troubleshooting
- Empty States: User-friendly messages when no outline is available or search returns no results
- Clone the repository:
git clone https://github.com/Niclassslua/obsidian-pdf-outline.git
cd obsidian-pdf-outline- Install dependencies:
npm install- Build the plugin:
npm run build- For development with watch mode:
npm run dev- Copy
main.js,manifest.json, andstyles.cssto your vault's.obsidian/plugins/obsidian-pdf-outline/folder - Reload Obsidian
- Enable the plugin in Settings → Community plugins
- Open a PDF file in Obsidian
- The PDF Outline tab will automatically appear in the right sidebar
- Click any outline item to navigate to that section in the PDF
- Use the search box to filter outline items
- Click "Alles einklappen/ausklappen" to collapse or expand all sections
- obsidian: Latest Obsidian API
- pdfjs-dist: ^3.11.174 (loaded via Obsidian's
loadPdfJs())
- Uses Obsidian's built-in PDF.js loading mechanism
- No external CDN dependencies
- Worker configuration handled automatically by Obsidian
- Strict type checking enabled
- ES2018 target for compatibility
- Module resolution: Node
obsidian-pdf-outline/
├── src/
│ ├── main.ts # Plugin entry point
│ ├── view.ts # Sidebar view implementation
│ ├── pdf-parser.ts # PDF parsing logic
│ ├── types.ts # TypeScript definitions
│ └── settings.ts # Settings tab
├── styles.css # Custom styles
├── manifest.json # Plugin manifest
├── package.json # Dependencies
└── tsconfig.json # TypeScript config
# Development build with watch mode
npm run dev
# Production build
npm run build
# Type checking
npm run lintContributions are welcome! Please ensure:
- Code follows TypeScript best practices
- New features include proper error handling
- UI matches Obsidian's native design patterns
- All changes are tested before submitting
See LICENSE file for details.
- Built using the Obsidian Sample Plugin as a template
- Uses PDF.js for PDF parsing (loaded via Obsidian's API)
- Follows Obsidian's plugin development guidelines