- Home
- Products For Home & Business
- Tools For Developers
- Download
- Purchase
- Support
- Company
QUESTIONS OR COMMENTS ABOUT PRODUCTS? WRITE US AT SUPPORT@BYTESCOUT.COM OR USE THIS FORM
QUESTIONS OR COMMENTS ABOUT PRODUCTS? WRITE US AT SUPPORT@BYTESCOUT.COM OR USE THIS FORM
You can download the source code of this example here: pdfdocscout_registration_free_in_asp_net2.zip
This example provides a sample code to demonstrate how to use PDFDocScout in ASP.NET 2 web-projects without installing PDFDoc Scout on web-server (using registration-free mode, this sample is based on an example from Maze Computers )
Create a new web-site project in Visual Studio

Enter name of new web-site and click OK

Right-click on project in Solution Explorer and select "Add Reference" command in popup menu invoked:
Browse for "ASPManifestHelpers.dll" (you can find it in ZIP with sample code) and select it and click OK to add reference:

Then create folder named "PDFDocScout.assembly" by right-clicking on project in Solution Explorer and selecting "New Folder" command:

Type name of the folder "PDFDocScout.assembly" and click OK to create a folder

Now you should add the following files into created folder:
PDFDocScout.dll
PDFDocScout.assembly.manifest
If you have DEMO version and so have PDFDocScoutDemo.DLL file then rename it to the PDFDocScout.DLL
To add files right-click on project in Solution Explorer and select "Add Existing Item" command:

File selection dialog will appear - select PDFDocScout.dll and PDFDocScout.assembly.manifest files (hold CTRL and click on each file to select) and click "Add" button to add files to the project:

Now add webapp.manifest file to the project: right-click on project in Solution Explorer and select "Add Existing Item..." command:

File selection dialog will appear. Select webapp.manifest file and click "Add":

Start project by clicking "Start Debugging" button as shown below:
Visual Studio will suuggest to add new Web.config file. Answer Yes as shown below:

Close Internet Explorer window and switch back to Visual Studio
Web.config file will appear in the list of project files:
Double click on web.config file

Visual Studio will open editor with Web.config file in it.
Add the following lines after <system.web> line:
<httpModules >
<add name = "HttpModule_Manifest" type="MazeComputer.AspManifestHelpers.HttpModule_Manifest, AspManifestHelpers" />
</httpModules >
So you will see a code like on a screenshot below:

Now add reference to PDFDocScout.dll file by doing the following: right-click on project name and select "Add Reference" command in right-click menu:

Browse /PDFDocScout.assembly/ and select PDFDocScout.dll file and click "OK" button to add reference

Now you will see that 2 new files appear in the list of files for project:
Interop.PDFDocScout.dll and stdole.dll (see screenshot below):

Finally our web-site project is ready for coding PDF generation using PDFDoc Scout library!
Double click on Default.aspx.cs file in Solution Explorer:

Editor window will appear with "Default.aspx.cs" file in it
First of all add this code to the beginning of the file:
using System;
using PDFDocScout;
using Page=System.Web.UI.Page;
Add code to generate PDF using PDFDocScout in "Page_Load" function as shown below:

try
{
// create new PDFDoc object
PDFDocument PDFDoc = new PDFDocumentClass();
// initalize library
PDFDoc.InitLibrary("demo", "demo");
// set in-memory mode
// set to True to generate PDF document in memory without any files on disk to output it to end-user to browser
PDFDoc.GenerateInMemoryFile = true;
// start PDF document generation
PDFDoc.BeginDocument();
// add text to current page
PDFDoc.Page.AddText("Hello, World!", 100, 100, 15);
// close PDF document generation
PDFDoc.EndDocument();
// get size of generated in-memory PDF document
int Size = PDFDoc.BinaryImageSize;
// create new buffer with size equal to generated pdf document file
byte[] buffer = new byte[Size + 1];
// get in-memory pdf file as byte stream
Array MemoryImage = (Array) PDFDoc.BinaryImage;
// copy byte stream into buffer
Array.Copy(MemoryImage, buffer, Size);
// clear http output
Response.Clear();
// set the content type to PDF
Response.ContentType = "application/pdf";
// add content type header
Response.AddHeader("Content-Type", "application/pdf");
// set the content disposition
Response.AddHeader("Content-Disposition", "inline;filename=helloworld.pdf");
// write the buffer with pdf file to the output
Response.BinaryWrite(buffer);
Response.End();
}
catch (Exception ex)
{
if (!(ex is System.Threading.ThreadAbortException))
System.Diagnostics.Debug.WriteLine(ex.Message);
}
Press F5 to start web-site project and PDF file will be generated and you’ll see PDF generated by your web-site project:

Generated PDF document file opened in Adobe Reader:

Tutorials: