Hello everyone,
I am trying to generate reports using Reportlab in web2py. I'm working on 
pythonanywhere.com
I am having some problems because I want to insert an image as header into 
the pdf report

this is my report.py 

from reportlab.platypus import *
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.rl_config import defaultPageSize
from reportlab.lib.units import inch, mm
from reportlab.lib.enums import TA_LEFT, TA_RIGHT, TA_CENTER, TA_JUSTIFY
from reportlab.platypus import SimpleDocTemplate, Image
from reportlab.lib import colors
from uuid import uuid4
from cgi import escape
import os

def index():
    title = "Mi mundo REPORTE PDF"
    heading = "MI PRIMER RE"
    text = 'bla '* 10
    styles = getSampleStyleSheet()
    tmpfilename=os.path.join(request.folder,'private',str(uuid4()))
    doc = SimpleDocTemplate(tmpfilename)
    story = []
    logo = "/static/images/logounca.png"
    imagen_logo = Image(os.path.realpath(logo),width=400,height=100)
    story.append(imagen_logo)
    story.append(Paragraph(escape(title),styles["Title"]))
    story.append(Paragraph(escape(heading),styles["Heading2"]))
    story.append(Paragraph(escape(text),styles["Normal"]))
    story.append(Spacer(1,2*inch))
    doc.build(story)
    data = open(tmpfilename,"rb").read()
    os.unlink(tmpfilename)
    response.headers['Content-Type']='application/pdf'
    return data

My view.html
{{extend 'layout.html'}}
<h1>This is my report/index.html</h1>
{{=BEAUTIFY(response._vars)}}

When I try to view the pdf, it gives me this error
*<type 'exceptions.IOError'> Cannot open resource 
"/static/images/logounca.png" fileName='/static/images/logounca.png' 
identity=[ImageReader@0x7fa7f0bf5510 
filename='/static/images/logounca.png']*
I don't know if I am calling the image url wrong or If I uploaded the image 
wrongly. 
I uploaded the image on pythonanywhere.com through the Static section.
If someone can help me with this issue, please

Thanks :)

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to