I belive Chinese is not ported to pypdf (the php software supported it
via a special class). AFAIK the chinese fonts BIG5 or GB must be
installed in the server. Maybe you could start an issue for adding it
in the project page.

http://code.google.com/p/pyfpdf/

On 15 mar, 17:53, Bruce Wade <bruce.w...@gmail.com> wrote:
> Does pyfpdf support Chinese yet? I tried using Chinese by the characters
> were not rendered in Chinese. Or do I need to set some kind of font.
>
>
>
>
>
>
>
>
>
> On Thu, Mar 15, 2012 at 1:35 PM, Alan Etkin <spame...@gmail.com> wrote:
> > That error page is likely to be sent because of the new generic view
> > security rule. I'm using the response.generic_patterns = ["*",] in the
> > controller file and it works well (the sentence wasn't included in the
> > original file).
>
> > On 15 mar, 17:15, Bruce Wade <bruce.w...@gmail.com> wrote:
> > > Okay so the downloaded code the pdf works but the normal HTML view
> > doesn't.
>
> > > invalid view (default/report.html)
>
> > > On Thu, Mar 15, 2012 at 11:48 AM, Alan Etkin <spame...@gmail.com> wrote:
> > > > I should check the code in the book, but I used a controller example
> > > > that should be available in the book's support files at
> > > >http://www.packtpub.com/supportandit worked for my environment:
>
> > > > Python 2.6.5
> > > > Mandriva GNU/Linux 2010
> > > > web2py (last mercurial version)
>
> > > > A complete working installer can be downloaded from the same url (in
> > > > the apps folder)
>
> > > > On Mar 15, 2:54 pm, Bruce Wade <bruce.w...@gmail.com> wrote:
> > > > > Fresh blank version of web2py, in default controller:
>
> > > > > def report():
> > > > >     import os
> > > > >     response.title = "web2py sample report"
>
> > > > >     # include a chart from google chart
> > > > >     url = "
> > > >http://chart.apis.google.com/chart?cht=p3&chd=t:60,40&chs=500x200&ch1.
> > ..
> > > > > "
> > > > >     chart = IMG(_src=url, _width="250", _height="100")
>
> > > > >     # create a small table with some data:
> > > > >     rows = [THEAD(TR(TH("Key", _width="70%"),
> > > > >         TH("Value", _width="30%"))),
> > > > >         TBODY(TR(TD("Hello"), TD("60")),
> > > > >         TR(TD("World"), TD("40")))]
>
> > > > >     table = TABLE(*rows, _border="0", _align="center", _width="50%")
>
> > > > >     if request.extension == "pdf":
> > > > >         from gluon.contrib.pyfpdf import FPDF, HTMLMixin
>
> > > > >         # create a custom class with the required functionalities
> > > > >         class MyFPDF(FPDF, HTMLMixin):
> > > > >             def header(self):
> > > > >                 "hook to draw custom page header (logo and title)"
>
> > > > >                 # remember to copy logo_pb.png to static/images (and
> > > > remove
> > > > > alpha channel)
> > > > >                 #logo = os.path.join(request.folder, "static",
> > "images",
> > > > > "logo_pb.png")
> > > > >                 #self.image(logo, 10, 8, 33)
> > > > >                 self.set_font("Arial", "B", 15)
> > > > >                 self.cell(65)   # padding
> > > > >                 self.cell(60, 10, response.title, 1, 0, 'C')
> > > > >                 self.ln(20)
>
> > > > >             def footer(self):
> > > > >                 "hook to draw custom page footer (printing page
> > numbers)"
> > > > >                 self.set_y(-15)
> > > > >                 self.set_font('Arial', 'I', 8)
> > > > >                 txt = 'Page %s of %s' % (self.page_no(),
> > > > > self.alias_nb_pages())
> > > > >                 self.cell(0, 10, txt, 0, 0, 'C')
> > > > >                 pdf = MyFPDF()
>
> > > > >                 # create a page and serialize/render HTML objects
> > > > >                 pdf.add_page()
> > > > >                 pdf.write_html(table.xml())
> > > > >                 #pdf.write_html(CENTER(chart).xml())
>
> > > > >                 # prepare PDF to download:
> > > > >                 response.headers['Content-Type'] = 'application/pdf'
> > > > >                 return pdf.output(dest='S')
>
> > > > >     # else normal html view
> > > > >     return dict(chart=chart, table=table)
>
> > > > > I thought it was the logo so I commented it out, but still the exact
> > same
> > > > > error.
>
> > > > > Looks like it is failing here:
> > > > > def _parsepng(self, name):
> > > > >         #Extract info from a PNG file
> > > > >         if name.startswith("http://";) or name.startswith("https://
> > "):
> > > > >             import urllib
> > > > >             f = urllib.urlopen(name)
>
> > > > > Which I am not sure why considering there is no PNG in my code so I
> > guess
> > > > > it is doing something behind the scene. I even commented out the
> > chart
> > > > line
> > > > > so there should be no image issues.
>
> > > > > On Thu, Mar 15, 2012 at 10:49 AM, Bruce Wade <bruce.w...@gmail.com>
> > > > wrote:
> > > > > > Install what app? I am following the instructions to create a PDF.
>
> > > > > > On Thu, Mar 15, 2012 at 10:47 AM, Alan Etkin <spame...@gmail.com>
> > > > wrote:
>
> > > > > >> How are you running the code? Did you install the app from the
> > apps
> > > > > >> folder?
>
> > > > > >> On Mar 15, 2:29 pm, Bruce Wade <bruce.w...@gmail.com> wrote:
> > > > > >> > Chapter 10: Creating PDF reports
>
> > > > > >> > Error:
>
> > > > > >> > Traceback (most recent call last):
> > > > > >> >   File
>
> > "/home/bruce/Development/bossteam_dev/projects/yaw_dev/gluon/restricted.py",
> > > > > >> > line 204, in restricted
> > > > > >> >     exec ccode in environment
> > > > > >> >   File
>
> > "/home/bruce/Development/bossteam_dev/projects/yaw_dev/applications/welcome/views/generic.pdf",
> > > > > >> > line 9, in <module>
> > > > > >> >     pass
> > > > > >> >   File
>
> > "/home/bruce/Development/bossteam_dev/projects/yaw_dev/gluon/contrib/generics.py",
> > > > > >> > line 63, in pdf_from_html
> > > > > >> >     return pyfpdf_from_html(html)
> > > > > >> >   File
>
> > "/home/bruce/Development/bossteam_dev/projects/yaw_dev/gluon/contrib/generics.py",
> > > > > >> > line 55, in pyfpdf_from_html
> > > > > >> >     pdf.write_html(html,image_map=image_map)
> > > > > >> >   File
>
> > "/home/bruce/Development/bossteam_dev/projects/yaw_dev/gluon/contrib/pyfpdf/html.py",
> > > > > >> > line 388, in write_html
> > > > > >> >     h2p.feed(text)
> > > > > >> >   File "/usr/lib/python2.7/HTMLParser.py", line 109, in feed
> > > > > >> >     self.goahead(0)
> > > > > >> >   File "/usr/lib/python2.7/HTMLParser.py", line 151, in goahead
> > > > > >> >     k = self.parse_starttag(i)
> > > > > >> >   File "/usr/lib/python2.7/HTMLParser.py", line 272, in
> > > > parse_starttag
> > > > > >> >     self.handle_startendtag(tag, attrs)
> > > > > >> >   File "/usr/lib/python2.7/HTMLParser.py", line 334, in
> > > > > >> handle_startendtag
> > > > > >> >     self.handle_starttag(tag, attrs)
> > > > > >> >   File
>
> > "/home/bruce/Development/bossteam_dev/projects/yaw_dev/gluon/contrib/pyfpdf/html.py",
> > > > > >> > line 262, in handle_starttag
> > > > > >> >     x, y, w, h, link=self.href)
> > > > > >> >   File
>
> > "/home/bruce/Development/bossteam_dev/projects/yaw_dev/gluon/contrib/pyfpdf/fpdf.py",
> > > > > >> > line 807, in image
> > > > > >> >     info=self._parsepng(name)
> > > > > >> >   File
>
> > "/home/bruce/Development/bossteam_dev/projects/yaw_dev/gluon/contrib/pyfpdf/fpdf.py",
> > > > > >> > line 1296, in _parsepng
> > > > > >> >     f = urllib.urlopen(name)
> > > > > >> >   File "/usr/lib/python2.7/urllib.py", line 84, in urlopen
> > > > > >> >     return opener.open(url)
> > > > > >> >   File "/usr/lib/python2.7/urllib.py", line 205, in open
> > > > > >> >     return getattr(self, name)(url)
> > > > > >> >   File "/usr/lib/python2.7/urllib.py", line 331, in open_http
> > > > > >> >     h = httplib.HTTP(host)
> > > > > >> >   File "/usr/lib/python2.7/httplib.py", line 1061, in __init__
> > > > > >> >     self._setup(self._connection_class(host, port, strict))
> > > > > >> >   File "/usr/lib/python2.7/httplib.py", line 693, in __init__
> > > > > >> >     self._set_hostport(host, port)
> > > > > >> >   File "/usr/lib/python2.7/httplib.py", line 718, in
> > _set_hostport
> > > > > >> >     raise InvalidURL("nonnumeric port: '%s'" % host[i+1:])
> > > > > >> > InvalidURL: nonnumeric port: ''
>
> > > > > >> > I also found this argument list to look very strange, look at
> > the
> > > > host
> > > > > >> > string, plus port is NoneFunction argument list
>
> > > > > >> > (self=<httplib.HTTPConnection instance>, host='127.0.0.1:8000
> > > > http:',
> > > > > >> > port=None)
>
> > > > > >> > --
> > > > > >> > --
> > > > > >> > Regards,
> > > > > >> > Bruce Wadehttp://
>
> > ca.linkedin.com/in/brucelwadehttp://www.wadecybertech.comhttp://www.warplydesigned.comhttp://www.f
> > .
> > > > ..
>
> > > > > > --
> > > > > > --
> > > > > > Regards,
> > > > > > Bruce Wade
> > > > > >http://ca.linkedin.com/in/brucelwade
> > > > > >http://www.wadecybertech.com
> > > > > >http://www.warplydesigned.com
> > > > > >http://www.fitnessfriendsfinder.com
>
> > > > > --
> > > > > --
> > > > > Regards,
> > > > > Bruce Wadehttp://
>
> > ca.linkedin.com/in/brucelwadehttp://www.wadecybertech.comhttp://www.warplydesigned.comhttp://www.f.
> > ..
>
> > > --
> > > --
> > > Regards,
> > > Bruce Wadehttp://
> > ca.linkedin.com/in/brucelwadehttp://www.wadecybertech.comhttp://www.warplydesigned.comhttp://www.f...
>
> --
> --
> Regards,
> Bruce 
> Wadehttp://ca.linkedin.com/in/brucelwadehttp://www.wadecybertech.comhttp://www.warplydesigned.comhttp://www.fitnessfriendsfinder.com

Reply via email to