When browsing PDF files on a daily basis, the personal habit of "setting the full screen mode, hiding the menu bar / toolbar, how to set the page layout of the document, etc." You set your preferences according to. Today, the text will show you how to achieve these preference settings through Free Spire.PDF for Java.
** Import JAR package ** ** Method 1: ** Download Free Spire.PDF for Java, unzip it, and then in the lib folder Import the Spire.Pdf.jar package into your Java application as a dependency.
** Method 2: ** After installing the JAR package directly from the Maven repository, configure the pom.xml file as follows:
<repositories>
<repository>
<id>com.e-iceblue</id>
<name>e-iceblue</name>
<url>http://repo.e-iceblue.com/nexus/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.pdf.free</artifactId>
<version>2.6.3</version>
</dependency>
</dependencies>
** Java code **
import com.spire.pdf.*;
public class ViewerPreference {
public static void main(String[] args) {
//Load the PDF document
PdfDocument pdf = new PdfDocument();
pdf.loadFromFile("test2.pdf");
//Center the window
pdf.getViewerPreferences().setCenterWindow(true);
//Hide the title
pdf.getViewerPreferences().setDisplayTitle(false);
//Fit to window size
pdf.getViewerPreferences().setFitWindow(true);
//Hide the menu bar
pdf.getViewerPreferences().setHideMenubar(true);
//Hide toolbar
pdf.getViewerPreferences().setHideToolbar(true);
//Set the page to display in two columns
pdf.getViewerPreferences().setPageLayout(PdfPageLayout.Two_Column_Left);
//Full screen
//pdf.getViewerPreferences().setPageMode(PdfPageMode.Full_Screen);
//Set print zoom
//pdf.getViewerPreferences().setPrintScaling(PrintScalingMode.App_Default);
//Save the document
pdf.saveToFile("viewer.pdf");
//Close
pdf.close();
}
}
Recommended Posts