0

I create reports by means of RML(XML) and parse to PDF (use pyjon.reports).

In output pdf polish char not display

my xml file

<?xml version="1.0" encoding="utf-8" standalone="no" ?>
<!DOCTYPE document SYSTEM "rml.dtd">
<document filename="encoding-test-utf8.pdf">

  <template>
    <pageTemplate id="main">
      <frame id="first" x1="72" y1="72" width="451" height="698"/>
    </pageTemplate>
  </template>

  <stylesheet>
  </stylesheet>

  <story>
    <title>Test of Encoding: UTF-8</title>
    <para>
    ą ź ś ć ł ę
    </para>
     <spacer length="1in" />
    <para>
    </para>
  </story>
</document>

My Python code,

# -*- coding: utf-8 -*-

from rml2pdf.factory import ReportFactory


factory = ReportFactory()
factory.render_template(template_file='templates/a.xml')
factory.render_document('test.pdf')
factory.cleanup()

Now i try debug but result is not effect. ( sorry for my english )

3
Contributors
3
Replies
10
Views
4 Years
Discussion Span
Last Post by shadia.mohamed.9_1
0

If you are using Python3 you may get a bytearray rather than a string and have to decode it first ...

# tested with Python32

# string of Polish characters
mystr = "ą ź ś ć ł ę"

# encode string to <class 'bytes'> or bytearray
mybytes = mystr.encode("utf8")

# decode <class 'bytes'> to string
mystr2 = mybytes.decode("utf8")

print(mystr)
print(mybytes)
print(mystr2)

'''result ...
ą ź ś ć ł ę
b'\xc4\x85 \xc5\xba \xc5\x9b \xc4\x87 \xc5\x82 \xc4\x99'
ą ź ś ć ł ę
'''

Just a note:
The IDLE or the improved VIDLE IDE seem to handle the foreign characters properly. Some other IDE's screw this up.

Edited by vegaseat

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.