scott1028 / pyfpdf

Automatically exported from code.google.com/p/pyfpdf
GNU Lesser General Public License v3.0
0 stars 0 forks source link

Unable to specify font and size when parsing html to ftp #15

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
While creating a PDF document, I had no problem generating the perfect header 
and footer, but when I passed html to your module, all styling was removed and 
I was unable to successfully change the font using the <font> tags.

So everything was coming out in times new roman, therefore I made the following 
changes you may want to include:

Basically I have added more fiends to the write_html() functions

e.g. pdf.write_html(text=str(XML(table, 
sanitize=False)),font="arial",fontsize=11)

This way you can specify the font and size of the text you are passing through. 
Changes done:

class HTMLMixin():
    def write_html(self, **kwargs):   
        "Parse HTML and convert it to PDF"
        h2p = HTML2FPDF(self,**kwargs)
        h2p.feed(kwargs["text"])

class HTML2FPDF(HTMLParser):
    "Render basic HTML to FPDF"

    def __init__(self, pdf, image_map):
        HTMLParser.__init__(self)
        self.image_map = kwargs.get("image_map","")
        self.set_font(kwargs.get("font","times"), kwargs.get("fontsize",12))

        (removed extra code)

Please let me know if you need anything else from me.

Tyrone Hattingh

Original issue reported on code.google.com by tyrone.h...@gmail.com on 14 Sep 2011 at 2:14

GoogleCodeExporter commented 9 years ago
Thanks, see issue 16 that will fix this, can you comment there?

Original comment by reingart@gmail.com on 3 Oct 2011 at 5:48