Wednesday, 30 January 2019 07:55

Set PDF Viewer Preference in Java

Written by  support iceblue
Rate this item
(0 votes)

PDF viewer preference allows users to view PDF with specified view mode or display layout. This article demonstrates how to set the viewer preference in a PDF file using Spire.PDF for Java.

import com.spire.pdf.*;

public class ViewerPreference {
    public static void main(String[] args) {

        //Load the PDF file
        PdfDocument pdf = new PdfDocument();
        pdf.loadFromFile("Additional.pdf");

        //Set viewer preference
        pdf.getViewerPreferences().setCenterWindow(true);
        pdf.getViewerPreferences().setDisplayTitle(false);
        pdf.getViewerPreferences().setFitWindow(true);
        pdf.getViewerPreferences().setHideMenubar(true);
        pdf.getViewerPreferences().setHideToolbar(true);
        pdf.getViewerPreferences().setPageLayout(PdfPageLayout.Single_Page);
        //pdf.getViewerPreferences().setPageMode(PdfPageMode.Full_Screen);
        //pdf.getViewerPreferences().setPrintScaling(PrintScalingMode.App_Default);

        //Save the file.
        pdf.saveToFile("ViewerPreference.pdf");
        //Close
        pdf.close();
    }
}

Output:

Set PDF Viewer Preference in Java

Additional Info

  • tutorial_title:
Last modified on Wednesday, 30 January 2019 07:57