Usaidbox PDF Viewer
is a lightweight library to add an embedded PDF preview in your app (Swing GUI). Using Apache PDFBox for rendering, it makes displaying and interacting with PDFs easy in Java.
- Embedded PDF viewer for Java (Swing GUI) apps
- PDF rendering powered by Apache PDFBox
- Page navigation
- Scaling options
- Print and Save options
- Java 8 or newer
Add this dependency to your build.gradle
file:
repositories {
maven { url 'https://repo.repsy.io/mvn/hangga/repo' }
}
dependencies {
implementation 'com.box.usaid:usaidbox:1.0.1'
}
<repository>
<id>repsy</id>
<url>https://repo.repsy.io/mvn/hangga/repo</url>
</repository>
<dependency>
<groupId>com.box.usaid</groupId>
<artifactId>usaidbox</artifactId>
<version>1.0.1</version>
</dependency>
To get started, create a new UsaidBox
object and call its methods as needed:
UsaidBox usaidBox = new UsaidBox("PDF Viewer");
Use the loadPdf()
method to load your PDF. You can load a PDF either with a String
path or a File
object.
usaidBox.loadPdf("path/to/your/pdf-file.pdf");
// Or use a File object
File pdfFile = ...
usaidBox.loadPdf(pdfFile);
Once your PDF is loaded, use setVisible(true)
to show the UsaidBox
dialog.
usaidBox.setVisible(true);
-
Custom Size: Set the dialog size as you like.
usaidBox.setCustomSize(1024, 768);
-
Maximize: Show the dialog in full-screen mode.
usaidBox.setMaximized();
-
Set Output File Name: Specify the file name for PDF downloads.
usaidBox.setOutputFileName("custom-output-name.pdf");
UsaidBox
also comes with a few controls:
-
Scaling: Use the combo box at the top to adjust view scale:
ACTUAL_SIZE
: Actual size.SHRINK_TO_FIT
: Shrinks to fit the screen.STRETCH_TO_FIT
: Stretches to fit.SCALE_TO_FIT
: Scales to fit the screen.
-
Page Navigation:
Next
andPrevious
buttons for page flipping. -
Print: Print the PDF file.
-
Save As: Download the PDF with your chosen file name.
-
Close: Close the dialog.
UsaidBox usaidBox = new UsaidBox("PDF Viewer")
.loadPdf("path/to/your/pdf-file.pdf")
.setCustomSize(1024, 768)
.setOutputFileName("OutputFile.pdf")
.setVisible(true);
This library is a proprietary, closed-source library with restrictions on redistribution and modification.
It is free to use, but if you find it valuable, you are welcome to make a donation or become a sponsor. For more information, please contact me.