
Syncfusion Winforms Pdf Viewer
- 1 installs
- 1 repo stars
- Updated July 6, 2026
- syncfusion/pdf-viewer-sdk-skills
Generates WinForms C# code for the Syncfusion PDF Viewer with loading, saving, printing, text search and extraction, bookmark navigation, zooming, and theming.
About
Generates C# code for the Syncfusion WinForms PDF Viewer covering PDF loading, printing, text search, extraction, navigation, and theming. A developer uses it when building desktop PDF viewing solutions in WinForms.
- Requires .NET Framework 4.5+ or .NET Core/NET 8+ with Syncfusion.PdfViewer.Windows
- Supports rendering-engine selection, localization, and error handling
Syncfusion Winforms Pdf Viewer by the numbers
- 1 all-time installs (skills.sh)
- Ranked #121 of 153 .NET & C# skills by installs in the Skillselion catalog
- Data as of Jul 8, 2026 (Skillselion catalog sync)
npx skills add https://github.com/syncfusion/pdf-viewer-sdk-skills --skill syncfusion-winforms-pdf-viewerAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 1 |
|---|---|
| repo stars | ★ 1 |
| Last updated | July 6, 2026 |
| Repository | syncfusion/pdf-viewer-sdk-skills ↗ |
What it does
Generates WinForms C# code for the Syncfusion PDF Viewer with loading, saving, printing, text search and extraction, bookmark navigation, zooming, and theming.
Files
Syncfusion WinForms PdfViewer - UI Sample generator
Generate C# Code for the User's Project (default)
Trigger keywords: "code", "snippet", "how to write", "Program.cs", "show me", "sample", "integrate", "example code", "generate code for", "create sample", "winforms pdfviewer".
Purpose: Generate clean, ready-to-use C# code snippets that directly insert into their WinForms application when working with Syncfusion WinForms PdfViewer control.
Workflow: 1. Build the C# code using the snippets provided in the references/*.md files. 2. Before generating the sample, ask the user whether the code should be:Integrated into an existing WinForms project, or Created as a new WinForms application. 3. If the user chooses to create a new WinForms project, ask them which target framework they want to use: -.NET Framework (e.g., 4.6, 4.7, 4.8) — uses Syncfusion.PdfViewer.WinForms and targets the classic .NET Framework. -.NET / .NET Core (e.g., .NET 8, .NET 10) — uses Syncfusion.PdfViewer.WinForms with <TargetFramework>net8.0-windows</TargetFramework> (or the selected version). 4. Based on the user's choice: Generate the .csproj file with the correct <TargetFramework> value. Add the required NuGet packages. Tailor any framework-specific code, such as namespace imports, form initialization, startup code (Program.cs), and PDF Viewer setup, accordingly. 5. Add only the APIs required to satisfy the user's requested functionality. Do not include optional APIs, additional. ---
Code References
All templates and snippets are in the references/ folder. Each file is a focused snippet or template the agent will combine when generating sample:
| File | Contents |
|---|---|
| view-pdfviewer.md | NuGet setup, add PdfViewerControl/PdfDocumentView, load PDF |
| saving-pdf-files.md | Save PDF via toolbar, programmatic save using LoadedDocument.Save(), BeginSave and EndSave events |
| printing-pdf-files.md | Print PDF via toolbar, silent printing using Print(), customize print size (ActualSize, Fit, CustomScale), print orientation (Auto, Portrait, Landscape), hide print status dialog, BeginPrint, PrintProgress, and EndPrint events |
| extract-text.md | Extract text from a single page using ExtractText(pageIndex, out textLines), extract text from entire file using PageCount loop, extract text with line bounds via TextLines/TextLine, extract words with bounds via WordCollection/TextWord |
| pdf-rendering-engines.md | Switch rendering engine using RenderingEngine property (PDFium default, SfPdf alternative), set custom PDFium binary path via ReferencePath for restricted-access environments |
| searching-text.md | Search next/previous text instance using SearchNextText()/SearchPreviousText(), find all instances with bounds using FindText(), count total matches, enable/disable highlight all instances via TextSearchSettings.HighlightAllInstance, customize highlight colors via TextSearchSettings.CurrentInstanceColor/OtherInstanceColor |
| navigation.md | Bookmark navigation, hyperlink handling, and page navigation (programmatic GoToBookmark(), HyperlinkClicked/HyperlinkMouseOver, GoToPageAtIndex()) |
| localization.md | Localize tooltip and context menu static text, default en-US localization keys table, add culture-specific Resx files (e.g., Syncfusion.PdfViewer.Windows.fr.resx), set custom assembly/namespace for localization using LocalizationManager.SetResources() |
| themes.md | Apply built-in themes using ThemeName property (Office2016Colorful, Office2016Black, Office2016DarkGray, Office2016White, Office2019Colorful, HighContrastBlack), load theme assemblies via SkinManager.LoadAssembly(), reset to default theme |
| interaction-modes.md | Switch cursor modes using CursorMode property — PdfViewerCursorMode.SelectTool for text selection (default), PdfViewerCursorMode.HandTool for panning/scrolling |
| error-handling.md | Subscribe to ErrorOccurred event, handle ErrorOccurredEventArgs.Message to log errors or display messages to users |
| magnifying.md | Zoom to a specific percentage using ZoomTo(), get current zoom via ZoomPercentage, switch zoom modes using ZoomMode property (FitPage, FitWidth) |
| view-pdf-stream.md | Load a PDF from a FileStream using the Load(stream) overload |
| document-information.md | Access filename and file path of the loaded PDF via DocumentInformation.FileName and DocumentInformation.FilePath; get page count via PageCount |
| mouse-position.md | Handle PageClicked and PageMouseMove events to get page index and mouse position relative to the PDF page |
| host-wpf-pdfviewer-in-winforms.md | Host the WPF PdfViewer inside a WinForms app using ElementHost to access advanced features (annotations, form filling, signatures) |
| toolbar.md | Show/hide individual toolbar buttons (Open, Save, Zoom, Print, Pan) using ToolbarSettings.<Button>.IsVisible |
---
Prerequisites
- Development Environment:Visual Studio 2022 or Visual Studio insider 2026(recommended for .NET 10).
- .NET Framework 4.5+ or .NET Core/NET 8+
- Syncfusion WinForms NuGet Package: Syncfusion.PdfViewer.Windows
Documentations
Syncfusion WinForms PdfViewer skill
Overview
Create WinForms applications featuring the Syncfusion WinForms PDF Viewer, customized to meet specific user requirements.
See [SKILL.md](SKILL.md) for the full intent-routing guide and rules.
---
Key Capabilities
- High-fidelity PDF rendering & navigation: pdf viewing, bookmark navigation, hyperlink navigation, interaction modes, printing and saving pdf files.
- Text search & extraction: text search and extract text from pdf.
Getting Started
How to Integrate Skills
Step 1: Checkout and copy the required skills
Clone or download the PDF-Viewer-SDK-Skills repository and copy the winforms-pdf-viewer skill from the skills/ directory.
Step 2: Install the skill
Place the copied skill folders in your workspace following this structure:
your-workspace/
├── .github/skills/ # or .claude/skills/ or .codestudio/skills/
│ └── winforms-pdf-viewer/
│ └── SKILL.md
├── your-project-files...
└── Program.csStep 3: Verify and manage your skills
Type /skills in the GitHub Copilot or Code Studio chat to quickly access the Configure Skills menu and manage your installed skills.
Step 4: Use skills in VS Code
There are two ways to use skills:
1. Slash commands - Type / in the GitHub Copilot chat to see available skills.
2. Automatic loading - Simply describe your task naturally, and your AI Agent automatically loads the relevant skill:
Create a WinForms window with WinForms PdfViewer that loads pdf documentWhen the winforms-pdf-viewer skill is loaded, the AI Agent provides focused C# snippets and commands for WinForms PdfViewer.
Prerequisites
- Visual Studio 2019 or later
- .NET Framework 4.6+ or .NET 6+
- Syncfusion License — register your key in
Program.cs, or set theSYNCFUSION_LICENSE_KEYenvironment variable.
Free license: Syncfusion Community License
NuGet Packages
dotnet add package Syncfusion.PdfViewer.Windows---
Example Prompts
Code Generation
Use these when you want C# code for your existing WinForms project.
- "Create a C# WinForms Form that adds a Syncfusion PdfViewer, loads a PDF from disk, and shows zoom/print toolbar buttons."
- "Add code to extract all text from page 2 and save it to a .txt file."
- "Show how to save the currently loaded PDF to a new file programmatically"
---
Troubleshooting
| Issue | Solution |
|---|---|
| License warning at startup | Call SyncfusionLicenseProvider.RegisterLicense() in Program.cs before any control is created |
| Missing NuGet package | dotnet add package Syncfusion.PdfViewer.Windows |
---
Resources
---
License
Syncfusion WinForms PdfViewer requires a commercial license for production use. A free community license is available for qualifying organizations.
Get Document Information
The PDF Viewer allows you to access the filename and file path of the loaded PDF document.
Get Filename
// Gets the filename of the loaded PDF document
string fileName = pdfViewer.DocumentInformation.FileName;Get File Path
// Gets the file path of the loaded PDF document
string filePath = pdfViewer.DocumentInformation.FilePath;Get Page Count
int count = pdfViewerControl1.PageCount;Working with ErrorOccurred Event
The ErrorOccurred event in PdfViewerControl is triggered whenever an error occurs within the control. This allows developers to log error details or display appropriate messages to users.
Subscribe to the ErrorOccurred Event
PdfViewer.ErrorOccurred += PdfViewer_ErrorOccurred;Handle the ErrorOccurred Event
private void PdfViewer_ErrorOccurred(object sender, ErrorOccurredEventArgs e)
{
// Log error message
Console.WriteLine("Error occurred in PdfViewerControl: " + e.Message);
// Display error message to the user
MessageBox.Show("An error occurred while viewing the PDF: " + e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}Extract Text from PDF Files in Windows Forms PDF Viewer
WinForms PDF Viewer allows you to extract the text from a particular page or from the entire PDF file using the ExtractText methods of PdfDocumentView.
---
Extract Text from a Particular Page
//Initialize the `PdfDocumentView` control.
PdfDocumentView pdfDocumentView = new PdfDocumentView();
//Load the PDF file.
pdfDocumentView.Load(@"Sample.pdf");
//Extract text from the first page.
TextLines textLines = new TextLines();
string extractedText = pdfDocumentView.ExtractText(0, out textLines);---
Extract Text from an Entire File
//Initialize the `PdfDocumentView` control.
PdfDocumentView pdfDocumentView = new PdfDocumentView();
//Load the PDF file.
pdfDocumentView.Load(@"Sample.pdf");
//Extract text from the file.
TextLines textLines = new TextLines();
string extractedText = string.Empty;
for (int i = 0; i < pdfDocumentView.PageCount; i++)
{
extractedText += pdfDocumentView.ExtractText(i, out textLines);
}---
Extract Text with Bounds
Extract Lines
//Initialize the `PdfDocumentView` control.
PdfDocumentView pdfDocumentView = new PdfDocumentView();
//Load the PDF file.
pdfDocumentView.Load(@"Sample.pdf");
//Initialize the `TextLines`
TextLines textLines = new TextLines();
//Pass the `TextLines` as a parameter to the `ExtractText` method.
pdfDocumentView.ExtractText(0, out textLines);
//Gets specific line from the collection through the index.
TextLine line = textLines[0];
//Get text in the line.
string text = line.Text;
//Get bounds of the line.
RectangleF lineBounds = line.Bounds;Extract Words
You can get the words in a line along with bounds using the WordCollection property of TextLine.
//Initialize the `PdfDocumentView` control.
PdfDocumentView pdfDocumentView = new PdfDocumentView();
//Load the PDF file.
pdfDocumentView.Load(@"Sample.pdf");
//Initialize the `TextLines`
TextLines textLines = new TextLines();
//Pass the `TextLines` as a parameter to the `ExtractText` method.
pdfDocumentView.ExtractText(0, out textLines);
//Gets specific line from the collection through the index.
TextLine line = textLines[0];
//Get the word collection in a line.
List<TextWord> wordCollection = line.WordCollection;
//Get the word
TextWord word = wordCollection[0];
//Get the text
string text = word.Text;
//Get the bounds of the word
RectangleF bounds = word.Bounds;Host WPF PdfViewer Features in WinForms
To leverage the advanced features offered by the WPF PdfViewer — such as adding annotations, form filling, signatures, stamps, sticky notes, and more — you can integrate the WPF PdfViewer into a Windows Forms application and take advantage of its extensive feature set.
A WPF PdfViewer control can be hosted within a Windows Forms application using an ElementHost. By embedding the WPF PdfViewer, you can access advanced features available in the WPF control while maintaining a Windows Forms interface.
Steps to Host the WPF PdfViewer in a WinForms Application
Step 1: Add a WPF UserControl and install the Syncfusion.PdfViewer.WPF NuGet package to your WinForms application.
Step 2: Add the following Syncfusion namespace in XAML to make use of the WPF PdfViewerControl.
<UserControl
xmlns:PdfView="clr-namespace:Syncfusion.Windows.PdfViewer;assembly=Syncfusion.PdfViewer.WPF">
</UserControl>Step 3: Add the following code in the XAML page to initialize the WPF PdfViewer.
<Grid>
<PdfView:PdfViewerControl x:Name="pdfViewer"/>
</Grid>Step 4: Load the PDF file into the PdfViewer when the UserControl is loaded in the application.
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
pdfViewer.Load(@"../../Data/Windows Store Apps Succinctly.pdf");
}Step 5: Add a panel to the form. Create an ElementHost object in the Form and add the created UserControl's object as a child to the ElementHost object. Add the ElementHost as a child to the panel as shown below.
// Create the ElementHost control to host the WPF PdfViewer
ElementHost elementHost = new ElementHost();
elementHost.AutoSize = true;
elementHost.Size = panel1.Size;
elementHost.Dock = DockStyle.Fill;
// Adds the ElementHost to the panel1 control
panel1.Controls.Add(elementHost);
// Create the WPF PdfViewer control and assign it as a child of ElementHost
PdfViewerUserControl pdfViewerUserControl = new PdfViewerUserControl();
// Embeds the PdfViewer into the ElementHost
elementHost.Child = pdfViewerUserControl;
// Set additional visual properties for a seamless look and feel
elementHost.Margin = new Padding(0, 0, 0, 0);
elementHost.Region = new Region();
elementHost.BackColor = System.Drawing.Color.White;Hosting the WPF viewer allows using features not available in the WinForms control while keeping the rest of the app WinForms-based.
Interaction Modes
PDF Viewer supports two cursor modes for interacting with PDF documents via the CursorMode property of PdfViewerControl.
Selection Mode
pdfViewerControl1.CursorMode = PdfViewerCursorMode.SelectTool;Panning Mode
pdfViewerControl1.CursorMode = PdfViewerCursorMode.HandTool;Localization
Localization is the process of configuring the application to a specific language. PDF Viewer provides support to localize all the static text used for tooltip and context menu contents. Localization can be done by adding resource file (Resx) in the application.
Default Localization Keys
The following table shows the default values for the common text used in the PdfViewerControl which is in en-US culture:
| Name | Value |
|---|---|
| Bookmarks | Bookmarks |
| Cancel | Cancel |
| CloseBookmarks | Click to close the bookmark pane |
| CloseSearchBar | Close search bar |
| CopyException | Copy exception detail to the clipboard |
| DocumentProtected | This document is password protected. Please enter a Document Open Password. |
| EnterPassword | Enter Password: |
| ErrorDocument | Essential PDF Viewer could not open the PDF document |
| EssentialPdfViewer | Essential Pdf Viewer |
| FitPage | Click to show one page at a time. |
| FitWidth | Click to fill the window with each page and scroll through pages continuously. |
| GoToFirstPage | Click to go to first page in the document. |
| GoToLastPage | Click to go to last page in the document. |
| GoToNextPage | Click to go to next page in the document. |
| GoToPreviousPage | Click to go to previous page in the document. |
| LoadingPage | Loading Page |
| LoadingSeparator | Of |
| Next | Next |
| NoMatches | Reader has finished searching the document. No more matches were found |
| Ok | Ok |
| OpenDocument | Click to open a PDF Document |
| Password | Password |
| Previous | Previous |
| PrintDocument | Click to Print this PDF file or pages from it. |
| SaveDocument | Click to save the document in the local disk |
| Searching | Searching |
| Separator | Of |
| ViewBookmarks | Click to view the bookmarks |
| Zoom | Zoom. |
| ZoomIn | Click to increase the magnification of the entire page. |
| ZoomOut | Click to decrease the magnification of the entire page. |
Create a .resx file named Syncfusion.PdfViewer.Windows.[CultureName].resx that includes all the name–value pairs listed in the table for the corresponding culture. Add the generated .resx file to the Resources folder for reference.
Adding Resource File
- Create a folder named
Resourcesin your application. - Add the default English (
en-US) Resx file ofPdfViewerControlin theResourcesfolder named asSyncfusion.PdfViewer.Windows.resx. - Create a new Resx file named as
Syncfusion.PdfViewer.Windows.[Culture name].resx. For example,Syncfusion.PdfViewer.Windows.fr.resxfor French culture. - Add the resource key (e.g.,
OpenDocument) and its corresponding localized value in the culture-specific Resx file. - Execute the application in the target culture to see the changes.
Localize Resource File with Different Assembly or Namespace
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("ar-AE");
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("ar-AE");
// Set the custom assembly and namespace for the localization.
LocalizationManager.SetResources(typeof(Custom_Form).Assembly, "ClassLibrary");
InitializeComponent();Magnifying PDF Documents
The WinForms PDF Viewer provides built-in zoom tools in the toolbar and programmatic APIs to control the magnification of the displayed PDF document.
Zoom to a Specific Percentage
// Zoom to 235 percentage.
pdfViewer.ZoomTo(235);Get the Current Zoom Percentage
// Get the current zoom percentage.
int currentZoomPercentage = pdfViewer.ZoomPercentage;Set Zoom Mode
// To apply fit-to-page zoom mode.
pdfViewer.ZoomMode = ZoomMode.FitPage;
// To apply fit-to-width zoom mode.
pdfViewer.ZoomMode = ZoomMode.FitWidth;Get Mouse Position
The PdfViewerControl notifies you when performing mouse click and mouse move operations on PDF pages through the PageClicked and PageMouseMove events respectively. These events also provide information such as the page index and mouse position relative to the page.
Page Clicked Event
// Wire the PageClicked event.
pdfViewerControl1.PageClicked += PdfViewer_PageClicked;
void PdfViewer_PageClicked(object sender, PageClickedEventArgs args)
{
// Find the page number in which the mouse click occurred.
int currentPage = args.PageIndex;
// Find the mouse position on the document page.
System.Drawing.PointF mousePosition = args.Position;
}Page Mouse Move Event
// Wire the PageMouseMove event.
pdfViewerControl1.PageMouseMove += Pdfviewer_PageMouseMove;
void Pdfviewer_PageMouseMove(object sender, PageMouseMoveEventArgs args)
{
// Find the page number in which the mouse move occurred.
int currentPage = args.PageIndex;
// Find the mouse position on the document page.
System.Drawing.PointF mousePosition = args.Position;
}Bookmark Navigation
Programmatically Navigate to a Bookmark
// Wire the document loaded event.
pdfViewer.DocumentLoaded += PdfViewer_DocumentLoaded;
// Load the PDF.
pdfViewer.Load("../../Data/C_Sharp_Succinctly.pdf");In the DocumentLoaded event handler, call the bookmark navigation logic:
private void PdfViewer_DocumentLoaded(object sender, EventArgs args)
{
GoToBookmark();
}Navigate to the first bookmark in the document:
void GoToBookmark()
{
PdfLoadedDocument pdfLoadedDocument = pdfViewer.LoadedDocument;
// Get the complete bookmarks in the PDF.
PdfBookmarkBase bookmarks = pdfLoadedDocument.Bookmarks;
// Get the first bookmark in the PDF bookmarks collection at index 0.
PdfBookmark firstBookmark = bookmarks[0];
// Navigate to the first bookmark.
pdfViewer.GoToBookmark(firstBookmark);
}---
Navigate to a Child Bookmark
void GoToChildBookmark()
{
PdfLoadedDocument pdfLoadedDocument = pdfViewer.LoadedDocument;
// Get the complete bookmarks in the PDF.
PdfBookmarkBase bookmarks = pdfLoadedDocument.Bookmarks;
// Get the fourth bookmark at index 3.
PdfBookmark fourthBookmark = bookmarks[3];
// Check whether it has child bookmarks.
if (fourthBookmark.Count > 0)
{
// Navigate to the first child of the fourth bookmark.
pdfViewer.GoToBookmark(bookmarks[3][0]);
}
}---
Enable or Disable Bookmark Feature
// Disable the bookmark feature.
pdfViewerControl.IsBookmarkEnabled = false;Set to true to re-enable it.
Working with Hyperlinks
Disable Hyperlink Navigation
pdfViewerControl.HyperlinkClicked += PdfViewerControl_HyperlinkClicked;
private void PdfViewerControl_HyperlinkClicked(object sender, Syncfusion.Windows.Forms.PdfViewer.HyperlinkClickedEventArgs args)
{
// Gets or sets the value to handle the navigation of hyperlink.
args.Handled = true;
}Retrieve Hyperlink Details
HyperlinkClicked Event
pdfViewerControl.HyperlinkClicked += PdfViewerControl_HyperlinkClicked;
private void PdfViewerControl_HyperlinkClicked(object sender, Syncfusion.Windows.Forms.PdfViewer.HyperlinkClickedEventArgs args)
{
// Returns the URI clicked in the PDF viewer control.
string URI = args.Uri;
}HyperlinkMouseOver Event
pdfViewerControl.HyperlinkMouseOver += PdfViewerControl_HyperlinkMouseOver;
private void PdfViewerControl_HyperlinkMouseOver(object sender, Syncfusion.Windows.Forms.PdfViewer.HyperlinkMouseOverEventArgs e)
{
// Returns the URI hovered in the PDF viewer control.
string URI = e.Uri;
}Redirect to a Different Hyperlink
pdfViewerControl.HyperlinkClicked += PdfViewerControl_HyperlinkClicked;
private void PdfViewerControl_HyperlinkClicked(object sender, Syncfusion.Windows.Forms.PdfViewer.HyperlinkClickedEventArgs args)
{
// Stops the navigation of the clicked hyperlink.
args.Handled = true;
// Opens a different URI in the default browser.
System.Diagnostics.Process.Start("www.google.com");
}Page Navigation
Navigate to a Specific Page
Navigation to a specific page through code is possible using the GoToPageAtIndex method.
pdfViewerControl1.GoToPageAtIndex(2);Navigate to a Specific Horizontal and Vertical Offset Programmatically
// Load the PDF
pdfViewerControl1.Load("Sample.pdf");
// Navigate to the horizontal and vertical offset of 100 and 400 respectively
pdfViewerControl1.HorizontalScrollOffset = 100;
pdfViewerControl1.VerticalScrollOffset = 400;PDF Rendering Engines in WinForms PdfViewer
Overview
Syncfusion WinForms PDF Viewer renders PDF pages through 2 different rendering engines:
- PDFium – Google Chrome's PDF rendering engine (default since v16.3.0.x)
- SfPdf – Syncfusion's own PDF rendering engine
---
PDFium
PDFium is used in Google Chrome for rendering PDF files. It provides accurate and robust PDF rendering. It is the recommended PDF rendering engine.
How PDFium works
- On running the WinForms application, the PDF Viewer generates a folder named
PDFiumin the application output path (e.g.,bin/releaseorbin/debug) at runtime. - It detects the machine architecture automatically and creates a subfolder named
x64,x86, orarm64. - Extracts the
PDFium.dllinto the subfolder and uses it to render PDF files.
---
When you include PdfToImageConverter via a NuGet package, PDFium assemblies will automatically be generated in the application's output path folder from the NuGet package during compilation.SfPdf Rendering Engine
SfPdf is Syncfusion's own rendering engine. To switch to SfPdf, set the RenderingEngine property:
// Set the rendering engine to SfPdf.
pdfViewer.RenderingEngine = PdfRenderingEngine.SfPdf;
// Load the PDF.
pdfViewer.Load("Sample.pdf");---
````markdown
Printing PDF Files in WinForms PdfViewer
Overview
The PdfViewerControl allows printing loaded PDFs using the Print button in the toolbar, which opens a standard Print dialog. It also supports silent printing and customizable print settings.
---
Silent Printing
// Print silently to the default printer.
pdfViewerControl1.Print(false);---
Customizing Print Size
Set Actual Size (Default)
// Prints the document in actual size.
pdfViewerControl1.PrinterSettings.PageSize = PdfViewerPrintSize.ActualSize;Set Fit
// Prints the document in fit size.
pdfViewerControl1.PrinterSettings.PageSize = PdfViewerPrintSize.Fit;Set Custom Scale
// Prints the document with custom scaling.
pdfViewerControl1.PrinterSettings.PageSize = PdfViewerPrintSize.CustomScale;
// Scale percentage for page resizing. Default value is 100.
pdfViewerControl1.PrinterSettings.ScalePercentage = 120;---
Printing with Orientation Settings
Auto Portrait/Landscape (Default)
// Prints the document in auto orientation.
pdfViewerControl1.PrinterSettings.PageOrientation = PdfViewerPrintOrientation.Auto;Set Portrait
// Prints the document in portrait orientation.
pdfViewerControl1.PrinterSettings.PageOrientation = PdfViewerPrintOrientation.Portrait;Set Landscape
// Prints the document in landscape orientation.
pdfViewerControl1.PrinterSettings.PageOrientation = PdfViewerPrintOrientation.Landscape;---
Events
PdfViewerControl provides three events to notify the start, progress, and end of the printing operation.
| Event | Description |
|---|---|
BeginPrint | Fires before the first page prints. |
PrintProgress | Fires to report printing progress (current page and total page count). |
EndPrint | Fires after the last page prints, or if printing is canceled/fails. |
---
BeginPrint Event
pdfViewerControl1.BeginPrint += PdfViewerControl1_BeginPrint;
// Load the PDF file.
pdfViewerControl1.Load("../../Data/HTTP Succinctly.pdf");
// Print the file silently to the default printer.
pdfViewerControl1.Print(true);
private void PdfViewerControl1_BeginPrint(object sender, BeginPrintEventArgs e)
{
//Insert your code here
}---
PrintProgress Event
// Wire the PrintProgress event.
pdfViewerControl1.PrintProgress += PdfViewerControl1_PrintProgress;
// Load the PDF file.
pdfViewerControl1.Load("../../Data/HTTP Succinctly.pdf");
// Print the file silently to the default printer.
pdfViewerControl1.Print(true);
private void PdfViewerControl1_PrintProgress(object sender, PrintProgressEventArgs e)
{
//Find the page number which is currently printing.
int currentPage = e.PageIndex;
//Find the total number of pages present in the file.
int pageCount = e.PageCount;
//Insert your code here
}---
EndPrint Event
// Wire the EndPrint event.
pdfViewerControl1.EndPrint += PdfViewerControl1_EndPrint;
// Load the PDF file.
pdfViewerControl1.Load("../../Data/HTTP Succinctly.pdf");
// Print the file silently to the default printer.
pdfViewerControl1.Print(true);
private void PdfViewerControl1_EndPrint(object sender, EndPrintEventArgs e)
{
//Insert your code here
}---
Hide Print Status Dialog
// Hide the print status dialog.
pdfViewerControl1.PrinterSettings.ShowPrintStatusDialog = false;---
````markdown
Saving PDF Files in WinForms PdfViewer
Overview
The Save feature in PdfViewerControl allows you to keep the file up to date with any modifications and prevent work from being lost by saving the file to local disk.
---
Programmatically Save the Loaded PDF Document
// Save the loaded document using the LoadedDocument object.
pdfViewerControl1.LoadedDocument.Save("../../Data/SavedFile.pdf");---
Events
PdfViewerControl provides two events to notify the start and end of the save operation.
| Event | Description |
|---|---|
BeginSave | Fires before the save operation starts. Allows cancelling via BeginSaveEventArgs.Cancel. |
EndSave | Fires after the save operation completes. |
---
BeginSave Event
// Wire the BeginSave event.
pdfViewerControl1.BeginSave += PdfViewerControl1_BeginSave;
// Load the PDF file.
pdfViewerControl1.Load("../../Data/HTTP Succinctly.pdf");
private void PdfViewerControl1_BeginSave(object sender, BeginSaveEventArgs e)
{
//Insert your code here
}---
EndSave Event
// Wire the EndSave event.
pdfViewerControl1.EndSave += PdfViewerControl1_EndSave;
// Load the PDF file.
pdfViewerControl1.Load("../../Data/HTTP Succinctly.pdf");
private void PdfViewerControl1_EndSave(object sender, EndSaveEventArgs e)
{
//Insert your code here
}---
Searching Text in WinForms PDF Viewer
Search Next Instance of a Text
Search and highlight the next instance of a text using PdfViewerControl:
// search next instance of a term "time"
if (!string.IsNullOrEmpty("time"))
pdfViewerControl.SearchNextText("time");Using PdfDocumentView:
// search next instance of a term "time"
if (!string.IsNullOrEmpty("time"))
pdfDocumentView.SearchNextText("time");---
Search Previous Instance of a Text
Search and highlight the previous instance of a text using PdfViewerControl:
// search previous instance of a term "time"
if (!string.IsNullOrEmpty("time"))
pdfViewerControl.SearchPreviousText("time");Using PdfDocumentView:
// search previous instance of a term "time"
if (!string.IsNullOrEmpty("time"))
pdfDocumentView.SearchPreviousText("time");---
Enable or Disable Highlighting All Searched Text Instances
// Disable highlighting all occurrences of the searched text (enabled by default)
pdfViewer.TextSearchSettings.HighlightAllInstance = false;---
Customize the Highlight Color of Found Text Instances
// Set color to highlight the current occurrence of the searched text
pdfViewer.TextSearchSettings.CurrentInstanceColor = Color.Red;
// Set color to highlight all other occurrences of the searched text
pdfViewer.TextSearchSettings.OtherInstanceColor = Color.Yellow;---
Find All Instances of a Text and Its Bounds
bool isMatchFound;
Dictionary<int, List<RectangleF>> textSearch = new Dictionary<int, List<RectangleF>>();
isMatchFound = pdfViewerControl1.FindText("targetText", out textSearch);---
Find the Total Number of Instances of a Text
Using PdfViewerControl:
Dictionary<int, List<RectangleF>> matchedTextDetails = new Dictionary<int, List<RectangleF>>();
int totalInstances = 0;
pdfViewerControl.FindText("time", out matchedTextDetails);
foreach (KeyValuePair<int, List<RectangleF>> matchedText in matchedTextDetails)
{
totalInstances += matchedText.Value.Count;
}Using PdfDocumentView:
Dictionary<int, List<RectangleF>> matchedTextDetails = new Dictionary<int, List<RectangleF>>();
int totalInstances = 0;
pdfDocumentView.FindText("time", out matchedTextDetails);
foreach (KeyValuePair<int, List<RectangleF>> matchedText in matchedTextDetails)
{
totalInstances += matchedText.Value.Count;
}Working with Themes
PDF Viewer supports various built-in themes to customize the default appearance of the PdfViewerControl using its ThemeName property.
Note: To use the Office2019Colorful or HighContrastBlack themes, install the corresponding NuGet packages:
Syncfusion.Office2019Theme.WinForms and Syncfusion.HighContrastTheme.WinForms. Other Office2016 themes do not require additional assemblies. ---
Apply Office 2016 Theme
Supported themes: Office2016Colorful, Office2016Black, Office2016DarkGray, Office2016White.
pdfViewerControl1.ThemeName = "Office2016DarkGray";---
Apply Office 2019 Theme
// In Program.cs Main() method — load the assembly before Application.Run()
SkinManager.LoadAssembly(typeof(Syncfusion.WinForms.Themes.Office2019Theme).Assembly);pdfViewerControl1.ThemeName = "Office2019Colorful";---
Apply High Contrast Theme
// In Program.cs Main() method — load the assembly before Application.Run()
SkinManager.LoadAssembly(typeof(Syncfusion.WinForms.Themes.HighContrastTheme).Assembly);pdfViewerControl1.ThemeName = "HighContrastBlack";---
Reset to Default Theme
pdfViewerControl1.ThemeName = "Default";Toolbar Buttons: Hide or Disable
The WinForms PDF Viewer provides a ToolbarSettings API that allows you to access and manage toolbar buttons. To hide a specific button, use the IsVisible property associated with that button. Setting IsVisible to false hides the button from the toolbar.
The following code snippet demonstrates how to hide the Open and Save buttons in the WinForms PDF Viewer control.
// Load the document into PdfViewer control
pdfviewerControl.Load("Input.pdf");
// Change the visibility of the Open and Save buttons
pdfviewerControl.ToolbarSettings.OpenButton.IsVisible = false;
pdfViewerControl1.ToolbarSettings.SaveButton.IsVisible = false;
pdfViewerControl1.ToolbarSettings.ZoomInButton.IsVisible = false;
pdfViewerControl1.ToolbarSettings.ZoomOutButton.IsVisible = false;
pdfViewerControl1.ToolbarSettings.PanButton.IsVisible = false;
pdfViewerControl1.ToolbarSettings.PrintButton.IsVisible = false;View the PDF Stream in Viewer
PDF files as stream can be viewed in Essential® PdfViewerControl using the overload available in the Load method.
FileStream stream = new FileStream("Sample.pdf", FileMode.Open);
// Initialize PDF Viewer
PdfViewerControl pdfViewerControl1 = new PdfViewerControl();
// Load the PDF
pdfViewerControl1.Load(stream);Getting Started with WinForms PdfViewer
Required Namespace
using Syncfusion.Windows.Forms.PdfViewer;---
Adding PdfViewerControl to a Form
Manually in Code
// Initializing the PdfViewerControl
PdfViewerControl pdfViewerControl1 = new PdfViewerControl();
// Add PdfViewerControl to the Form
Controls.Add(pdfViewerControl1);
// Dock the control to fill the form
pdfViewerControl1.Dock = DockStyle.Fill;
// Loading the document in the PdfViewerControl
pdfViewerControl1.Load("Sample.pdf");---
Adding PdfDocumentView to a Form
PdfDocumentView allows viewing PDF files without a toolbar. All other features are similar to PdfViewerControl.
Manually in Code
// Initializing the PdfDocumentView
PdfDocumentView pdfDocumentView1 = new PdfDocumentView();
// Loading the document
pdfDocumentView1.Load("Sample.pdf");
// Add PdfDocumentView to the Form
Controls.Add(pdfDocumentView1);---
Key Differences
| Feature | PdfViewerControl | PdfDocumentView |
|---|---|---|
| Built-in Toolbar | ✅ Yes | ❌ No |
| Page Navigation | ✅ Yes | ✅ Yes |
| Zoom Controls | ✅ Yes (toolbar) | Manual only |
| Use case | Full-featured viewer UI | Embedded/custom UI |
---