4. Using Python

To use the PDFreactor Python API simply copy the PDFreactor.py to a directory of your webserver where Python is enabled (by e.g. CGI or mod-python).

Then include the PDFreactor.py with:

import sys
sys.path.append("path/to/PDFreactor.py/")
from PDFreactor import *

With just a few lines you can create and directly show PDFs inside your Python webapplication:

PDFreactor = PDFreactor()
PDFreactor.setAuthor("Myself")
PDFreactor.setAddLinks(True)
PDFreactor.setAddBookmarks(True)
result = PDFreactor.renderDocumentFromURL("http://www.realobjects.com")
if PDFreactor.getError() == None:
    print "Content-Type: application/pdf\n"
    print result
else:
    print "Content-Type: text/html\n"
    print PDFreactor.getError()

Windows specific issues:

To directly output the PDF to the browser please use the following code:

if sys.platform == "win32":
    import os, msvcrt
    msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
    print "Content-Type: application/pdf\n"
    sys.stdout.write(result)

See:

PDFreactor methods in the Python API docs for all avaible options.