Click or drag to resize

Security and Viewer Preferences

Before a document is displayed, the viewer can protect it and set how it opens. The settings are written into the displayed copy of the document (your file is not changed) and take effect for the next document you load, or after ReloadPdfDocument.

Security options

PdfSecurityOptions holds the passwords and the permissions of the displayed document. The viewer honours the printing and copying permissions: the print button and the print methods are disabled, and the text cannot be selected and copied.

Property

Description

UserPassword

A password needed to open the document. The viewer asks the user for it.

OwnerPassword

The password that protects the permissions. When you set permissions without it, a random owner password is used.

CanPrint

Allow or deny printing.

CanCopyContent

Allow or deny selecting and copying the text.

CanEditContent, CanEditAnnotations, CanFillFormFields, CanAssembleDocument

Written into the document for other PDF readers (this viewer does not edit documents).

KeySize

The encryption key size.

// a password to open the document, and no printing or copying
pdfViewer.PdfSecurityOptions.UserPassword = "secret";
pdfViewer.PdfSecurityOptions.CanPrint = false;
pdfViewer.PdfSecurityOptions.CanCopyContent = false;
pdfViewer.LoadFile(path);

The same properties are available directly on the control (CanPrint, UserPassword, ...), so they can be set in the Visual Studio designer.

A document that is already protected keeps its own protection. To change its security options or viewer preferences, set OpenPassword to its password.

Viewer preferences

PdfViewerPreferences sets how the document opens: PageLayout (single page, one column, two columns) and PageMode (the outline, the thumbnails or the attachments shown next to it). The other preferences (HideMenuBar, FitWindow, DisplayDocTitle, ...) are written into the document for other PDF readers.

C#
// open as a book: two pages side by side, the cover alone, with the outline
pdfViewer.PdfViewerPreferences.PageLayout = PdfViewerPageLayout.TwoColumnRight;
pdfViewer.PdfViewerPreferences.PageMode = PdfViewerPageMode.UseOutlines;
pdfViewer.ReloadPdfDocument();

A layout or panel set with PageLayoutMode or DocumentDisplayMode takes precedence over the viewer preferences; set them to NotSet to let the document preferences apply.

See Also