PDFDoc Scout |
PDFDoc Scout library - Sample
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
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 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:
Start project by clicking "Start Debugging" button
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 >
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: Now you will see that 2 new files appear in the list of
files for project: 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;
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:
You can download the source code of this example here: pdfdocscout_registration_free_in_asp_net2.zip
"Hello, World!" quick start step-by-step tutorials: |
|
|
||