Java Sets PDF Document Browsing Preferences

Time:2019-9-11

When viewing PDF documents, some browsing preferences can be set, such as whether to browse in full screen, hide or display menu bar/toolbar, set page layout mode, etc. The following will show how to set up through Java programming.

Use tools:

  • Free Spire. PDF for Java (free version)
  • IntelliJ IDEA

 

JarFile acquisition and import:

Method 1:Official websiteDownload JarFile package. After downloading, decompress and import Spire. Pdf. jar file under lib folder into Java program. Refer to the following import effect:

Method2It can be imported through maven warehouse.

 

JavaCode example

import com.spire.pdf.*;

public class ViewerPreference {
    public static void main(String[]args){
        // Loading test documents
        PdfDocument pdf = new PdfDocument();
        pdf.loadFromFile("test.pdf");

        Pdf. getViewerPreferences (). setHideMenubar (true); //Hide menu bar
        Pdf. getViewerPreferences (). setHideToolbar (true); // Hidden Toolbar
        Pdf. getViewerPreferences (). setPageLayout (PdfPageLayout. Two_Column_Left); //Set two columns of the page to display
        Pdf. getViewerPreferences (). setPageMode (PdfPageMode. Use_Outlines); // Set Page Mode
        Pdf. getViewerPreferences (). setCenterWindow (true); // Set Form to Center
        Pdf. getViewerPreferences (). setDisplayTitle (false); // Display title
        // pdf. getViewerPreferences (). setPrintScaling (PrintScaling Mode. App_Default); //Set Print Scaling
        Pdf. getViewerPreferences (). setFitWindow (false); // Set the adaptive form
        Pdf. getViewerPreferences (). setHide Windows UI (true); // Hide Form Interface

        // Save Documents
        pdf.saveToFile("result.pdf",FileFormat.PDF);
        pdf.dispose();
    }
}

Comparison of setting effect before and after:

 

(End of this article)