pdfcpu

Logo

A PDF processor written in Go.

View the Project on GitHub pdfcpu/pdfcpu


Changelog

Set Viewer Preferences

This command configures how a PDF is displayed on the screen and shall be printed.

Define whether you want to display a toolbar, a menubar or if you want your document to be centered among others.

Define a default print page range, your paper handling options and other parameters for printing.

Have a look at some examples.

Usage

pdfcpu viewerpref set inFile ( inFileJSON | JSONstring ) [flags]

Common Flags


Arguments

namedescriptionrequired
inFilePDF input fileyes
inFileJSONJSON input file oryes
JSONstringJSON string containing viewing preferencesyes

Preference Parameters

namedescriptiondefault
HideToolbarHide tool bars when the document is activefalse
HideMenubarHide the menu bar when the document is activefalse
HideWindowUIHide user interface elements in the document’s windowfalse
FitWindowResize the document’s window to fit the size of the first displayed pagefalse
CenterWindowPosition the document’s window in the centre of the screenfalse
DisplayDocTitleDisplay the document titlefalse
NonFullScreenPageModeHow to display the document on exiting full-screen modeUseNone
DirectionThe predominant logical content order for textL2R
ViewAreaViewing Page boundary for screenCropBox
ViewClipClipping page boundary for screenCropBox
PrintAreaRendering Page boundary for printingCropBox
PrintClipClipping page boundary for printingCropBox
DuplexPaper handling option-
PickTrayByPDFSizeWhether the PDF page size shall be used to select the input paper tray-
PrintPageRangeThe page numbers used to initialize the print dialogue box when the file is printed (since PDF 1.7). The array shall contain an even number of integers to be interpreted in pairs, with each pair specifying the first and last pages in a sub-range of pages to be printed. The first page of the PDF file shall be denoted by 1.-
NumCopiesThe number of copies that shall be printed when the print dialog is opened for this file (since PDF 1.7).-
EnforceArray of names of Viewer preference settings that shall be enforced by PDF processors and that shall not be overridden by subsequent selections in the application user interface (since PDF 2.0) - possible value: PrintScaling-

DisplayDocTitle

valuedescription
trueThe window’s title bar should display the document title taken from the dc:title element of the XMP metadata stream
falseThe title bar should display the name of the PDF file containing the document

NonFullScreenPageMode

valuedescription
UseNoneNeither document outline nor thumbnail images visible (=default)
UseOutlinesDocument outline visible
UseThumbsThumbnail images visible
UseOCOptional content group panel visible

Direction

valuedescription
L2RLeft to right
R2LRight to left (including vertical writing systems, such as Chinese, Japanese, and Korean)

View/Print Area/Clip

Since PDF 1.4, deprecated as of PDF 2.0

Values: The PDF page boundaries (boxes)

parameterdescription
ViewAreaThe name of the page boundary representing the area of a page that shall be displayed when viewing the document on the screen.
ViewClipThe name of the page boundary to which the contents of a page shall be clipped when viewing the document on the screen.
PrintAreaThe name of the page boundary representing the area of a page that shall be rendered when printing the document.
PrintClipThe name of the page boundary to which the contents of a page shall be clipped when printing the document.

Duplex

The paper handling option that shall be used when printing the file from the print dialogue (since PDF 1.7)

valuedescription
SimplexPrint single-sided
DuplexFlipShortEdgeDuplex and flip on the short edge of the sheet
DuplexFlipLongEdgeDuplex and flip on the long edge of the sheet

Examples

Generally the viewer preferences are set via JSON.

Eg. Set viewer preferences via JSON string (case agnostic):

$ pdfcpu viewerpref set test.pdf "{\"HideMenuBar\": true, \"CenterWindow\": true}"

Set printer preferences (which are part of the viewer preferences) via JSON string (case agnostic):

$ pdfcpu viewerpref set test.pdf "{\"duplex\": \"duplexFlipShortEdge\", \"printPageRange\": [1, 4, 10, 12], \"NumCopies\": 3}"

Set viewer preferences via JSON file:

$ cat viewerpref.json
{
    "viewerPreferences": {
        "HideToolBar": true,
        "HideMenuBar": false,
        "HideWindowUI": false,
        "FitWindow": true,
        "CenterWindow": true,
        "DisplayDocTitle": true,
        "NonFullScreenPageMode": "UseThumbs",
        "Direction": "R2L",
        "Duplex": "Simplex",
        "PickTrayByPDFSize": false,
        "PrintPageRange": [
            1, 4,
            10, 20
        ],
        "NumCopies": 3,
        "Enforce": [
            "PrintScaling"
        ]
    }
}

$ pdfcpu viewerpref set test.pdf viewerpref.json