Skip to content

About

A basic Java PDF Viewer using Swing

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

Repository files navigation

Java PDF Viewer 2.0

A lightweight desktop PDF viewer written in Java/Swing on top of Apache PDFBox, with a set of everyday reading conveniences.

Features

  • Nimbus look and feel by default, switchable at runtime from View → Look & Feel (Sun CDE/Motif, Metal, system, etc.), or chosen at launch via -Djpdf.laf=nimbus|motif|system|metal.
  • Single-page and continuous (scrolling) layouts — toggle from View → Continuous Scroll. Both layouts are virtualized: only the pages near the viewport are instantiated or rendered, so documents with thousands of pages stay light (a 2,500-page file jumps to any page in a ~190 MB heap).
  • Sidebar (toggle from View → Show Sidebar) with:
    • Pages — live page thumbnails; click to jump.
    • Bookmarks — the document outline as a clickable tree.
  • Annotation tools (Tools menu):
    • Highlight — drag across the page to add a translucent highlight.
    • Sticky Note — click to drop a note; double-click a note to edit it.
    • Clear Annotations on Page, and File → Save Annotated As… to write the highlights and notes into a new PDF (via PDFBox annotations).
  • Full page navigation — first / previous / next / last and Go to Page… (Home, PageUp, PageDown, End, Ctrl+G).
  • Zoom controls — zoom in/out, set an exact percentage, Actual Size, plus Fit Width and Fit Page that re-fit automatically on resize.
  • 90° rotation of the current view.
  • Toolbar and status bar showing the file name, current page and zoom level.
  • Mouse-wheel zoom with Ctrl held; normal wheel scrolls.
  • Drag-and-drop a PDF onto the window, or pass a file path as a command-line argument, to open it.
  • Printing via the system print dialog.
  • Responsive UI — documents are loaded and pages are rendered/thumbnailed on background threads (never on the Swing EDT), guarded by a single render lock (PDFBox's renderer is not thread-safe) with an LRU cache of recently rendered pages so revisiting a page is instant.

Requirements

  • To run the published JAR: Java 21+ (any JRE/JDK).
  • To build from source: JDK 21+. build.sh downloads the Apache PDFBox dependencies automatically; no other setup is required.

Download & run

Grab jPDFViewer-<version>.jar from the Releases page — it bundles PDFBox, so no classpath is needed:

java -jar jPDFViewer-2.0.jar [path/to/file.pdf]

# Launch with the classic Sun CDE/Motif look and feel instead of the Nimbus default
java -Djpdf.laf=motif -jar jPDFViewer-2.0.jar [path/to/file.pdf]

Build from source

# Fetches PDFBox into libs/ on first run and produces dist/jPDFViewer-2.0.jar
./build.sh
java -jar dist/jPDFViewer-2.0.jar [path/to/file.pdf]

The project is plain javac — no build tool required — split across small single-responsibility classes: jPDFViewer (window/controller), RenderService (off-EDT rendering + cache), PageView, VirtualPages and CenterPanel (the page canvases), plus Annotation, Tool and LookAndFeels.

Keyboard shortcuts

Action Shortcut
Open Ctrl/⌘ + O
Save Annotated Ctrl/⌘ + S
Print Ctrl/⌘ + P
Go to Page Ctrl/⌘ + G
Zoom In / Out Ctrl/⌘ + = / -
Actual Size Ctrl/⌘ + 0
Rotate Ctrl/⌘ + R
Previous / Next PageUp / PageDown
First / Last Home / End
Quit Ctrl/⌘ + Q

Notes

  • Annotations are placed in unrotated page coordinates, so the highlight/note tools are active only when the current view rotation is 0°.

About

A basic Java PDF Viewer using Swing

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages