Guide for C#
Core Document Formats
HTML5 Web Viewer
Additional Features

C# PDF - Create Online PDF Viewer in C#.NET

C#.NET Web-based PDF Document Viewer & Reader

Visual C#
Home > .NET Imaging SDK > C# > Create Online PDF Web Viewer
If this is your first time to use our DocImageSDK, we strongly suggest you reading How to Start first!

C#.NET PDF document HTML5 web viewer control from RasterEdge DocImage SDK for .NET is a professional and user-friendly PDF document viewing and annotating solution. This online web-based PDF document viewer and reader control can be easily and stably integrated into C#.NET web imaging application and deployed on ASP.NET web server platform.
C#.NET developers can directly run online web-based PDF document viewer & reader demo with commomly used modern web browsers. Or, you can use .NET web document viewer control to generate an online HTML5 PDF document viewer & reader and read, annotate or redact PDF document file in web browsers.
This tutorial article for how to create HTML5 PDF document web viewer and reader using C#.NET is divided into following four parts.
  • Key features of C#.NET online web PDF document viewer & reader
  • Installation requirement of C#.NET ASP.NET web PDF document viewer control
  • How to create online web PDF document viewer & reader using C#.NET code
  • C#.NET PDF document online web viewer control FAQs
C# HTML5 PDF Viewer & Reader Library Features
  • Modern C#.NET PDF document viewer control used for ASP.NET web server application
  • Professional PDF document web viewer, written in ASP.NET and C#
  • Instantly generate thumbnail or outline preview using latest HTML5 technology, based on JavaScript
  • Provide high fidelity PDF viewing in web application using C# without installing other software
  • Annotate and redact PDF document in web browser using C#.NET code
  • Easy to convert and print office document to PDF using within C#.NET Web Document Viewer
Web PDF Viewer Installation Requirement
In order to make RasterEdge PDF ASP.NET web viewer & reader control run perfectly in your own C#.NET class application, please make sure you have installed all the following components into your C#.NET developing environment. Please note that, our testing environment for this C#.NET PDF online web viewer & reader control is in Visual Studio 2005.
  • Microsoft Visual Studio 2005/2008/2010/2012/2013
  • .NET Framework 2.0 or greater versions
  • Windows operating system XP or above
How to Create Web PDF Viewer in C#
In this part, C# developers will find step-by-step guidance on how to create a PDF document viewer in ASP.NET web applications.
  1. In Visual Studio 2005, create an ASP.NET website;
  2. Add RasterEdge.Imaging.WebViewer.dll in package "bin" folder to your C#.NET project reference (note: dependencies will automatically be included in your web project);
  3. Then, you need to modify the configuration file by copying the content of Web.config in download package to your web configuration file which is supposed to be Web.config.
  4. Later, copy .NET Web Document Viewer resources (RasterEdge_Imaging_Files, RasterEdge_Demo_Docs and RasterEdge_Cache) to your C#.NET web project folder for PDF document viewing and manipulating.
  5. If you want to embed C#.NET Web Viewer Control into your web page to view PDF file, please create a new Web Form (Default.aspx);
  6. Now, directly copy the following Visual C# codes to Default.aspx, which helps to create C#.NET web PDF document viewer objects and initialize the viewer.
<link href="RasterEdge_Imaging_Files/RasterEdge.css" rel="stylesheet"type="text/css"/>
<script src="RasterEdge_Imaging_Files/RasterEdge.js" type="text/javascript"></script>
<script src="RasterEdge_Imaging_Files/CreateViewerToolBar.js" type="text/javascript"></script>
<script type="text/javascript">
_fid = "<%=fid %>";
_viewer = new RasterEdgeViewer({
_serverUrl: "/RasterEdge_Imaging_Files/WebHandler.ashx",
//0 represent png, 1 represent svg
_pdfViewer: 1,
_wordViewer: 1,
_excelViewer:1,

//Set width and height of the webViewer(pixel)
_viewerWidth: 1024,
_viewerHeight: 730,
});

//define annotation style
//annotation style
//Color:Hexadecimal color can be used
//Transparency:1 on behalf of saturated, 0 represents completely transparent
//TextStyle:italic/oblique/normal
TextAnnoStyle = new AnnoStyle({FillColor: "White", ShowedText: "double click to edit", TextColor: "Black", TextFont: "Arial", TextSize: 12, TextStyle :"normal"});
FreehandAnnoStyle = new AnnoStyle({OutLineColor: "Red", OutLineWidth: 5.0});
HighlightAnnoStyle = new AnnoStyle({FillColor: "Yellow"});
RectangleAnnoStyle = new AnnoStyle({OutLineColor: "Black", OutLineWidth: 3.0});
FilledRectangleAnnoStyle = new AnnoStyle({OutLineColor: "Black", OutLineWidth: 3.0, FillColor: "Black", Transparency: 1});
EllipseAnnoStyle = new AnnoStyle({FillColor: "Orange"});
RubberStampAnnoStyle = new AnnoStyle({OutLineColor: "Tomato", OutLineWidth: 3.0, FillColor: "Red", ShowedText: "Good", TextColor: "Black", TextFont: "Arial", TextSize: 12, TextStyle: "Italic"});
PolygonLinesAnnoStyle = new AnnoStyle({OutLineColor: "Red", OutLineWidth: 5.0});
PolygonAnnoStyle = new AnnoStyle({OutLineColor: "OrangeRed", OutLineWidth: 3.0, FillColor: "OrangeRed"});
LineAnnoStyle = new AnnoStyle({OutLineColor: "Red", OutLineWidth: 5.0});
ArrowAnnoStyle = new AnnoStyle({OutLineColor: "Red", OutLineWidth: 5.0, FillColor: "Red",Transparency:0.8});

//Set whether the toolbar shows the corresponding icon(true or false)
//You can set the item including:_toolbar/_fileToolbar/_annoToolbar/_fullToolbar
//_uploadToolbar/_printToolbar/_saveToolbar/_convertToolbar //_textToolbar/_freehandToolbar/_arrowToolbar/_lineToolbar/_polygonLinesToolbar/_filledRectangleToolbar/_rectangleToolbar/_highlightToolbar/_ellipseToolbar/_polygonToolbar/_rubberStampToolbar/_deleteToolbar
</script>
  1. The next step is to design the viewing area for loaded web PDF document and this can be achieved by the following code;
<div class="re_container">
<div class = "re_func_toolbar"></div>
<div id="_tblImgs"class="re_content" style="width:100%">
<div class="RE_WebViewer" id="REWebViewer1"></div>
</div>
</div>
  1. To control certain functions in your C#.NET web PDF viewing application, like PDF opening and saving, you may use and copy the following codes in Default.aspx.cs (code behind for Default.aspx )
public string mode;
public string fid;
protected void Page_Load(object sender, EventArgs e)
{
string command = Request.Form["RECommand"];
if (command == null || command.Equals(""))
{
WorkRegistry.Reset();
LoadFileFromUrl();
}
else if (command.Equals("OpenFile"))
{
LoadFileFromUpload();
}
else if (command.Equals("SaveFile"))
{
SaveFile();
}
}

public void LoadFileFromUrl()
{
string file = Request.QueryString["file"];
if (file != null &&file != "")
{
file = file.Trim();
string initFilePath = file;
string projectName = System.Web.HttpContext.Current.Request.PhysicalApplicationPath.Replace("\\", "/");
string path = projectName + "
/RasterEdge_Demo_Docs/" + initFilePath;
if (File.Exists(path))
{
fid = REDocumentControl.GenerateId();
string result = LoadFile("
RasterEdge_Demo_Docs" + initFilePath, fid);
if (result != "
")
this.RegisterStartupScript("
", "<script>alert('" + result + "');</script>");
}
}
}

public void LoadFileFromUpload()
{
string uploadFile = Request.Form["
uploadfile"];
string filename = "
/RasterEdge_Cache/" + uploadFile;
fid = Request.Form["
Fid"];
string result = LoadFile(filename, fid);
Response.Clear();
Response.Write(result);
Response.End();

//load document from stream
//REDocumentControl.LoadFile(Stream stream, fid);

//load document from array
//REDocumentControl.LoadFile(byte[] array, fid);
}

public void SaveFile()
{
string fileName = Request.Form["
saveFileName"];
string fid = Request.Form["
Fid"];
Response.Clear();
Response.Write(fileName);
Response.End();
}

private string LoadFile(string filename,string fid)
{
string result = "
";
try
{
REDocumentControl.LoadFile(filename, fid);
}
catch (Exceptionex)
{
result = ex.Message.ToString();
}
return result;
C# PDF ASP.NET Web Viewer FAQs
Q: Does your C#.NET PDF document web online viewer and reader support searching PDF content based on certain key word?
A: Sorry, the current version of this C#.NET PDF ASP.NET web viewer control doesn't support this function. But we will try to add the content searching functionality to the upcoming version.
More Tutorials!
Find more user guides with RasteEdge .NET Image SDK using Visual C# sample codings!


Recommend this to Google+