The Web Forms Control |
The PdfViewer server control renders the viewer in the page (as an iframe). Set its properties in the markup or in the code behind; they apply when the page is rendered, and after every postback.
PdfSourceURL displays a document from an address: an application relative path (~/files/report.pdf) or an absolute URL. A document on another web site is downloaded by the server and served to the viewer, because browsers do not let a page read documents from other sites.
PdfSourceBytes displays a document you have in memory - created or converted in your code, or read from a database. The document is kept in the session state, so it is displayed again after a postback.
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { // a report converted from HTML, displayed without saving it PdfConverter converter = new PdfConverter(); pdfViewer.PdfSourceBytes = converter.GetPdfBytesFromUrl("https://www.example.com/report"); } }
The static GetPageCount(Stream) method gives the number of pages of a document.
Property | Description |
|---|---|
The page the document opens at (the first page is 1). | |
Fit (the whole page), FitH (the page width) or FitV (the page height). | |
An exact zoom (100 = 100%). It takes precedence over the fit mode. | |
SinglePage, OneColumn (the default), TwoColumnLeft or TwoColumnRight (two pages side by side, the first page alone like a book cover). | |
The panel next to the document: Thumbs, Bookmarks, Attachments or None. NotSet lets the document decide. |
Property | Description |
|---|---|
Show or hide the toolbar. | |
Show or hide the button that opens the navigation panel. | |
Show or hide the scrollbars. | |
Show or hide the print and the download buttons. To prevent printing, also deny it in the security options (the users can otherwise print with the browser). | |
The colors of the viewer: Light, Dark, or System (as set in the browser of the user, the default). The pages keep their own colors. | |
The open file command (tools menu, Ctrl+O): the user opens a PDF file of the computer in the viewer; it is not sent to the server. The default value is false. | |
The button that opens and closes the navigation panel. The default value is true. | |
The find bar (Ctrl+F). The default value is true. | |
Previous and next page, the page number box, first and last page. The default value is true. | |
Zoom out, zoom in and the zoom list. The default value is true. | |
Presentation mode (full screen). The default value is true. | |
Document properties. The default value is true. | |
Width, Height | The size of the viewer, like for any web control. |
<epdf:PdfViewer ID="pdfViewer" runat="server" PdfSourceURL="~/files/report.pdf" CurrentPage="3" ZoomPercentage="125" PageLayoutMode="TwoColumnLeft" DocumentDisplayMode="Thumbs" AllowDownload="false" Width="100%" Height="800px" /> <epdf:PdfViewer ID="darkViewer" runat="server" PdfSourceURL="~/files/report.pdf" ViewerTheme="Dark" ShowFindButton="false" ShowPresentationModeButton="false" Height="800px" />
A hidden button only changes the toolbar: its keyboard shortcut does nothing, and the client API (find, print, navigation) works either way.
The control serves the viewer files and the documents given as bytes itself, under the ~/expertpdf-viewer.ashx/ address of the application. No handler or module needs to be registered in web.config. The IIS application pool must use the Integrated pipeline mode (the default of IIS and IIS Express). When the application restricts access with authorization rules, the users who see the viewer must be allowed to request that address.