This tutorial will show you how to integrate DocuVieware Lite™ in a newly created C# ASP.NET Web Forms project.
Each time there is a difference between C# and VB.NET, both syntaxes will be provided.
DocuVieware Lite™ requires .NET Framework 4.5 or above.
The screenshots have been taken using GdPicture.NET™ 12, it may differ from the current release.
1. Empty project creation
2. Adding mandatory referencies
3. Setting up licensing
4. DocuVieware Lite™ integration
5. Loading a document
Empty project creation
Start with the File > New > Project... menu, then choose Web > ASP.NET Web Application. In this tutorial you will be working on DocuViewareDemo which is new ASP.NET 4.5 Web Forms project.
Depending on your Visual Studio version, you may not already have a Global.asax file in your project. In that case you want to add it too. This is also done through the Add > New item... menu, then select Global Application Class in the list.
Here is the structure obtained:
Now that the project structure is complete, the next step will be to add project references.
Adding mandatory referencies
The references you need to add are:
- GdPicture.NET.12.WEB.DocuVieware.dll found in [INSTALLATION FOLDER]\Redist\DocuVieware\
- System.Web.Http from the Microsoft ASP.NET Web API
You may not have the mandatory System.Web.Http namespace directly available on your system, this is because it requires Microsoft ASP.NET Web API to be installed first.
To do this, simply run the following command in the Package Manager Console (from the Tools menu, select NuGet Package Manager and then click Package Manager Console):
PM> Install-Package Microsoft.AspNet.WebApi
You might also need to add Newtonsoft JSON, even though it should be already in the references but the version is outdated and it will most probably cause an error at runtime.
To do this, still in the Package Manager Console (from the Tools menu, select NuGet Package Manager and then click Package Manager Console), run the following command:
PM> Install-Package Newtonsoft.JSON
The project references should look like this:
You also need to take care of extra libraries that are mandatory for deployment, those files are found in [INSTALLATION FOLDER]\Redist\
- GdPicture.NET.12.filters.dll (for a 32-bit execution)
- GdPicture.NET.12.image.gdimgplug.dll (for a 32-bit execution)
- GdPicture.NET.12.jbig2.encoder.dll (for a 32-bit execution)
- GdPicture.NET.12.filters.64.dll (for a 64-bit execution)
- GdPicture.NET.12.image.gdimgplug.64.dll (for a 64-bit execution)
- GdPicture.NET.12.jbig2.encoder.64.dll (for a 64-bit execution)
They need to be added to the project (using the Add > Existing item... menu) and once done, the "Build Action" property should be set to "Content" and the "Copy to Output Directory" property should set to "Copy always" for each file.
Setting up licensing
You need to go into Global.asax.cs, add a mandatory import and handle the DocuVieware Lite™ configuration and licensing part as well.
To properly unlock DocuVieware Lite™ you are going to add a call to the RegisterKEY method in the Application_Start event.
You need to replace "XXXX" by your actual license key.
Here is what the two files should look like at this point.
Step 1 : Add the assembly registration to the page so you can add a DocuVieware Lite™ control on it. Here is the ASP.NET code you need to add to do this:
Step 2 : Add and set the DocuVieware1 object properties in the Default.aspx page, after some clean-up, like this:
DocuVieware Lite™ will now have a fixed size of 1000x800 pixels.
Here is how the page source code looks like in the end:
That’s it! You can start the project and load documents in your brand new DocuVieware™.
Loading a document
Loading a document into your newly created DocuVieware Lite™ page is easy, you simply need to load your document into a Stream object and call the LoadFromStream method from the DocuVieware class.
Step 1: In the page code behind, create a stream and load your document in it.
Step 2: Call the LoadFromStream method in the Page_Load part so the document is displayed when the page is loaded.