Components for Developers
© 2000-2008, Two Pilots

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

PDF Creator Pilot documentation

Download CHM version of this manual.
PDF Creator Pilot 4
How to create PDF with Python on the web server

See Also Example
Collapse All

Once you have installed PDF Creator Pilot to you system it is available for use from Python.

This sample demonstrates how to use PDF Creator Pilot with Python running under IIS web server. You may use any web server and any library to handle writing in output stream. Different libraries may provide different ways for writing data to response.

You need to import win32com.client library to be able to work with COM. Then create a new COM object:

import sys
import win32com.client
PDF = win32com.client.Dispatch("PDFCreatorPilot.PDFDocument4")

Then you need to set license data and adjust other properties:

PDF.SetLicenseData("demo", "demo")
PDF.Compression = 1 # coFlate = 1

Fill your document with some data:

fnt = PDF.AddBuiltInFont(1, 0, 0)
PDF.UseFont(fnt, 14)
PDF.ShowTextAt(30, 30, "Hello from Python!")

Now send it directly to user output stream:

# get generated PDF as binary image
size = PDF.MemoryFileSize
data = PDF.BinaryImage
Response.Clear()
Response.ContentType = "application/pdf"
Response.AddHeader("Content-Type", "application/pdf")
Response.AddHeader("Content-Disposition", "attachment;filename=test.pdf")
Response.AddHeader("Content-Length", size)
Response.BinaryWrite(data)
Response.End()

Example

Using PDF Creator Pilot in APS/Python page

ASP/Python
[copy to clipboard]
<%@LANGUAGE=Python%>
<%
import sys
import win32com.client

PDF = win32com.client.Dispatch("PDFCreatorPilot.PDFDocument3")
PDF.StartEngine("demo", "demo")
PDF.Compression = 1
PDF.GenerateInMemoryFile = 1
 
PDF.BeginDoc()
# draw a message on the current PDF page
PDF.PDFPAGE_SetActiveFont("Verdana", 0, 0, 0, 0, 14, 0)
PDF.PDFPAGE_TextOut(10, 20, 0, "HELLO, from Python!")
PDF.EndDoc()

# get generated PDF as binary image
size = PDF.MemoryFileSize
data = PDF.BinaryImage
Response.Clear()
Response.ContentType = "application/pdf"
Response.AddHeader("Content-Type", "application/pdf")
Response.AddHeader("Content-Disposition", "attachment;filename=test.pdf")
Response.AddHeader("Content-Length", size)
Response.BinaryWrite(data)
Response.End()
%>

See Also

Reference

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

© 2000-2008, Two Pilots