got the html export into file working with code bellow: 

    # write view html into file
    conf, po, skus = get_data(65)    # test data
    view_template = os.path.join(request.folder, 'views/default', 
'print_proforma_invoice.html')
    html = response.render(view_template, dict(conf=conf, po=po, skus=skus))
    filename="test-dec-pdf-po-28.html" # test output file name
    open(filename,'wb').write(response.render(view_template, 
dict(conf=conf, po=po, skus=skus)))

but it seems the PDF part creation triggered an error while rendering CSS 
in pyfpdf/html.py. (100px was a width of an image, specified in css)

If it's of any value to anyone, here is a trackback bellow:

<type 'exceptions.ValueError'> invalid literal for int() with base 10: 
'100px'

traceback:

Traceback (most recent call last):
  File "/Users/adnan/web2py-dev-branch/gluon/restricted.py", line 204, in 
restricted
    exec ccode in environment
  File 
"/Users/adnan/web2py-dev-branch/applications/Wholesale/controllers/default.py" 
<http://127.0.0.1:8000/admin/default/edit/Wholesale/controllers/default.py>, 
line 596, in <module>
  File "/Users/adnan/web2py-dev-branch/gluon/globals.py", line 172, in <lambda>
    self._caller = lambda f: f()
  File 
"/Users/adnan/web2py-dev-branch/applications/Wholesale/controllers/default.py" 
<http://127.0.0.1:8000/admin/default/edit/Wholesale/controllers/default.py>, 
line 580, in myreport
    pdf.write_html(html)
  File "/Users/adnan/web2py-dev-branch/gluon/contrib/pyfpdf/html.py", line 388, 
in write_html
    h2p.feed(text)
  File 
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/HTMLParser.py",
 line 108, in feed
  File 
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/HTMLParser.py",
 line 148, in goahead
  File 
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/HTMLParser.py",
 line 269, in parse_starttag
  File 
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/HTMLParser.py",
 line 325, in handle_startendtag
  File "/Users/adnan/web2py-dev-branch/gluon/contrib/pyfpdf/html.py", line 257, 
in handle_starttag
    w = px2mm(attrs.get('width', 0))
  File "/Users/adnan/web2py-dev-branch/gluon/contrib/pyfpdf/html.py", line 17, 
in px2mm
    return int(px)*25.4/72.0
ValueError: invalid literal for int() with base 10: '100px'

Reply via email to