Winnovative PDF Viewer Control for Windows Forms v7.1
Winnovative PDF Viewer Control for Windows Forms v7.1
The PDF Viewer control for Windows Forms can be linked into any Windows Forms and WPF application to add PDF visualization and manipulation capabilities to your application. With Winnovative PDF Viewer for Windows Forms you can display a PDF from a specified file, navigate the document, navigate to a page inside the PDF document, print PDF documents, control PDF security options to disable content copying or printing. The integration with your Windows Forms or WPF applications is extremely easy. The free Adobe Reader is required on the machine where the control is used.
Features
.NET user control and C# samples
Can be used in Windows Forms and WPF applications
Display PDF documents from files
Display PDF documents from streams
Navigate and print PDF documents
Navigate to a PDF page programatically
Set viewer zoom level programatically
Set page layout to one or more columns
Display password protected PDF documents
Show or hide viewer toolbars
Show or hide viewer scroll bars
Show or hide viewer navigation panel
Disable PDF document printing or copying
Royalty free development libraries and samples
Support for .NET 4.0 framework and later
Documentation and C# samples for all the features
Code Sample for PDF Viewer for Windows Forms
The code below was taken from the PDF Viewer for Windows Forms Demo demo application available for download in the product package. In this sample an instance of the PdfViewer class is used to display a PDF document in a Windows Forms application.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
// The PDF Viewer namespace
using PdfViewer4WinNet;
namespace PdfViewerWinNetDemo
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private void MainForm_Load(object sender, EventArgs e)
{
LoadPageLayoutModes();
LoadDocumentDisplayModes();
LoadPageFitModes();
LoadViewerPreferences();
formTooltip.SetToolTip(btnOpenFile, "Open a file in viewer");
formTooltip.SetToolTip(btnPrintDialog, "Opens the print dialog");
string demoFilePath = System.IO.Path.Combine(Application.StartupPath, "WinnovativeSoftware.pdf");
pdfViewerControl.LicenseKey = "nBIDEwIFEwICAgITBx0DEwACHQIBHQoKCgo=";
if (System.IO.File.Exists(demoFilePath))
{
// load PDF from file
pdfViewerControl.LoadFile(demoFilePath);
lblPageCount.Text = pdfViewerControl.PageCount > 0 ? String.Format("Page Count: {0}",
pdfViewerControl.PageCount) : String.Empty;
}
}
private void LoadPageLayoutModes()
{
string[] pageLayoutModes = Enum.GetNames(typeof(PageLayoutMode));
ddlPageLayout.DataSource = pageLayoutModes;
ddlPageLayout.SelectedItem = PageLayoutMode.NotSet.ToString();
}
private void LoadDocumentDisplayModes()
{
string[] documentDisplayModes = Enum.GetNames(typeof(DocumentDisplayMode));
ddlDocumentDisplayMode.DataSource = documentDisplayModes;
ddlDocumentDisplayMode.SelectedItem = DocumentDisplayMode.NotSet.ToString();
}
private void LoadPageFitModes()
{
string[] pageFitModes = Enum.GetNames(typeof(PageFitMode));
ddlPageFitMode.DataSource = pageFitModes;
ddlPageFitMode.SelectedItem = PageFitMode.NotSet.ToString();
}
private void LoadViewerPreferences()
{
cbShowNavigationPanel.Checked = pdfViewerControl.ShowNavigationPanel;
}
private void btnOpenFile_Click(object sender, EventArgs e)
{
OpenFileDialog fd = new OpenFileDialog();
if (fd.ShowDialog() == DialogResult.OK)
{
using (FileStream pdfFileStream = new FileStream(fd.FileName, FileMode.Open, FileAccess.Read))
{
// load PDF from stream
pdfViewerControl.LoadStream(pdfFileStream);
lblPageCount.Text = pdfViewerControl.PageCount > 0 ? String.Format("Page Count: {0}",
pdfViewerControl.PageCount) : String.Empty;
}
}
}
private void btnPrintDialog_Click(object sender, EventArgs e)
{
pdfViewerControl.PrintWithDialog();
}
private void btnZoom_Click(object sender, EventArgs e)
{
SetZoomDialog zd = new SetZoomDialog();
zd.Percentage = 100;
if (zd.ShowDialog() == DialogResult.OK)
{
pdfViewerControl.SetZoom(zd.Percentage);
}
}
private void cbShowToolbar_CheckedChanged(object sender, EventArgs e)
{
pdfViewerControl.SetShowToolbar(cbShowToolbar.Checked);
}
private void btnSetPageNumber_Click(object sender, EventArgs e)
{
SetPageNumberDialog pnd = new SetPageNumberDialog(pdfViewerControl.PageCount);
pnd.PageNumber = 1;
if (pnd.ShowDialog() == DialogResult.OK)
{
pdfViewerControl.SetCurrentPage(pnd.PageNumber);
}
}
private void btnFirstPage_Click(object sender, EventArgs e)
{
pdfViewerControl.GoToFirstPage();
}
private void btnLastPage_Click(object sender, EventArgs e)
{
pdfViewerControl.GoToLastPage();
}
private void btnPreviousPage_Click(object sender, EventArgs e)
{
pdfViewerControl.GoToPreviousPage();
}
private void btnNextPage_Click(object sender, EventArgs e)
{
pdfViewerControl.GoToNextPage();
}
private void btnBack_Click(object sender, EventArgs e)
{
pdfViewerControl.GoBackwardStack();
}
private void btnForward_Click(object sender, EventArgs e)
{
pdfViewerControl.GoForwardStack();
}
private void ddlPageLayout_SelectedIndexChanged(object sender, EventArgs e)
{
pdfViewerControl.PageLayoutMode = (PageLayoutMode)Enum.Parse(typeof(PageLayoutMode),
ddlPageLayout.SelectedItem.ToString());
if (pdfViewerControl.PageLayoutMode == PageLayoutMode.NotSet)
pdfViewerControl.ReloadPdfDocument();
}
private void ddlPageFitMode_SelectedIndexChanged(object sender, EventArgs e)
{
pdfViewerControl.PageFitMode = (PageFitMode)Enum.Parse(typeof(PageFitMode),
ddlPageFitMode.SelectedItem.ToString());
if (pdfViewerControl.PageFitMode == PageFitMode.NotSet)
pdfViewerControl.ReloadPdfDocument();
}
private void ddlDocumentDisplayMode_SelectedIndexChanged(object sender, EventArgs e)
{
pdfViewerControl.DocumentDisplayMode = (DocumentDisplayMode)Enum.Parse(typeof(DocumentDisplayMode),
ddlDocumentDisplayMode.SelectedItem.ToString());
if (pdfViewerControl.DocumentDisplayMode == DocumentDisplayMode.NotSet)
pdfViewerControl.ReloadPdfDocument();
}
private void cbShowScrollbar_CheckedChanged(object sender, EventArgs e)
{
pdfViewerControl.ShowScrollbars = cbShowScrollbar.Checked;
}
private void cbShowNavigationPanel_MouseClick(object sender, MouseEventArgs e)
{
cbShowNavigationPanel.Checked = !cbShowNavigationPanel.Checked;
MessageBox.Show("The left navigation panel visibility can be changed by ShowNavigationPanel
property only before loading the control. For example you can set this property in the Properties
windows from Visual Studio before running the demo application.");
}
private void btnApplySecurityOptions_Click(object sender, EventArgs e)
{
pdfViewerControl.PdfSecurityOptions.CanPrint = cbAllowPrint.Checked;
pdfViewerControl.PdfSecurityOptions.CanCopyContent = cbAllowContentCopy.Checked;
pdfViewerControl.PdfSecurityOptions.CanFillFormFields = cbAllowFormFilling.Checked;
pdfViewerControl.PdfSecurityOptions.CanEditContent = cbAllowContentEdit.Checked;
pdfViewerControl.PdfSecurityOptions.CanEditAnnotations = cbAllowEditAnnotation.Checked;
pdfViewerControl.PdfSecurityOptions.CanAssembleDocument = cbAllowAssemble.Checked;
pdfViewerControl.PdfSecurityOptions.UserPassword = textBoxUserPassword.Text.Trim();
pdfViewerControl.ReloadPdfDocument();
}
private void cbAllowFormFilling_CheckedChanged(object sender, EventArgs e)
{
if (!cbAllowFormFilling.Checked)
{
cbAllowContentEdit.Checked = false;
cbAllowEditAnnotation.Checked = false;
}
}
}
}
Only for V.I.P
Warning! You are not allowed to view this text.