Home

PDFDoc Scout

PDFDoc Scout screenshot (click to enlarge)



PDFDoc Scout library - Sample

Download Free Trial See Licensing Options More Information

Quick Guide on using PDFDoc Scout library with ClickOnce deployment style in ASP.NET 2 web-sites

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

pdfdocscout_aspnet2_regfree_create_new_site_menu_in_vs

Enter name of new web-site and click OK


pdfdocscout_aspnet2_regfree_create_new_site_dialog_in_vs

Right-click on project in Solution Explorer and select "Add Reference" command in popup menu invoked:pdfdocscout_aspnet2_regfree_add_reference_to_aspmanifesthelpers_dll_menu_in_vs

Browse for "ASPManifestHelpers.dll" (you can find it in ZIP with sample code) and select it and click OK to add reference:
pdfdocscout_aspnet2_regfree_add_reference_to_aspmanifesthelpers_dll_dialog_in_vs

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

pdfdocscout_aspnet2_regfree_docscout_assembly_folder_menu_in_vs

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


pdfdocscout_aspnet2_regfree_create_pdfdocscout_assembly_folder_rename_in_vs

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:

pdfdocscout_aspnet2_regfree_add_pdfdocscout_dll_and_pdfdocscout_assembly_manifest_menu_in_vs

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:
pdfdocscout_aspnet2_regfree_add_pdfdocscout_dll_and_pdfdocscout_assembly_manifest_dialog_in_vs

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

pdfdocscout_aspnet2_regfree_add_webapp_manifest_menu_in_vs


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

pdfdocscout_aspnet2_regfree_add_webapp_manifest_dialog_in_vs

Start project by clicking "Start Debugging" button as shown below:pdfdocscout_aspnet2_regfree_start_project_in_vs


Visual Studio will suuggest to add new Web.config file. Answer Yes as shown below:


pdfdocscout_aspnet2_regfree_add_web_config_in_vs

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

pdfdocscout_aspnet2_regfree_click_web_config_in_vs

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:

pdfdocscout_aspnet2_regfree_edit_web_config_in_vs

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:

pdfdocscout_aspnet2_regfree_add_reference_to_pdfdocscout_dll_menu_in_vs

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

pdfdocscout_aspnet2_regfree_add_reference_to_pdfdocscout_dll_dialog_in_vs

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):

pdfdocscout_aspnet2_regfree_bin_folder_in_vs

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:

pdfdocscout_aspnet2_regfree_click_defailt_aspx_cs_in_vs

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:

pdfdocscout_aspnet2_regfree_code_defailt_aspx_cs_in_vs

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:
pdfdocscout_aspnet2_regfree_open_file_dialog_in_vs

Generated PDF document file opened in Adobe Reader:

pdfdocscout_aspnet2_regfree_open_file_in_vs

You can download the source code of this example here: pdfdocscout_registration_free_in_asp_net2.zip
Download Free Trial See Licensing Options More Information


See also: Bytescout.PDF - native .NET library to write/read/sign/
modify/merge/split PDF documents (but no HTML2PDF support)



On-line documentation (HTML format)


"Hello, World!" quick start step-by-step tutorials:

Products  |  Download  |  Purchase  |  Support  |  Contacts  |  Testimonials |  

ByteScout, 2003-2008. All other company and product names may be trademarks of their respective companies. Privacy Statement