# Path: app.py



import os
import sys
from flask import request, Response, render_template, redirect, url_for
from flaskext.mail import Mail, Message
from xhtml2pdf import pisa
from StringIO import StringIO
from app import app
        <h2>Some page title.</h2>
        <table width="100%" cellpadding="4" cellspacing="0">
            <tbody>
                <tr>
                    <td width="100%">Some text.</td>
                </tr>
            </tbody>
            <tbody>
                <tr style="border: 1px solid #000000;">
                    <td width="100%">
                        <h3 style="text-align: center;">Some subtitle</h3>
                        <div>{{ g.user.get('user_attribute') }}</div>
                    </td>
                </tr>
            </tbody>
        </table>
        <hr style="margin: 3em 0;"/>
        <img src="{{ url_for('static', filename='img.png', _external=True) }}" />
    {% endblock %}
    </body>
</html>
"""


def create_pdf(pdf_data):
    pdf = StringIO()
    pisa.CreatePDF(StringIO(pdf_data.encode('utf-8')), pdf)
    return pdf



# Path: app.py



# Path: templatetricks/generate_pdf.py
import os
import sys
from flask import request, Response, render_template, redirect, url_for
from flaskext.mail import Mail, Message
from xhtml2pdf import pisa
from StringIO import StringIO
from app import app

        <h2>Some page title.</h2>
        <table width="100%" cellpadding="4" cellspacing="0">
            <tbody>
                <tr>
                    <td width="100%">Some text.</td>
                </tr>
            </tbody>
            <tbody>
                <tr style="border: 1px solid #000000;">
                    <td width="100%">
                        <h3 style="text-align: center;">Some subtitle</h3>
                        <div>{{ g.user.get('user_attribute') }}</div>
                    </td>
                </tr>
            </tbody>
        </table>
        <hr style="margin: 3em 0;"/>
        <img src="{{ url_for('static', filename='img.png', _external=True) }}" />
    {% endblock %}
    </body>
</html>
"""


def create_pdf(pdf_data):
    pdf = StringIO()
    pisa.CreatePDF(StringIO(pdf_data.encode('utf-8')), pdf)
    return pdf



mail_ext = Mail(app)