[reportlab-users] Wrong characters displayed with AcrobatReader

Paolo G. Cantore paolo.cantore at t-online.de
Tue Apr 8 14:27:23 EDT 2008


Dear Robin,

thanks to your code snippet I started a longer test session this
afternoon and "Eureka, eureka" I got it.

It was deep inside my definitions of a derived canvas class.

When I deleted the function _escape (for pdf escapes) all worked as
expected.

def _escape(s): # masquerading of ( and )
>> s = s.replace("(", "\(")
>> s = s.replace(")", "\)")
>> return s

I introduced this function a long time ago (199x) to produce correct pdf
documents due to a suggestion from Reportlab experts. I don't know if
this function is still needed for normal pdf generation.

Is the pdf generation okay without the _escape function?

Thanks a lot to you and the others for your help
--
Paolo


Robin Becker wrote:

> Paolo G. Cantore wrote:

>> Dear all,

>>

>> I want to use Reportlab for generating PDF documents with TrueType

>> fonts including thai, chinese, japanese and korean characters / graphs.

>>

>> My tests look very promising as I am able to generate PDFs which are

>> displayed and printed correctly with xpdf or evince (standard viewer

>> for Gnome). But to my absolute surprise the same PDFs are not

>> displayed correctly with AcrobatReader. There must be an astonishing

>> algorithm implemented in AcrobatReader which converts in a random

>> manner one character into another in the whole document.

>>

>> Please try to open the attached PDF with AdobeReader and you'll see

>> what I mean. In the PDF all "c" characters are converted to "Y"

>> characters (Certificate ==> CertifiYate). In other cases I had "a"

>> converted to "7". When you open the PDF with xpdf or other viewers

>> all is okay.

>>

>> The font used is Norasi (UTF-8 unicode) but the same applies to

>> Cyberbit.

>>

>> Is this a known behaviour of AcrobatReader?

>> Am I doing something wrong?

>> Do you have any suggestions or work around how to avoid this

>> displaying problem?

>>

>> Thank you!

> .......

> Paulo we use acrobat reader with Asian characters so I don't think

> it's just acrobat. Your PDF didn't arrive so perhaps you forgot to

> attach or it's too big.

>

> Don't send to the list if it's huge send it me direct and I'll take a

> look. Since you mention evince I guess you're linux/bsd alike.

>

> As for the problem itself it seems very strange. Presumably you're

> passing utf8 into the string drawing code after mentioning that you're

> using a particular font. We use an automatic subsetting scheme (by

> Marius Gedminas) to avoid embedding the whole font, but I believe the

> default is to assume the first 128 characters are used (which makes

> european text reasonable).

>

> If you want to do some simple experiments can you try stuff really

> simply ie this does work in windows acrobat. Use your font and see how

> the results are?

>

> ##########################################

> from reportlab import rl_config

> rl_config.pageCompression = 0

> rl_config.invariant = 1

> from reportlab.pdfgen.canvas import Canvas

> from reportlab.pdfbase.pdfmetrics import registerFont

> from reportlab.pdfbase.ttfonts import TTFont

> registerFont(TTFont('testfont',r'\WINDOWS\Fonts\msmincho.ttc'))

> c = Canvas('testfont.pdf')

> c.setStrokeColor((1,0,0))

> c.setFillColor((0,0,1))

> c.setLineWidth(0.5)

> c.setFont('testfont',10,12)

> for i,s in enumerate((

> 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',

> 'abcdefghijklmnopqrstuvwxyz',

> '0123456789',

> u'\u5974\u5a41\u5b17',

> )):

> c.drawString(72,7*72-i*12,s)

> c.showPage()

> c.save()

> ##########################################




More information about the reportlab-users mailing list