Hello,
Am trying to generate Arabic reports by web2py and the characters displayed 
with wrong encoding.

I tried the following :

1- generate PDF :

def printExam():

    reload(sys)
    sys.setdefaultencoding('utf-8') 
    exam_id = request.args[0]
    subject = request.args[1]
    
    response.title = T('Test')

    # read elements from db 

    elements = db(db.exam_questions.exam == exam_id ).select()
    count = db(db.exam_questions.exam == exam_id ).count()
# define header and footers:
    head = THEAD(TR(TH("Header 1", _width="100%"), 
                    _bgcolor="#A0A0A0"))
    foot = TFOOT(TR(TH("Footer 1", _width="100%"), 
                    _bgcolor="#E0E0E0")) 
    rows  = []
    for element in elements:
for i in range(count):
#col = i % 2 and "#F0F0F0" or "#FFFFFF"
rows.append(TR(
                       TD(element.question, _align="right"),
                       )) 

    # make the table object
    body = TBODY(*rows)
    table = TABLE(*[head, foot, body], 
                  _border="1", _align="right", _width="100%")
    # define our FPDF class (move to modules if it is reused frequently)
    class MyFPDF(FPDF, HTMLMixin):
def header(self):
#self.set_font('DIN Next LT Arabic', 'B', 15)
self.cell(0, 10, response.title, 1, 0, 'C')
self.ln(20)

def footer(self):
self.set_y(-15)
#self.set_font('DIN Next LT Arabic', 'I', 8)
txt = 'Page %s of %s' % (self.page_no(), self.alias_nb_pages())
self.cell(0, 10, txt, 0, 0, 'C')

    pdf = MyFPDF()
    pdf.add_font('DIN Next LT Arabic', '', r"DINNextLTArabic-Regular.ttf", 
uni=True)

    # first page:
    pdf.add_page()
    pdf.write_html(str(XML(table, sanitize=False)))
    response.headers['Content-Type'] = 'application/pdf; charset=utf-8'
    return pdf.output(dest='S')



2- create word documnet :

def documnet():
from gluon.contrib.pyrtf import *
import cStringIO,codecs
    
doc     = Document()
ss      = doc.StyleSheet
section = Section()
doc.Sections.append( section )
    
p = Paragraph( ss.ParagraphStyles.Heading1 )
p.append( str(T('Test')).encode('utf-8'))
section.append( p )

s = cStringIO.StringIO()
wrapper = codecs.getwriter("utf8")(s)
Renderer().Write(doc, wrapper)
wrapper.seek(0)
response.encoding = 'utf-8'
#response.headers['Content-Type'] = 'application/doc; charset=utf-8'
return response.stream(wrapper, attachment= True, 
filename='yourdocument.rtf') 


Both displayed the Arabic word with wrong encoding ? could you please 
advise how can i do that ?



My second question is , Is there away to integrate with Birt from web2py ?

Thanks in advance.

-- 
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