Display PDFs with
Pixel-Perfect Rendering
A powerful PDF viewer component for Windows desktop applications. Drag, drop, and display PDF documents with full zoom, search, and selection capabilities.
Code Examples
Explore how to integrate the PDF Viewer component into your .NET applications
Open Document
Open a PDF document and use the status of the open operation. Subscribe to the DocumentLoaded event for async notifications.
var pdfViewer = new PdfViewer();
pdfViewer.DocumentLoaded += PdfViewer_DocumentLoaded;
PdfOpenFileStatus status = pdfViewer.OpenDocument(@"c:\test\test.pdf");
string msg = "";
if (status.Result == PdfOpenFileStatus.PdfOpenFileResult.OK)
msg = string.Format("Document has {0} pages. Current page is {1}.",
pdfViewer.NumberOfPages, pdfViewer.CurrentPageNumber);
else
msg = "Problem loading document. Status = " + status.Result.ToString();
MessageBox.Show(msg);
private void PdfViewer_DocumentLoaded(object sender, DocumentLoadedEventArgs e)
{
MessageBox.Show("Document " + e.FileName + " was loaded");
}
Print PDF Document
Print the PDF document directly from the viewer and subscribe to print events for progress tracking.
var pdfViewer = new PdfViewer();
pdfViewer.OpenDocument(@"c:\test\test.pdf");
// Subscribe to print events
pdfViewer.DocumentPrintBegin += PdfViewer_DocumentPrintBegin;
pdfViewer.DocumentPrintEnd += PdfViewer_DocumentPrintEnd;
pdfViewer.DocumentPrintPageBegin += PdfViewer_DocumentPrintPageBegin;
pdfViewer.DocumentPrintPageEnd += PdfViewer_DocumentPrintPageEnd;
PdfPrint.Status status = pdfViewer.Print();
private void PdfViewer_DocumentPrintPageBegin(object sender,
PdfPrint.DocumentPrintPageEventArgs e)
{
string msg = "Print page begin. Page " + e.PageNumber +
" of " + e.TotalNumberOfPagesToPrint;
}
PDF Selection
Enable text and image selection within PDF documents for user interaction.
var pdfViewer = new PdfViewer();
pdfViewer.OpenDocument(@"c:\test\test.pdf");
// Enable selection mode
pdfViewer.SelectionMode = SelectionMode.Text;
// Get selected text
string selectedText = pdfViewer.GetSelectedText();
// Copy selection to clipboard
pdfViewer.CopySelectionToClipboard();
// Clear selection
pdfViewer.ClearSelection();
// Selection changed event
pdfViewer.SelectionChanged += (s, e) => {
Console.WriteLine("Selection changed: " + e.SelectedText);
};
Search PDF Document
Search for text within PDF documents and navigate through search results with highlighting.
var pdfViewer = new PdfViewer();
pdfViewer.OpenDocument(@"c:\test\test.pdf");
// Search for text
var searchResults = pdfViewer.Search("search term");
// Navigate through results
pdfViewer.GoToNextSearchResult();
pdfViewer.GoToPreviousSearchResult();
// Highlight all matches
pdfViewer.HighlightSearchResults = true;
// Search options
var options = new SearchOptions
{
CaseSensitive = false,
WholeWordsOnly = true,
HighlightColor = Color.Yellow
};
pdfViewer.Search("term", options);
Manage PDF Zoom
Control zoom levels programmatically with preset values or custom percentages.
var pdfViewer = new PdfViewer();
pdfViewer.OpenDocument(@"c:\test\test.pdf");
// Get available zoom levels (50, 75, 100, 125...)
var availableZoomValues = pdfViewer.GetAvailableZoomLevels();
// Zoom in/out to next preset level
pdfViewer.ZoomIn();
pdfViewer.ZoomOut();
// Set zoom to fit page
pdfViewer.ZoomValue = (float)Math.Round(
pdfViewer.FitToPageZoomValue * 100, 2);
// Get zoom limits
var minZoom = pdfViewer.GetMinZoomLevel();
var maxZoom = pdfViewer.GetMaxZoomLevel();
// Set custom zoom (100 = actual size)
pdfViewer.ZoomValue = 70;
Open a PDF document and handle the status of the open operation.
var pdfViewer = new PdfViewer();
PdfOpenFileStatus status = pdfViewer.OpenDocument(@"c:\test\test.pdf");
if (status.Result == PdfOpenFileStatus.PdfOpenFileResult.OK)
Console.WriteLine("Pages: " + pdfViewer.NumberOfPages);
Print the PDF document and subscribe to print events.
var pdfViewer = new PdfViewer();
pdfViewer.OpenDocument(@"c:\test\test.pdf");
PdfPrint.Status status = pdfViewer.Print();
Navigate through PDF pages with various methods.
pdfViewer.GoToFirstPage();
pdfViewer.GoToLastPage();
pdfViewer.GoToPage(5);
int currentPage = pdfViewer.CurrentPageNumber;
Enable text and image selection within PDF documents.
pdfViewer.SelectionMode = SelectionMode.Text;
string text = pdfViewer.GetSelectedText();
pdfViewer.CopySelectionToClipboard();
Search for text within PDF documents.
var results = pdfViewer.Search("search term");
pdfViewer.GoToNextSearchResult();
pdfViewer.HighlightSearchResults = true;
Control zoom levels programmatically.
pdfViewer.ZoomIn();
pdfViewer.ZoomOut();
pdfViewer.ZoomValue = 150; // 150%
Ready to Get Started?
Download the free demo and start displaying PDFs in your .NET applications today.
Download Free Demo