Class PdfViewerControl
PdfViewerControl helps to view and print PDF files. The DocumentToolbar helps to navigate easily anywhere inside the document and also provides direct access to open, save and print documents.
Inherited Members
Namespace: Syncfusion.Windows.Forms.PdfViewer
Assembly: Syncfusion.PdfViewer.Windows.dll
Syntax
public class PdfViewerControl : BaseControl, IThemeProvider, IVisualStyle, IDisposable
Constructors
PdfViewerControl()
Initializes PdfViewerControl.
Declaration
public PdfViewerControl()
Fields
PageClicked
Occurs when a page is clicked in PdfViewerControl
Declaration
public EventHandler<PageClickedEventArgs> PageClicked
Field Value
Type |
---|
System.EventHandler<PageClickedEventArgs> |
PageMouseMove
Occurs when the mouse pointer moves over the page in PdfViewerControl
Declaration
public EventHandler<PageMouseMoveEventArgs> PageMouseMove
Field Value
Type |
---|
System.EventHandler<PageMouseMoveEventArgs> |
Properties
CurrentPageIndex
Returns the index of the current page displayed in the Viewer
Declaration
public int CurrentPageIndex { get; }
Property Value
Type |
---|
System.Int32 |
CursorMode
Gets and sets the Cursor Mode
Declaration
public PdfViewerCursorMode CursorMode { get; set; }
Property Value
Type |
---|
PdfViewerCursorMode |
DocumentInformation
Gets the information of the PDF document loaded
Declaration
public DocumentInformation DocumentInformation { get; }
Property Value
Type |
---|
DocumentInformation |
EnableContextMenu
Enables or disables the context menu.
Declaration
public bool EnableContextMenu { get; set; }
Property Value
Type |
---|
System.Boolean |
EnableNotificationBar
Enables the display of Notification bar on setting true.
Declaration
public bool EnableNotificationBar { get; set; }
Property Value
Type |
---|
System.Boolean |
HorizontalScrollOffset
Gets or sets the horizontal scroll offset of the control.
Declaration
public int HorizontalScrollOffset { get; set; }
Property Value
Type |
---|
System.Int32 |
IsBookmarkEnabled
Enables or disables the bookmark feature.
Declaration
public bool IsBookmarkEnabled { get; set; }
Property Value
Type |
---|
System.Boolean |
IsDocumentLoaded
Returns true, if the PDF document is loaded in PDF viewer control. Default value is false.
Declaration
public bool IsDocumentLoaded { get; }
Property Value
Type |
---|
System.Boolean |
IsTextSearchEnabled
Gets or sets a value indicating whether text search is enabled. Default value is true.
Declaration
public bool IsTextSearchEnabled { get; set; }
Property Value
Type |
---|
System.Boolean |
IsTextSelectionEnabled
Gets or sets a value indicating whether text selection is enabled. Default value is true.
Declaration
public bool IsTextSelectionEnabled { get; set; }
Property Value
Type |
---|
System.Boolean |
LoadedDocument
Gets the LoadedDocument of PdfViewerControl
Declaration
public PdfLoadedDocument LoadedDocument { get; }
Property Value
Type |
---|
PdfLoadedDocument |
MessageBoxSettings
Gets and sets the message box settings.
Declaration
public MessageBoxSettings MessageBoxSettings { get; set; }
Property Value
Type |
---|
MessageBoxSettings |
MinimumZoomPercentage
Gets and sets the minimum zoom percentage. The value should be in between 10 and 400. The default value is 50.
Declaration
public int MinimumZoomPercentage { get; set; }
Property Value
Type |
---|
System.Int32 |
PageBorderThickness
Get or set the thickness of the page border. Default value is 1.
Declaration
public int PageBorderThickness { get; set; }
Property Value
Type |
---|
System.Int32 |
PageCount
Gets the page count
Declaration
public int PageCount { get; }
Property Value
Type |
---|
System.Int32 |
PrintDocument
Gets the print document
Declaration
public PrintDocument PrintDocument { get; }
Property Value
Type |
---|
System.Drawing.Printing.PrintDocument |
PrinterSettings
Represents printer settings for the document to be printed.
Declaration
public PdfViewerPrinterSettings PrinterSettings { get; set; }
Property Value
Type |
---|
PdfViewerPrinterSettings |
ReferencePath
Specifes the Pdfium path in PDF Viewer control
Declaration
public string ReferencePath { get; set; }
Property Value
Type |
---|
System.String |
RenderingEngine
Specifies the rendering mode for PdfViewer.
Declaration
[Obsolete("The SfPdf engine is no longer supported. By default, PDFium engine will be used. So avoid setting the Rendering engine for the PDF Viewer control")]
public PdfRenderingEngine RenderingEngine { get; set; }
Property Value
Type |
---|
PdfRenderingEngine |
ScrollDisplacementValue
Gets or sets the displacement value for scrolling.
Declaration
public int ScrollDisplacementValue { get; set; }
Property Value
Type |
---|
System.Int32 |
ShowHorizontalScrollBar
Gets and sets the boolean value to show and hide the horizontal scrollbar in PdfViewerControl
Declaration
public bool ShowHorizontalScrollBar { get; set; }
Property Value
Type |
---|
System.Boolean |
ShowToolBar
Gets and sets the visibility of the toolbar
Declaration
public bool ShowToolBar { get; set; }
Property Value
Type |
---|
System.Boolean |
ShowVerticalScrollBar
Gets and sets the boolean value to show and hide the vertical scrollbar in PdfViewerControl
Declaration
public bool ShowVerticalScrollBar { get; set; }
Property Value
Type |
---|
System.Boolean |
SpaceBetweenPages
Defines the page gap between the pages. The minimum value of ‘SpaceBetweenPages’ is 0.
Declaration
public int SpaceBetweenPages { get; set; }
Property Value
Type |
---|
System.Int32 |
Remarks
Default value is 8. The unit of ‘SpaceBetweenPages’ is pixel.
TextSearchSettings
Defines the textsearch settings when searching the text in the document
Declaration
public TextSearchSettings TextSearchSettings { get; set; }
Property Value
Type |
---|
TextSearchSettings |
ThemeStyle
Gets or sets the PdfViewerVisualStyle value used to customize the appearance of the PdfViewerControl.
Declaration
public PdfViewerVisualStyle ThemeStyle { get; set; }
Property Value
Type |
---|
PdfViewerVisualStyle |
ToolbarSettings
Represents document toolbar settings for PdfViewer.
Declaration
public DocumentToolbarSettings ToolbarSettings { get; set; }
Property Value
Type |
---|
DocumentToolbarSettings |
VerticalScrollOffset
Gets or sets the vertical scroll offset of the control.
Declaration
public int VerticalScrollOffset { get; set; }
Property Value
Type |
---|
System.Int32 |
VisualStyle
Visual style of the PdfViewerControl.
Declaration
public VisualStyle VisualStyle { get; set; }
Property Value
Type |
---|
VisualStyle |
ZoomMode
Gets and sets the Zoom Mode
Declaration
public ZoomMode ZoomMode { get; set; }
Property Value
Type |
---|
ZoomMode |
ZoomPercentage
Gets the current zoom percentage.
Declaration
public int ZoomPercentage { get; }
Property Value
Type |
---|
System.Int32 |
Methods
Dispose()
Clean up any resources being used.
Declaration
public void Dispose()
Dispose(Boolean)
Clean up any resources being used.
Declaration
protected override void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | disposing | true if managed resources should be disposed; otherwise, false. |
ExportAsImage(Int32)
Exports the specified page as Image
Declaration
public Bitmap ExportAsImage(int pageIndex)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | pageIndex | The page index to be converted into image |
Returns
Type | Description |
---|---|
System.Drawing.Bitmap | Returns the specified page as Image |
ExportAsImage(Int32, SizeF, Boolean)
Exports the specified page as Image
Declaration
public Bitmap ExportAsImage(int pageIndex, SizeF customSize, bool keepAspectRatio)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | pageIndex | The page index to be converted into image |
System.Drawing.SizeF | customSize | The custom size of the converted image |
System.Boolean | keepAspectRatio | Whether need to maintain the pdf page size |
Returns
Type |
---|
System.Drawing.Bitmap |
ExportAsImage(Int32, SizeF, Single, Single, Boolean)
Exports the specified page as Image
Declaration
public Bitmap ExportAsImage(int pageIndex, SizeF customSize, float dpiX, float dpiY, bool keepAspectRatio)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | pageIndex | The page index to be converted into image |
System.Drawing.SizeF | customSize | The custom size of the converted image |
System.Single | dpiX | The horizontal DPI of the resultant image. |
System.Single | dpiY | The vertical DPI of the resultant image. |
System.Boolean | keepAspectRatio | Whether need to maintain the pdf page size |
Returns
Type |
---|
System.Drawing.Bitmap |
ExportAsImage(Int32, Int32)
Exports the specified pages as Images
Declaration
public Bitmap[] ExportAsImage(int startIndex, int endIndex)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | startIndex | The starting page index |
System.Int32 | endIndex | The ending page index |
Returns
Type | Description |
---|---|
System.Drawing.Bitmap[] | Returns the specified pages as Images |
ExportAsImage(Int32, Int32, SizeF, Boolean)
Exports the specified pages as Images
Declaration
public Bitmap[] ExportAsImage(int startIndex, int endIndex, SizeF customSize, bool keepAspectRatio)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | startIndex | The starting page index |
System.Int32 | endIndex | The ending page index |
System.Drawing.SizeF | customSize | The custom size of the converted image |
System.Boolean | keepAspectRatio | Whether need to maintain the pdf page size |
Returns
Type | Description |
---|---|
System.Drawing.Bitmap[] | Returns the specified pages as images with custom size |
ExportAsImage(Int32, Int32, SizeF, Single, Single, Boolean)
Exports the specified pages as Images
Declaration
public Bitmap[] ExportAsImage(int startIndex, int endIndex, SizeF customSize, float dpiX, float dpiY, bool keepAspectRatio)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | startIndex | The starting page index |
System.Int32 | endIndex | The ending page index |
System.Drawing.SizeF | customSize | The custom size of the converted image |
System.Single | dpiX | The horizontal DPI of the resultant image. |
System.Single | dpiY | The vertical DPI of the resultant image. |
System.Boolean | keepAspectRatio | Whether need to maintain the pdf page size |
Returns
Type | Description |
---|---|
System.Drawing.Bitmap[] | Returns the specified pages as images with custom size and resolution |
ExportAsImage(Int32, Int32, Single, Single)
Exports the specified pages as Images with respect to dpi specified.
Declaration
public Bitmap[] ExportAsImage(int startIndex, int endIndex, float dpiX, float dpiY)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | startIndex | The starting page index |
System.Int32 | endIndex | The ending page index |
System.Single | dpiX | The horizontal DPI of the resultant image. |
System.Single | dpiY | The vertical DPI of the resultant image. |
Returns
Type | Description |
---|---|
System.Drawing.Bitmap[] | Returns the specified pages as Images with custom resolution |
ExportAsImage(Int32, Single, Single)
Exports the specified page as Image with respect to dpi specified.
Declaration
public Bitmap ExportAsImage(int pageIndex, float dpiX, float dpiY)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | pageIndex | The page index to be converted into image |
System.Single | dpiX | The horizontal DPI of the resultant image. |
System.Single | dpiY | The vertical DPI of the resultant image. |
Returns
Type | Description |
---|---|
System.Drawing.Bitmap | Returns the specified page as Image with custom resolution |
ExportAsMetafile(Int32)
Exports the specified page as System.Drawing.Imaging.Metafile
Declaration
public Metafile ExportAsMetafile(int pageIndex)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | pageIndex | The index of the PDF page. |
Returns
Type | Description |
---|---|
System.Drawing.Imaging.Metafile | Metafile |
ExportAsMetafile(Int32, Int32)
Exports the specified pages as System.Drawing.Imaging.Metafile
Declaration
public Metafile[] ExportAsMetafile(int startIndex, int endIndex)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | startIndex | The start index of the PDF page |
System.Int32 | endIndex | The end index of the PDF page |
Returns
Type | Description |
---|---|
System.Drawing.Imaging.Metafile[] | Array of Metafile |
ExtractText(Int32, out TextLines)
Extracts text from the page of PDF document with lines and words collection.
Declaration
public string ExtractText(int index, out TextLines textLines)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | |
TextLines | textLines | Holds the lines with bounds in the page. |
Returns
Type | Description |
---|---|
System.String | The Extracted Text. |
ExtractText(Int32, out List<TextData>)
Extracts text along with its format from the PDF Page.
Declaration
public string ExtractText(int index, out List<TextData> textDataCollection)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | |
System.Collections.Generic.List<TextData> | textDataCollection | Provides the text data collection |
Returns
Type | Description |
---|---|
System.String | Returns the extracted text. |
FindText(String, out Dictionary<Int32, List<RectangleF>>)
Returns the page number and rectangle positions of the text matchs
Declaration
public bool FindText(string text, out Dictionary<int, List<RectangleF>> matchRect)
Parameters
Type | Name | Description |
---|---|---|
System.String | text | The text to be searched |
System.Collections.Generic.Dictionary<System.Int32, System.Collections.Generic.List<System.Drawing.RectangleF>> | matchRect | Holds the page number and rectangle positions of the text matches |
Returns
Type |
---|
System.Boolean |
GoToBookmark(PdfBookmark)
Navigates to the location of the bookmark.
Declaration
public void GoToBookmark(PdfBookmark bookmark)
Parameters
Type | Name | Description |
---|---|---|
PdfBookmark | bookmark | The PdfBookmark object that contains the details of the bookmark to which the viewer has to navigate. |
Examples
PdfBookmarkBase bookmark = pdfViewerControl1.LoadedDocument.Bookmarks;
if (bookmark.Count > 0)
pdfViewerControl1.GoToBookmark(bookmark[0]);
GoToPageAtIndex(Int32)
Navigates to the specified page.
Declaration
public void GoToPageAtIndex(int index)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | The page index |
Load(PdfLoadedDocument)
Loads a pdf document in the Pdf viewer from the specified PdfLoadedDocuemnt.
Declaration
public void Load(PdfLoadedDocument loadedDocument)
Parameters
Type | Name | Description |
---|---|---|
PdfLoadedDocument | loadedDocument | The PdfLoadedDocument to be viewed in the PdfViewer |
Load(Stream)
Loads a Pdf document in the Pdf viewer from the specified stream.
Declaration
public void Load(Stream stream)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | stream | A stream that contains the data for the Pdf document |
Load(Stream, String)
Loads a Pdf document in the Pdf viewer from the specified stream.
Declaration
public void Load(Stream stream, string password)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | stream | A stream that contains the data for the Pdf document |
System.String | password | The password for opening the document. |
Load(String)
Loads a Pdf document in the Pdf viewer
Declaration
public void Load(string filePath)
Parameters
Type | Name | Description |
---|---|---|
System.String | filePath | The path for the Pdf document to display in the pdf viewer |
Load(String, String)
Loads a Pdf document in the Pdf viewer
Declaration
public void Load(string filePath, string password)
Parameters
Type | Name | Description |
---|---|---|
System.String | filePath | The path for the Pdf document to display in the pdf viewer |
System.String | password | The password for opening the document. |
OnThemeNameChanged(String)
Notifies when a theme name is changed.
Declaration
public override void OnThemeNameChanged(string themeName)
Parameters
Type | Name | Description |
---|---|---|
System.String | themeName | Represents the theme name. |
Overrides
Print(Boolean)
Prints the document loaded in the viewer.
Declaration
public void Print(bool showPrintDialog)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | showPrintDialog | If set to true, displays the PrintDialog box. Prints in silent mode when set to false. |
Print(Boolean, Boolean)
Prints the document loaded in the viewer.
Declaration
public void Print(bool showPrintDialog, bool printDocumentAsText)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | showPrintDialog | If set to true, displays the PrintDialog box. Prints in silent mode when set to false. |
System.Boolean | printDocumentAsText | If set to true, text elements are printed as selectable text. Otherwise it is printed as non selectable text |
Print(String)
Prints the document on the specified printer.
Declaration
public void Print(string printerName)
Parameters
Type | Name | Description |
---|---|---|
System.String | printerName | The name of the destination printer to print the PDF document. |
ProcessCmdKey(ref Message, Keys)
Declaration
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
Parameters
Type | Name | Description |
---|---|---|
System.Windows.Forms.Message | msg | |
System.Windows.Forms.Keys | keyData |
Returns
Type |
---|
System.Boolean |
SearchNextText(String)
Search the next occurrence of the text.
Declaration
public void SearchNextText(string targetString)
Parameters
Type | Name | Description |
---|---|---|
System.String | targetString | The text to be searched |
SearchPreviousText(String)
Search the previous occurrence of the text.
Declaration
public void SearchPreviousText(string targetString)
Parameters
Type | Name | Description |
---|---|---|
System.String | targetString | The text to be searched |
SearchText(String)
Searches the text
Declaration
public void SearchText(string targetText)
Parameters
Type | Name | Description |
---|---|---|
System.String | targetText |
ShowTextSearchBar()
Display text search bar for search text in viewer.
Declaration
public void ShowTextSearchBar()
Unload()
Unloads the Pdf document
Declaration
public void Unload()
ZoomTo(Int32)
Magnifies the page of the document to the provided zoom percentage.
Declaration
public void ZoomTo(int percentage)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | percentage | Zoom percentage |
Events
BeginPrint
Occurs when the print is called and before the first page of the document prints.
Declaration
public event EventHandler<BeginPrintEventArgs> BeginPrint
Event Type
Type |
---|
System.EventHandler<BeginPrintEventArgs> |
BeginSave
Occurs before initiating the save operation of the PDF document.
Declaration
public event EventHandler<BeginSaveEventArgs> BeginSave
Event Type
Type |
---|
System.EventHandler<BeginSaveEventArgs> |
ButtonClicked
Occurs when button clicked.
Declaration
public event PdfViewerControl.ButtonClickedEventHandler ButtonClicked
Event Type
Type |
---|
PdfViewerControl.ButtonClickedEventHandler |
CurrentPageChanged
Occurs when current page is changed.
Declaration
public event PdfDocumentView.CurrentPageChangedEventHandler CurrentPageChanged
Event Type
Type |
---|
PdfDocumentView.CurrentPageChangedEventHandler |
DocumentLoaded
Occurs when the pdf document is loaded
Declaration
public event PdfViewerControl.DocumentLoadedEventHandler DocumentLoaded
Event Type
Type |
---|
PdfViewerControl.DocumentLoadedEventHandler |
DocumentLoading
Occurs when the PDF document is loading.
Declaration
public event EventHandler<DocumentLoadingEventArgs> DocumentLoading
Event Type
Type |
---|
System.EventHandler<DocumentLoadingEventArgs> |
DocumentUnloaded
Occurs when the PDF document is unloaded
Declaration
public event EventHandler<DocumentUnloadedEventArgs> DocumentUnloaded
Event Type
Type |
---|
System.EventHandler<DocumentUnloadedEventArgs> |
EndPrint
Occurs when the last page of the document has printed. This event also occurs if the printing process is canceled or an exception occurs during the printing process.
Declaration
public event EventHandler<EndPrintEventArgs> EndPrint
Event Type
Type |
---|
System.EventHandler<EndPrintEventArgs> |
EndSave
Occurs after the completion of the save operation.
Declaration
public event EventHandler<EndSaveEventArgs> EndSave
Event Type
Type |
---|
System.EventHandler<EndSaveEventArgs> |
ErrorOccurred
Occurs when the error occurred in PdfViewerControl
Declaration
public event EventHandler<ErrorOccurredEventArgs> ErrorOccurred
Event Type
Type |
---|
System.EventHandler<ErrorOccurredEventArgs> |
HyperlinkClicked
Occurs when the Hyperlink is clicked in a page of
Declaration
public event EventHandler<HyperlinkClickedEventArgs> HyperlinkClicked
Event Type
Type |
---|
System.EventHandler<HyperlinkClickedEventArgs> |
HyperlinkMouseOver
Occurs when the mouse is moved over the hyperlink.
Declaration
public event EventHandler<HyperlinkMouseOverEventArgs> HyperlinkMouseOver
Event Type
Type |
---|
System.EventHandler<HyperlinkMouseOverEventArgs> |
ImagePreRender
Occurs prior to the rendering of every image in the document
Declaration
public event PdfViewerControl.ImagePreRenderEventHandler ImagePreRender
Event Type
Type |
---|
PdfViewerControl.ImagePreRenderEventHandler |
KeyPressed
Occurs when a key is pressed
Declaration
public event PdfViewerControl.KeyPressedEventHandler KeyPressed
Event Type
Type |
---|
PdfViewerControl.KeyPressedEventHandler |
PrintProgress
Occurs to provide information on how much of printing content were submitted to printing subsystem
Declaration
public event EventHandler<PrintProgressEventArgs> PrintProgress
Event Type
Type |
---|
System.EventHandler<PrintProgressEventArgs> |
ScrollChanged
Occurs when scroll is changed.
Declaration
public event EventHandler<ScrollChangedEventArgs> ScrollChanged
Event Type
Type |
---|
System.EventHandler<ScrollChangedEventArgs> |
TextMatchFound
Occurs when a match for the searched text found.
Declaration
public event EventHandler<TextMatchFoundEventArgs> TextMatchFound
Event Type
Type |
---|
System.EventHandler<TextMatchFoundEventArgs> |
TextSearchCompleted
Occurs when a text search operation is completed.
Declaration
public event EventHandler<TextSearchCompletedEventArgs> TextSearchCompleted
Event Type
Type |
---|
System.EventHandler<TextSearchCompletedEventArgs> |
TextSearchInitiated
Occurs when the text search is initiated.
Declaration
public event EventHandler<TextSearchInitiatedEventArgs> TextSearchInitiated
Event Type
Type |
---|
System.EventHandler<TextSearchInitiatedEventArgs> |
TextSelectionCompleted
Event triggered once the text selection was completed
Declaration
public event PdfViewerControl.TextSelectionCompletedEventHandler TextSelectionCompleted
Event Type
Type |
---|
PdfViewerControl.TextSelectionCompletedEventHandler |