[Java] PDF viewing settings

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();
    }
}

view.png

Recommended Posts

[Java] PDF viewing settings
Java compressed PDF document
Java adds table to PDF
Save Java PDF in Excel
Java encryption and decryption PDF
Paging PDF with Java + PDFBox.jar
Java turns Excel into PDF
Save Java HTML as PDF
Java settings word Page background color
Java to extract PDF text content
[OpenCV3.2.0] Eclipse (Java) settings (for Mac)
Add, modify, delete JAVA PDF bookmarks
Java environment variable settings (Windows, AdoptOpenJDK11)
Java
Output PDF and TIFF with Java 8
Add, replace, delete Java PDF images
Add watermark to Java to PDF document
Settings for SSL debugging in Java
Java
Java draws shapes in PDF documents
Java adds form fields to PDF
Java Excel settings background color and background image
Program PDF headers and footers in Java