Skip to content

happypdf / ViewerPreferences

Class: ViewerPreferences ​

Defined in: src/core/interactive/ViewerPreferences.ts:97

Methods ​

getCenterWindow() ​

ts
getCenterWindow(): boolean;

Defined in: src/core/interactive/ViewerPreferences.ts:239

Returns true if PDF readers should position the document's window in the center of the screen.

Returns ​

boolean

Whether or not to center the document window.


getDisplayDocTitle() ​

ts
getDisplayDocTitle(): boolean;

Defined in: src/core/interactive/ViewerPreferences.ts:250

Returns true if the window's title bar should display the document Title, taken from the document metadata (see [[PDFDocument.getTitle]]). Returns false if the title bar should instead display the filename of the PDF file.

Returns ​

boolean

Whether to display the document title.


getDuplex() ​

ts
getDuplex(): Duplex | undefined;

Defined in: src/core/interactive/ViewerPreferences.ts:288

Returns the paper handling option that should be used when printing the file from the print dialog.

Returns ​

Duplex | undefined

The paper handling option.


getFitWindow() ​

ts
getFitWindow(): boolean;

Defined in: src/core/interactive/ViewerPreferences.ts:230

Returns true if PDF readers should resize the document's window to fit the size of the first displayed page.

Returns ​

boolean

Whether or not the window should be resized to fit.


getHideMenubar() ​

ts
getHideMenubar(): boolean;

Defined in: src/core/interactive/ViewerPreferences.ts:211

Returns true if PDF readers should hide the menu bar when displaying this document.

Returns ​

boolean

Whether or not the menu bar should be hidden.


getHideToolbar() ​

ts
getHideToolbar(): boolean;

Defined in: src/core/interactive/ViewerPreferences.ts:202

Returns true if PDF readers should hide the toolbar menus when displaying this document.

Returns ​

boolean

Whether or not toolbars should be hidden.


getHideWindowUI() ​

ts
getHideWindowUI(): boolean;

Defined in: src/core/interactive/ViewerPreferences.ts:221

Returns true if PDF readers should hide the user interface elements in the document's window (such as scroll bars and navigation controls), leaving only the document's contents displayed.

Returns ​

boolean

Whether or not user interface elements should be hidden.


getNonFullScreenPageMode() ​

ts
getNonFullScreenPageMode(): NonFullScreenPageMode;

Defined in: src/core/interactive/ViewerPreferences.ts:259

Returns the page mode, which tells the PDF reader how to display the document after exiting full-screen mode.

Returns ​

NonFullScreenPageMode

The page mode after exiting full-screen mode.


getNumCopies() ​

ts
getNumCopies(): number;

Defined in: src/core/interactive/ViewerPreferences.ts:343

Returns the number of copies to be printed when the print dialog is opened for this document.

Returns ​

number

The default number of copies to be printed.


getPickTrayByPDFSize() ​

ts
getPickTrayByPDFSize(): boolean | undefined;

Defined in: src/core/interactive/ViewerPreferences.ts:299

Returns true if the PDF page size should be used to select the input paper tray.

Returns ​

boolean | undefined

Whether or not the PDF page size should be used to select the input paper tray.


getPrintPageRange() ​

ts
getPrintPageRange(): PageRange[];

Defined in: src/core/interactive/ViewerPreferences.ts:320

Returns an array of page number ranges, which are the values used to initialize the print dialog box when the file is printed. Each range specifies the first (start) and last (end) pages in a sub-range of pages to be printed. The first page of the PDF file is denoted by 0. For example:

js
const viewerPrefs = pdfDoc.catalog.getOrCreateViewerPreferences()
const includesPage3 = viewerPrefs
  .getPrintRanges()
  .some(pr => pr.start =< 2 && pr.end >= 2)
if (includesPage3) console.log('printRange includes page 3')

Returns ​

PageRange[]

An array of objects, each with the properties start and end, denoting page indices. If not, specified an empty array is returned.


getPrintScaling() ​

ts
getPrintScaling(): PrintScaling;

Defined in: src/core/interactive/ViewerPreferences.ts:278

Returns the page scaling option that the PDF reader should select when the print dialog is displayed.

Returns ​

PrintScaling

The page scaling option.


getReadingDirection() ​

ts
getReadingDirection(): ReadingDirection;

Defined in: src/core/interactive/ViewerPreferences.ts:268

Returns the predominant reading order for text.

Returns ​

ReadingDirection

The text reading order.


lookupBool() ​

ts
protected lookupBool(key): PDFBool | undefined;

Defined in: src/core/interactive/ViewerPreferences.ts:116

Parameters ​

ParameterType
keyBoolViewerPrefKey

Returns ​

PDFBool | undefined


lookupName() ​

ts
protected lookupName(key): PDFName | undefined;

Defined in: src/core/interactive/ViewerPreferences.ts:122

Parameters ​

ParameterType
keyNameViewerPrefKey

Returns ​

PDFName | undefined


setCenterWindow() ​

ts
setCenterWindow(centerWindow): void;

Defined in: src/core/interactive/ViewerPreferences.ts:393

Choose whether the PDF reader should position the document's window in the center of the screen.

Parameters ​

ParameterTypeDescription
centerWindowbooleantrue if the window should be centered.

Returns ​

void


setDisplayDocTitle() ​

ts
setDisplayDocTitle(displayTitle): void;

Defined in: src/core/interactive/ViewerPreferences.ts:404

Choose whether the window's title bar should display the document Title taken from the document metadata (see [[PDFDocument.setTitle]]). If false, the title bar should instead display the PDF filename.

Parameters ​

ParameterTypeDescription
displayTitlebooleantrue if the document title should be displayed.

Returns ​

void


setDuplex() ​

ts
setDuplex(duplex): void;

Defined in: src/core/interactive/ViewerPreferences.ts:501

Choose the paper handling option that should be selected by default in the print dialog.

For example:

js
import { PDFDocument, Duplex } from 'pdf-lib'

const pdfDoc = await PDFDocument.create()
const viewerPrefs = pdfDoc.catalog.getOrCreateViewerPreferences()
viewerPrefs.setDuplex(Duplex.DuplexFlipShortEdge)

Parameters ​

ParameterTypeDescription
duplexDuplexThe double or single sided printing option.

Returns ​

void


setFitWindow() ​

ts
setFitWindow(fitWindow): void;

Defined in: src/core/interactive/ViewerPreferences.ts:383

Choose whether the PDF reader should resize the document's window to fit the size of the first displayed page.

Parameters ​

ParameterTypeDescription
fitWindowbooleantrue if the window should be resized.

Returns ​

void


setHideMenubar() ​

ts
setHideMenubar(hideMenubar): void;

Defined in: src/core/interactive/ViewerPreferences.ts:362

Choose whether the PDF reader's menu bar should be hidden while the document is active.

Parameters ​

ParameterTypeDescription
hideMenubarbooleantrue if the menu bar should be hidden.

Returns ​

void


setHideToolbar() ​

ts
setHideToolbar(hideToolbar): void;

Defined in: src/core/interactive/ViewerPreferences.ts:352

Choose whether the PDF reader's toolbars should be hidden while the document is active.

Parameters ​

ParameterTypeDescription
hideToolbarbooleantrue if the toolbar should be hidden.

Returns ​

void


setHideWindowUI() ​

ts
setHideWindowUI(hideWindowUI): void;

Defined in: src/core/interactive/ViewerPreferences.ts:373

Choose whether the PDF reader should hide user interface elements in the document's window (such as scroll bars and navigation controls), leaving only the document's contents displayed.

Parameters ​

ParameterTypeDescription
hideWindowUIbooleantrue if the user interface elements should be hidden.

Returns ​

void


setNonFullScreenPageMode() ​

ts
setNonFullScreenPageMode(nonFullScreenPageMode): void;

Defined in: src/core/interactive/ViewerPreferences.ts:431

Choose how the PDF reader should display the document upon exiting full-screen mode. This entry is meaningful only if the value of the PageMode entry in the document's [[PDFCatalog]] is FullScreen.

For example:

js
import { PDFDocument, NonFullScreenPageMode, PDFName } from 'pdf-lib'

const pdfDoc = await PDFDocument.create()

// Set the PageMode
pdfDoc.catalog.set(PDFName.of('PageMode'),PDFName.of('FullScreen'))

// Set what happens when full-screen is closed
const viewerPrefs = pdfDoc.catalog.getOrCreateViewerPreferences()
viewerPrefs.setNonFullScreenPageMode(NonFullScreenPageMode.UseOutlines)

Parameters ​

ParameterTypeDescription
nonFullScreenPageModeNonFullScreenPageModeHow the document should be displayed upon exiting full screen mode.

Returns ​

void


setNumCopies() ​

ts
setNumCopies(numCopies): void;

Defined in: src/core/interactive/ViewerPreferences.ts:571

Choose the default number of copies to be printed when the print dialog is opened for this file.

Parameters ​

ParameterTypeDescription
numCopiesnumberThe default number of copies.

Returns ​

void


setPickTrayByPDFSize() ​

ts
setPickTrayByPDFSize(pickTrayByPDFSize): void;

Defined in: src/core/interactive/ViewerPreferences.ts:520

Choose whether the PDF document's page size should be used to select the input paper tray when printing. This setting influences only the preset values used to populate the print dialog presented by a PDF reader.

If PickTrayByPDFSize is true, the check box in the print dialog associated with input paper tray should be checked. This setting has no effect on operating systems that do not provide the ability to pick the input tray by size.

Parameters ​

ParameterTypeDescription
pickTrayByPDFSizebooleantrue if the document's page size should be used to select the input paper tray.

Returns ​

void


setPrintPageRange() ​

ts
setPrintPageRange(printPageRange): void;

Defined in: src/core/interactive/ViewerPreferences.ts:551

Choose the page numbers used to initialize the print dialog box when the file is printed. The first page of the PDF file is denoted by 0.

For example:

js
import { PDFDocument } from 'pdf-lib'

const pdfDoc = await PDFDocument.create()
const viewerPrefs = pdfDoc.catalog.getOrCreateViewerPreferences()

// We can set the default print range to only the first page
viewerPrefs.setPrintPageRange({ start: 0, end: 0 })

// Or we can supply noncontiguous ranges (e.g. pages 1, 3, and 5-7)
viewerPrefs.setPrintPageRange([
  { start: 0, end: 0 },
  { start: 2, end: 2 },
  { start: 4, end: 6 },
])

Parameters ​

ParameterTypeDescription
printPageRangePageRange | PageRange[]An object or array of objects, each with the properties start and end, denoting a range of page indices.

Returns ​

void


setPrintScaling() ​

ts
setPrintScaling(printScaling): void;

Defined in: src/core/interactive/ViewerPreferences.ts:480

Choose the page scaling option that should be selected when a print dialog is displayed for this document.

For example:

js
import { PDFDocument, PrintScaling } from 'pdf-lib'

const pdfDoc = await PDFDocument.create()
const viewerPrefs = pdfDoc.catalog.getOrCreateViewerPreferences()
viewerPrefs.setPrintScaling(PrintScaling.None)

Parameters ​

ParameterTypeDescription
printScalingPrintScalingThe print scaling option.

Returns ​

void


setReadingDirection() ​

ts
setReadingDirection(readingDirection): void;

Defined in: src/core/interactive/ViewerPreferences.ts:459

Choose the predominant reading order for text.

This entry has no direct effect on the document's contents or page numbering, but may be used to determine the relative positioning of pages when displayed side by side or printed n-up.

For example:

js
import { PDFDocument, ReadingDirection } from 'pdf-lib'

const pdfDoc = await PDFDocument.create()
const viewerPrefs = pdfDoc.catalog.getOrCreateViewerPreferences()
viewerPrefs.setReadingDirection(ReadingDirection.R2L)

Parameters ​

ParameterTypeDescription
readingDirectionReadingDirectionThe reading order for text.

Returns ​

void

MIT Licensed. A fork of pdf-lib.