Java Sets PDF Document Browsing Preferences


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. 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

Comparison of setting effect before and after:


(End of this article)


Recommended Today

Server Core Knowledge

Catalog 1. Computer: a tool to assist human brain 2. Composition of computer hardware 3. power supply 4.CPU 5. memory 6. Classification of computer use 7. Introduction to common Internet servers 8. Server classification 1. Computer: a tool to assist human brain Nowadays people touch computers almost all the time! Whether it’s a desktop computer, […]