Components for Developers © 2000-2008, Two Pilots

PDF Library Download Features Manual Tutorials FAQ Pricing HTML2PDF Add-on History In the Lab

PDF version of this article is available.
Click here to download.

How to generate PDF in ASP: "Hello, PDF!" example

Step by Step

 

This page contains a step-by-step tutorial that will teach you how to create PDF files from ASP page using PDF Creator Pilot library.

Please note that to be able to use the full version of PDF Creator Pilot library on Web-server, you need to have an additional Web License for every Web-server that is used.

PDF Creator Pilot can generate in-memory PDF file so it does not need to be stored as a file and can be streamed right into the browser window.

The library has a special "GenerateInMemoryFile" flag for such purposes. You can set this flag to TRUE and the library will generate and keep your PDF file only in the memory. You can get PDF as a string or as a BinaryImage.

1) Install PDF Creator Pilot library on your computer and create an "HelloPDF.asp" file in the Notepad.

2) To create a PDF file from ASP, you have to implement a code that will do the following things:

  1. create and initialize PDF Creator Pilot object;
  2. set GenerateInMemoryFile to TRUE;
  3. draw "Hello, PDF!" message on the PDF document;
  4. copy PDF document as a BinaryImage using Response ASP object and its BinaryWrite command;
  5. disconnect from the library.

Content of "HelloPDF.asp" file:


<%

 ' create pdf library object
 Set PDF = CreateObject("PDFCreatorPilot3.PDFDocument3")

 ' initialize PDF Engine
 PDF.StartEngine "demo@demo", "demo"
 
 ' set GenerateInMemoryFile flag to TRUE so keep PDF only in the memory
 PDF.GenerateInMemoryFile = TRUE
 
 ' start document generation
 PDF.BeginDoc
 
 ' draw "HELLO, PDF" message on the current PDF page
 PDF.PDFPAGE_SetActiveFont "Verdana", True, False, False, False, 14, 0
 PDF.PDFPAGE_TextOut 10, 20, 0, "HELLO, PDF!"
 
 ' finalize document generation
 PDF.EndDoc
 
 ' get generated PDF as binary image
 PdfImage = PDF.BinaryImage
 
 ' clear the output stream
 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=form.pdf"
' write the PDF binary image to the Response output stream response.BinaryWrite PdfImage response.End ' disconnect from library Set PDF = Nothing %>

Feel free to copy this code to the Notepad and save it as "HelloPDF.ASP":

3) Copy HelloPDF.ASP to the server root folder. If you use IIS, then it is located in the "c:\inetpub\wwwroot\" folder by default.

4) Now you can launch HelloPDF.asp page from your browser and your users will see the generated PDF in the browser as it shown on the screenshot below:

Hello, PDF! in the Internet Explorer browser

You can download the source code for the described example here (0.6 Kb)

 

PDF Creator Pilot can be used with different languages to generate PDF files. See "Hello, PDF" example for:

See also:

 

If you have questions related to PDF Creator Pilot, contact us via our online support form.

PDF Library Download Features Manual Tutorials FAQ Pricing HTML2PDF Add-on History In the Lab

 

 

PDF Library | Virtual Printer | Converters to PDF

Support | Blog | Forum | Contacts | Site map

© 2000-2008, Two Pilots