Welcome, guest | Sign In | My Account | Store | Cart
import cStringIO
import ho.pisa as pisa
import os

# Shortcut for dumping all logs on screen

def HTML2PDF(data, filename, open=False):

    Simple test showing how to create a PDF file from
    PML Source String. Also shows errors and tries to start
    the resulting PDF

    pdf = pisa.CreatePDF(
        file(filename, "wb"))

    if open and (not pdf.err):

    return not pdf.err

if __name__=="__main__":
    HTMLTEST = """
    <p>Hello <strong style="color: #f00;">World</strong>
    <table border="1" style="background: #eee; padding: 0.5em;">
            <td>Good weather</td>
            <td>0 EUR</td>
        <tr style="font-weight: bold">
            <td colspan="2" align="right">Sum</td>
            <td>0 EUR</td>

    HTML2PDF(HTMLTEST, "test.pdf", open=True)