C# Developer Getting Started
Viscomsoft .NET PDF Viewer SDK |
C# Developer Getting Started |
1. Launch Visual Studio 2010 or another version of Visual Studio. Select Visual C#, Select Windows Form Application.
|
2. In the Solution Explorer, right-click References, and then click Add Reference.
3. Select Browse tab, Navigate to the extracted .NET PDF Viewer SDK for REDIST folder, open it, and then select Viscomsoft.PDFViewer.dll and ViscomsoftPDFCore.dll.
4. At the top of the Form1.cs file, add the following import statements to the top of the page
using Viscomsoft.PDFViewer;
5. The following code bit presents the pdf viewer sdk initialization:
public partial class Form1 : Form
{
private PDFView _pdfViewer = new PDFView();
public Form1()
{
InitializeComponent();
_pdfViewer.Canvas.Parent = this;
_pdfViewer.Canvas.Location = new Point(0, 24);
_pdfViewer.ContinuousPages = true;
//let scrolling the pdf file using the mouse wheel
_pdfViewer.Canvas.Select();
}
6. Load the PDF file.
private void Form1_Load(object sender, EventArgs e)
{
PDFDocument doc = new PDFDocument();
if (doc.open("c:\\yourfile.pdf"))
{
_pdfViewer.Document = doc;
_pdfViewer.gotoPage(1);
}
else
doc.close();
}
7. Now that you can loaded a PDF file, but the display area is very small. so add following code to the Form1.cs file
private void resizeCanvas()
{
_pdfViewer.Canvas.Size = new Size(this.ClientSize.Width, this.ClientSize.Height - 24);
}
8. add resizeCanvas() in Form1_Load event
private void Form1_Load(object sender, EventArgs e)
{
resizeCanvas();
PDFDocument doc = new PDFDocument();
if (doc.open("c:\\yourfile.pdf"))
{
_pdfViewer.Document = doc;
_pdfViewer.gotoPage(1);
}
else
doc.close();
}
9. Select the form in the designer then go to the Properties Window and find the Events button
13. Select Resize event and double click it.
10. add resizeCanvas() in Form1_Resize event
private void Form1_Resize(object sender, EventArgs e)
{
resizeCanvas();
}
11. Press F5 to Run the project, now it can loading and display the PDF document.