How to C#: Quick to Start Using XDoc.Windows Viewer
To Have a Quick Evaluation of XDoc.Windows Viewer in Visual C# Console Application
As a leading professional third-party SDK supplier in the field of image and document management, RasterEdge has always been devoted to providing various effective and fully-functional imaging solutions for developers who are working on different .NET developing applications.
Related .net document control helps:
asp.net open pdf password using c#:
ASP.NET PDF Password Edit Control: online add, remove, update PDF file open password using C#
c# asp.net sharepoint document viewer: ASP.NET SharePoint Document Viewer: view, annotate, redact documents in SharePoint
c# asp.net powerpoint document viewer: ASP.NET PowerPoint Document Viewer Control: view pptx files online in C# using ASP.NET
asp.net mvc pdf editor using c#: ASP.NET MVC PDF Editor: view, annotate, redact, edit PDF document in C# ASP.NET MVC
c# asp.net excel document viewer: ASP.NET Excel Document Viewer in C# Control: view office excel files online in ASP.NET web applications
c# asp.net dicom document viewer: ASP.NET Dicom Document Viewer Control: view, annotate dicom imaging files online in ASP.NET
c# asp.net pdf document viewer: ASP.NET PDF Document Viewer in C#: view, annotate, redact Adobe PDF files online in ASP.NET
This C#.NET image and document viewer toolkit, RasterEdge XDoc.Windows Viewer SDK for .NET is one of the most strongly-featured and mature document imaging library toolkits on the market, which is designed to help developers implement image and document scan, annotating, print, conversion tasks in their C#.NET applications.
Using this C#.NET image and document processor control, you can easily and quickly complete image and document loading, conversion, annotation and more in any type of a 32-bit or 64-bit .NET application.
As you know, there are various reliable image and document processing features that can be implemented in C#.NET programming. And you may want to have a quick testing on RasterEdge XDoc.Windows Viewer after downloading its free trial package. To meet your requirement, on this quick to start page, we will tell how to create a C# console application.
Create a C# WinForm Application
Open Visual Studio and click "New" from toolbar. Note, Visual Studio 2005 and above versions are available;
Choose "C# Language" and "Windows Application" respectively to create a project.
Add necessary references to your C#.NET project. Right-click the project and select "Add Reference..." to locate and add the following DLLs as project references;
RasterEdge.Imaging.Annotation.dll
RasterEdge.Imaging.Basic.Codec.dll
RasterEdge.Imaging.Basic.dll
RasterEdge.Imaging.DICOM.dll
RasterEdge.Imaging.Drawing.dll
RasterEdge.Imaging.Font.dll
RasterEdge.Imaging.JBIG2.dll
RasterEdge.Imaging.JPEG2000.dll
RasterEdge.Imaging.Processing.dll
RasterEdge.XDoc.Excel.dll
RasterEdge.XDoc.Office.Inner.Common.dll
RasterEdge.XDoc.Office.Inner.Office03.dll
RasterEdge.XDoc.PDF.dll
RasterEdge.XDoc.PowerPoint.dll
RasterEdge.XDoc.TIFF.dll
RasterEdge.XDoc.WindowsViewer.dll
RasterEdge.XDoc.Word.dll
RasterEdge.XImage.AdvancedCleanup.Core.dll
RasterEdge.XImage.BarcodeScanner.dll
RasterEdge.XImage.OCR.dll
RasterEdge.XImage.OCR.Tesseract.dll
RasterEdge.XImage.Raster.Core.dll
RasterEdge.XImage.Raster.dll
Use corresponding namespaces;
using RasterEdge.XDoc.WindowsViewer;
Note: When you get the error "Could not load file or assembly 'RasterEdge.Imaging.Basic' or any other assembly or one of its dependencies. An attempt to load a program with an incorrect format", please check your configure as follows:
If you are using x64 libraries/dlls, Right click the project -> Properties -> Build -> Platform target: x64.
If using x86, the platform target should be x86.
How to Create and Open a Windows Viewer in C#.NET
The following demo code will show you how to create a windows viewer quickly.
private WinViewer winViewer;
public Form1()
{
InitializeComponent();
// Set the windows viewer display settings.
ViewerOptions option = new ViewerOptions();
option.ShowThumb = true; //Display thumbnail or not, true will display.
option.ThumbDock = ThumbDock.Left; //Set the location of Thumbnail. (Left, Right, Top, Bottom)
option.SizeByDocViewer = false; //Spread DocViewer to WinViewer or not, true will not spread.
option.ShowNavigationBar = true; //Display the navigation or not. It will contains change page to display (first, prev, next, last, zoom in/out).
option.DocViewerWidth = 800;
option.DocViewerHeight = 800;
option.ThumbViewerHeight = 800;
//Create a windows viewer according to the viewer settings.
winViewer = new WinViewer(option);
winViewer.Width = 1000;
winViewer.Height = 800;
// Add the winViewer to your own form through panel.
this.panel1.Controls.Add(winViewer);
}
//Design a button to open file.
private void Open_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "(*.*)|*.*";
ofd.Multiselect = false;
if (ofd.ShowDialog() == DialogResult.OK)
{
this.winViewer.LoadFromFile(ofd.FileName);
}
}
|
How to Add a Navigation for Windows Viewer in C#.NET
After creating a windows viewer, if you want to add a button to display another page, you can try as follows.
Related APIs (WinViewer.cs)
UpPage(): Display previous page.
DownPage(): Display next page.
GoToPage(int showIndex): Display specific page.
//Design a button to display previous page.
private void prev_Click(object sender, EventArgs e)
{
this.winViewer.UpPage();
}
//Design a button to display next page.
private void next_Click(object sender, EventArgs e)
{
this.winViewer.DownPage();
}
//Design a button to display first page.
private void next_Click(object sender, EventArgs e)
{
this.winViewer.GoToPage(1);
}
//Design a button to display last page.
private void next_Click(object sender, EventArgs e)
{
this.winViewer.GoToPage(winViewer.GetTotalPageCount());
}
|
How to Add a Zoom Box for Windows Viewer in C#.NET
If you want to add a button to display page with specific zoom value, the following steps will be helpful.
Related APIs (WinViewer.cs)
ZoomIndexChange(int zoomIndex): Display page with specified zoom.
Valid Value
|
Zoom Value
|
Description
|
0
|
1200%
|
12 multiples of the original page size to display.
|
1
|
1000%
|
10 multiples of the original page size to display.
|
2
|
800%
|
8 multiples of the original page size to display.
|
3
|
600%
|
6 multiples of the original page size to display.
|
4
|
400%
|
4 multiples of the original page size to display.
|
5
|
300%
|
3 multiples of the original page size to display.
|
6
|
200%
|
2 multiples of the original page size to display.
|
7
|
150%
|
1.5 multiples of the original page size to display.
|
8
|
125%
|
1.25 multiples of the original page size to display.
|
9
|
100%
|
Original page size to display.
|
10
|
80%
|
In eighty percent of the origianl page size to display.
|
11
|
75%
|
In 75 percent of the origianl page size to display.
|
12
|
66.67%
|
In two-thirds of the origianl page size to display.
|
13
|
50%
|
In one-half of the origianl page size to display.
|
14
|
33.33%
|
In one-third of the origianl page size to display.
|
15
|
25%
|
In a quarter of the origianl page size to display.
|
16
|
18.5%
|
In 18.5 percent of the origianl page size to display.
|
17
|
Actual Size
|
Original page size to display.
|
18
|
Fit Page
|
The actual height of original page size to display.
|
19
|
Fit Width
|
The actual width of original page size to display.
|
//Design a button to display page with specified zoom value.
private void zoom_Click(object sender, EventArgs e)
{
this.winViewer.ZoomIndexChange(1);
}
|
How to Rotate Page on Windows Viewer in C#.NET
If you want to rotate page with specific degree to display, the following steps will be enough.
Related APIs (WinViewer.cs)
Rotate0(): Dispaly page as original direction.
Rotate90(): Display page with rotating degree.
Rotate180(): Display page bottom to up.
Rotate270(): Display page with rotating 270 deegree.
//Design a button to display page as original direction.
private void rotate0_Click(object sender, EventArgs e)
{
this.winViewer.Rotate0();
}
//Design a button to display page with rotating 90 degree.
private void rotate90_Click(object sender, EventArgs e)
{
this.winViewer.Rotate90();
}
//Design a button to display page bottom to up.
private void rotate180_Click(object sender, EventArgs e)
{
this.winViewer.Rotate180();
}
//Design a button to display page with rotating 270.
private void rotate270_Click(object sender, EventArgs e)
{
this.winViewer.Rotate270();
}
|
How to Annotate Document or Draw Annotation on Page in Windows Viewer in C#.NET
If you want to annotate page with various annotation, the following annotation types will work.
Related APIs (WinViewer.cs)
DrawHightLight(): .
DrawRectangle():
DrawFilledRectangle():
DrawEllipse():
DrawLine(): .
DrawRubbeStamp():
DrawFreehand():
DrawPolygon():
DrawPolygonLines():
DrawText():
//Design a button to draw highlight annotation on page.
private void highlight_Click(object sender, EventArgs e)
{
this.winViewer.DrawHightLight();
}
//Design a button to draw text comment .
private void drawText_Click(object sender, EventArgs e)
{
this.winViewer.DrawText();
}
//To add more annotation ......
//To save the annotations, it is necessary to call the method BurnAnnotation().
private void BurnAnnotation_Click(object sender, EventArgs e)
{
this.winViewer.BurnAnnotation();
}
//To save source file, it is necessary to call the method SaveFile(string filePath).
private void SaveFile_Click(object sender, EventArgs e)
{
this.winViewer.SaveFile(@"");
}
|