ReptarX / pyfpdf

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

problems with unicode characters #52

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

I have written a new function (see attached file):

def report():
    from gluon.contrib.pyfpdf import FPDF, HTMLMixin
    from gluon.contrib.pyfpdf.html import HTML2FPDF

    text = u"<font face='DejaVu'>abc<br/>äöü</font>"
    text2 = u"€" # does not work   <==============
    text3 = u"Χανιά" # does'n work  <===============

    pdf=FPDF()

    pdf.add_font('DejaVu', '', os.path.join(request.folder, "private", "font", 'DejaVuSans.ttf'), uni=True)
    pdf.set_font('DejaVu','',12)

    # create the basic html parser:
    # h2p = HTML2FPDF(pdf, image_map) # what is image map?  <=========
    h2p = HTML2FPDF(pdf)

    h2p.font_list = list(h2p.font_list) + ['DejaVu']
    pdf.add_page()
    h2p.feed(text)

    response.headers['Content-Type']='application/pdf'
    return pdf.output(dest='S')

Result: as expected, with or without <face... >
But: again it's only possible to use Latin-1 characters. What is wrong?

============================================================

I think there is another problem:
The file "DejaVuSans.pkl" contains an absolute file path, e.g.

line 4:
S'D:\\dropbox\\web2py\\applications\\fpdf17utest\\private\\font\\DejaVuSans.ttf'

I have not tried it, but I think, therefore this application will not be 
portable.

==========================================================

What is the expected output? 
World blä€ßèéØÞĩΏφζЖЦהعỶ₧ α

What do you see instead?

report.html:
World blä€ßèéØÞĩΏφζЖЦהعỶ₧ &alpha;

report.pdf:
World 
blä€ßèéØÞĩΕφζЖЦהعỶâ‚
§ 

What version of the product are you using? On what operating system?
1.7. 
Windows 7

Original issue reported on code.google.com by mweis...@gmail.com on 5 Mar 2013 at 2:07

Attachments:

GoogleCodeExporter commented 9 years ago
Typos:

def report():
    "example to generate a pdf based un basic html (use http:/.../report.pdf download the pdf)"
                                     ^------------------------------------

    response.view = "generic.html"            # default view to test html generation
    response.title = "web2py sample report"

    # include a google chart!
    url = "http://chart.apis.google.com/chart?cht=p3&chd=t:60,40&chs=250x100&chl=Hello|World&.png"
    chart = IMG(_src=url, _width="250",_height="100")

------------------------------------------------------

def invoice():
    "example to generate an invoice based on a geeric pdf template"
                                                 ^---------------------------------------------

    # for more info see https://code.google.com/p/pyfpdf/wiki/Templates

    from gluon.contrib.pyfpdf import Template
    import os.path

    # generate sample invoice (according Argentina's regulations)

Original comment by mweis...@gmail.com on 5 Mar 2013 at 2:15

GoogleCodeExporter commented 9 years ago
Hello, could you please split this in several smaller issues? thanks for you 
contribution!

Original comment by reingart@gmail.com on 5 Mar 2013 at 2:41

GoogleCodeExporter commented 9 years ago
Please see issue 68, there are some hints about how to use ttf fonts and html

Original comment by reingart@gmail.com on 5 Feb 2014 at 4:23