Q:
How can I drag & drop PDF viewer control to my windows form?
Alternatively what are the steps I need to take to add PDF View class
to my windows form?
-----
To make PDFView class more versatile it is derived from Control
instead of UserControl (which is a derived from Control). Still adding
the control is quite easy. For a simplest example of using PDFView
class, please see 'PDFViewSample' sample project (http://
www.pdftron.com/net/samplecode/PDFViewSimple.cs).
- First you will need to add a reference to PDFNet11.DLL.
To add PDFView control add the following lines to your WinForms file:
// Add the following lines to 'imports' section
using pdftron;
using pdftron.PDF;
using pdftron.Filters;
using pdftron.Common;
using PDFTRON.SDF;
...public class MainForm : System.Windows.Forms.Form
...{
......
// Add the following private variables in your forms class:
private PDFView _pdfview;
private PDFDoc _pdfdoc;
// Add the following initialization code in win form constructor:
public MainForm() {
InitializeComponent();
_pdfview = new PDFView();
_pdfview.Location = new Point(0, 0);
_pdfview.Dock = System.Windows.Forms.DockStyle.Fill;
Controls.Add(_pdfview);
}
// Add the following code to the main entry point for your application
static void Main() {
PDFNet.Initialize();
// Make sure that 'pdfnet.res' from 'PDFNet/resources' is copied to
'c:/MyApp'.
// For more info, please see http://www.pdftron.com/net/faq.html#pdfnet_res
bool found = PDFNet.SetResourcesPath("c:/MyApp/pdfnet.res");
if (!found) MessageBox.Show("PDFNet resource file 'pdfnet.res' was
not found.\nSome files may not render properly.", "Error");
}
// Add the following method and use it to open PDF documents.
public bool OpenPDF(String filename) {
try {
_pdfdoc = new PDFDoc(filename);
_pdfdoc.InitSecurityHandler();
_pdfview.SetDoc(_pdfdoc);
return true;
catch(PDFNetException ex) {
MessageBox.Show(ex.Message);
}
catch(Exception ex) {
MessageBox.Show(ex.ToString());
}
return false;
}