473,396 Members | 1,599 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Create a Multilanguage PDF in Python

Hi guys,

I'm disprate with the Pdf Unicode. I try to create a class using ufpdf
but some chars are not correct and now I would like try Python because
a friend tolds me that it's very powerful.
I need a simple script in Python that grab all Records from a MySql
table and print in the pdf file.

The languages stored in my db are about 25 and they are:
Greek English French Hungarian Italian Lithuanian Dutch Portuguese
Albanian
Czech Danish German Spanish Estonian Finnish Irish Latvian Maltese
Polish Romanian
Russian Slovene Slovak Swedish

Anyone can help me, please?
Thanks
Perseo

Aug 20 '06 #1
12 3266
"Perseo" <mt******@gmail.comwrites:
Hi guys,

I'm disprate with the Pdf Unicode. I try to create a class using ufpdf
but some chars are not correct and now I would like try Python because
a friend tolds me that it's very powerful.
I need a simple script in Python that grab all Records from a MySql
table and print in the pdf file.

The languages stored in my db are about 25 and they are:
Greek English French Hungarian Italian Lithuanian Dutch Portuguese
Albanian
Czech Danish German Spanish Estonian Finnish Irish Latvian Maltese
Polish Romanian
Russian Slovene Slovak Swedish
You can give reportlab [1] a try. It has support for TrueType fonts
and unicode translation using UTF-8. I used to use it for pdf files
with polish chars.

Some example code:

<code>
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.pdfgen import canvas

pdfmetrics.registerFont(TTFont('Verdana', 'Verdana.ttf'))
c = canvas.Canvas("pl.pdf")
c.setFont("Verdana", 12)
c.drawString(100, 600, "Witaj, wiecie!".decode("iso-8859-2").encode("utf-8"))
c.showPage()
c.save()
</code>
[1] http://www.reportlab.org/

--
HTH,
Rob
Aug 20 '06 #2
Hi Rob,

thank you for your answer, but I'm a newbie in Web application written
in Python. Now I try your suggestion ...

Thanks
Perseo
Rob Wolfe wrote:
"Perseo" <mt******@gmail.comwrites:
Hi guys,

I'm disprate with the Pdf Unicode. I try to create a class using ufpdf
but some chars are not correct and now I would like try Python because
a friend tolds me that it's very powerful.
I need a simple script in Python that grab all Records from a MySql
table and print in the pdf file.

The languages stored in my db are about 25 and they are:
Greek English French Hungarian Italian Lithuanian Dutch Portuguese
Albanian
Czech Danish German Spanish Estonian Finnish Irish Latvian Maltese
Polish Romanian
Russian Slovene Slovak Swedish

You can give reportlab [1] a try. It has support for TrueType fonts
and unicode translation using UTF-8. I used to use it for pdf files
with polish chars.

Some example code:

<code>
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.pdfgen import canvas

pdfmetrics.registerFont(TTFont('Verdana', 'Verdana.ttf'))
c = canvas.Canvas("pl.pdf")
c.setFont("Verdana", 12)
c.drawString(100, 600, "Witaj, wiecie!".decode("iso-8859-2").encode("utf-8"))
c.showPage()
c.save()
</code>
[1] http://www.reportlab.org/

--
HTH,
Rob
Aug 20 '06 #3
Hi again,

WORKS!!! I download all I need as python + reportlab. Only 2 questions:

1. I need all of this package? because it is 6Mb!
2. How can I connect my software with MySql. In my Hosting is present
the Python support but I don't thing that the MySQLdb is present. How
can I solve this little problem?

Thanks
Perseo
Rob Wolfe wrote:
"Perseo" <mt******@gmail.comwrites:
Hi guys,

I'm disprate with the Pdf Unicode. I try to create a class using ufpdf
but some chars are not correct and now I would like try Python because
a friend tolds me that it's very powerful.
I need a simple script in Python that grab all Records from a MySql
table and print in the pdf file.

The languages stored in my db are about 25 and they are:
Greek English French Hungarian Italian Lithuanian Dutch Portuguese
Albanian
Czech Danish German Spanish Estonian Finnish Irish Latvian Maltese
Polish Romanian
Russian Slovene Slovak Swedish

You can give reportlab [1] a try. It has support for TrueType fonts
and unicode translation using UTF-8. I used to use it for pdf files
with polish chars.

Some example code:

<code>
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.pdfgen import canvas

pdfmetrics.registerFont(TTFont('Verdana', 'Verdana.ttf'))
c = canvas.Canvas("pl.pdf")
c.setFont("Verdana", 12)
c.drawString(100, 600, "Witaj, wiecie!".decode("iso-8859-2").encode("utf-8"))
c.showPage()
c.save()
</code>
[1] http://www.reportlab.org/

--
HTH,
Rob
Aug 20 '06 #4

Perseo wrote:
Hi again,

WORKS!!! I download all I need as python + reportlab. Only 2 questions:

1. I need all of this package? because it is 6Mb!
I'm afraid you need all of it.
BTW My reportlab package is only 3MB... hmm strange.
2. How can I connect my software with MySql. In my Hosting is present
the Python support but I don't thing that the MySQLdb is present. How
can I solve this little problem?
You can install MySQLdb wherever you want. You need only to make
sure the module is in your PYTHONPATH.

HTH,
Rob

Aug 21 '06 #5
I can't upload in the PYTHONPATH but in a normal folder of our site.
Exist another way to do it?
Thanks

Rob Wolfe wrote:
Perseo wrote:
Hi again,

WORKS!!! I download all I need as python + reportlab. Only 2 questions:

1. I need all of this package? because it is 6Mb!

I'm afraid you need all of it.
BTW My reportlab package is only 3MB... hmm strange.
2. How can I connect my software with MySql. In my Hosting is present
the Python support but I don't thing that the MySQLdb is present. How
can I solve this little problem?

You can install MySQLdb wherever you want. You need only to make
sure the module is in your PYTHONPATH.

HTH,
Rob
Aug 21 '06 #6
Perseo wrote:
I can't upload in the PYTHONPATH but in a normal folder of our site.
Exist another way to do it?
PYTHONPATH is an environment variable. You can set it to arbitrary paths,
and python will look for module there, too. Or you modify sys.path before
you try the import.

Diez
Aug 21 '06 #7
Thanks I will try it.

Diez B. Roggisch wrote:
Perseo wrote:
I can't upload in the PYTHONPATH but in a normal folder of our site.
Exist another way to do it?

PYTHONPATH is an environment variable. You can set it to arbitrary paths,
and python will look for module there, too. Or you modify sys.path before
you try the import.

Diez
Aug 22 '06 #8
Nothing to do!
I enable test2.py and the folder with 777 permission and I write at the
top of the file the PYTHONPATH "#!/usr/bin/python" as you told me but
it doesn't works as well.

this is my organization:
www.domain.com/python/reportlab/ [all files]
www.domain.com/python/test2.py

<code>
#!/usr/bin/python

print "Content-Type: text/html\n\n"
print "Hello World"

from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.pdfgen import canvas

pdfmetrics.registerFont(TTFont('Verdana', 'Verdana.ttf'))
c = canvas.Canvas("pl.pdf")
c.setFont("Verdana", 12)
c.drawString(100, 600, "Witaj,
wiecie!".decode("iso-8859-2").encode("utf-8"))
c.showPage()
c.save()
</code>

The verdana font doesn't exist in the reportlab fonts folder. I try to
delete the rows where it is called like (registerFont, setFont) but
nothing to do.

any suggestion?!

Diez B. Roggisch wrote:
Perseo wrote:
I can't upload in the PYTHONPATH but in a normal folder of our site.
Exist another way to do it?

PYTHONPATH is an environment variable. You can set it to arbitrary paths,
and python will look for module there, too. Or you modify sys.path before
you try the import.

Diez
Aug 22 '06 #9

Perseo wrote:
Nothing to do!
I enable test2.py and the folder with 777 permission and I write at the
top of the file the PYTHONPATH "#!/usr/bin/python" as you told me but
it doesn't works as well.
#!/usr/bin/python is not PYTHONPATH. I think you should
read this:
http://docs.python.org/tut/node4.htm...00000000000000
The verdana font doesn't exist in the reportlab fonts folder. I try to
delete the rows where it is called like (registerFont, setFont) but
nothing to do.
Fonts are not part of reportlab package. You should find it
in your OS or in the net. You need to know what font do you want to
use.
any suggestion?!
Install reportlab package in your home directory, for example
/home/perseo/python/lib

and then in the shell write this:

export PYTHONPATH=/home/perseo/python/lib

and look here:
http://docs.python.org/tut/node8.htm...00000000000000

HTH,
Rob

Aug 23 '06 #10
PERFECT! Done! Thanks
Now I create a little file in pdf format but the data are in the MySql
database! :(
How can I connect to it?

Thanks for all suggestions
Perseo
Rob Wolfe wrote:
Perseo wrote:
Nothing to do!
I enable test2.py and the folder with 777 permission and I write at the
top of the file the PYTHONPATH "#!/usr/bin/python" as you told me but
it doesn't works as well.

#!/usr/bin/python is not PYTHONPATH. I think you should
read this:
http://docs.python.org/tut/node4.htm...00000000000000
The verdana font doesn't exist in the reportlab fonts folder. I try to
delete the rows where it is called like (registerFont, setFont) but
nothing to do.

Fonts are not part of reportlab package. You should find it
in your OS or in the net. You need to know what font do you want to
use.
any suggestion?!

Install reportlab package in your home directory, for example
/home/perseo/python/lib

and then in the shell write this:

export PYTHONPATH=/home/perseo/python/lib

and look here:
http://docs.python.org/tut/node8.htm...00000000000000

HTH,
Rob
Aug 23 '06 #11
It's too difficult for me, anyone can help me contact me thru chat or
something else, please. It drives me crazy!

Perseo wrote:
PERFECT! Done! Thanks
Now I create a little file in pdf format but the data are in the MySql
database! :(
How can I connect to it?

Thanks for all suggestions
Perseo
Rob Wolfe wrote:
Perseo wrote:
Nothing to do!
I enable test2.py and the folder with 777 permission and I write at the
top of the file the PYTHONPATH "#!/usr/bin/python" as you told me but
it doesn't works as well.
#!/usr/bin/python is not PYTHONPATH. I think you should
read this:
http://docs.python.org/tut/node4.htm...00000000000000
The verdana font doesn't exist in the reportlab fonts folder. I try to
delete the rows where it is called like (registerFont, setFont) but
nothing to do.
Fonts are not part of reportlab package. You should find it
in your OS or in the net. You need to know what font do you want to
use.
any suggestion?!
Install reportlab package in your home directory, for example
/home/perseo/python/lib

and then in the shell write this:

export PYTHONPATH=/home/perseo/python/lib

and look here:
http://docs.python.org/tut/node8.htm...00000000000000

HTH,
Rob
Aug 23 '06 #12
Hi Rob this is my code:

<code>
#!/usr/bin/python

import time, os, sys
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.pdfgen import canvas
from reportlab.lib.units import inch, cm
from reportlab.lib.pagesizes import A4

#precalculate some basics
top_margin = A4[1] - inch
bottom_margin = inch
left_margin = inch
right_margin = A4[0] - inch
frame_width = right_margin - left_margin

pdfmetrics.registerFont(TTFont('Verdana', 'verdana.ttf'))
canv = canvas.Canvas("test.pdf")

def drawPageFrame(mycanv):
mycanv.line(left_margin, top_margin, right_margin, top_margin)
mycanv.setFont('Verdana',12)
mycanv.drawString(left_margin, top_margin + 2, "Pdf Test")
mycanv.line(left_margin, top_margin, right_margin, top_margin)

mycanv.line(left_margin, bottom_margin, right_margin, bottom_margin)
mycanv.drawCentredString(0.5*A4[0], 0.5 * inch,
"Page %d" % mycanv.getPageNumber())

canv.setPageCompression(1)
drawPageFrame(canv)

#do some title page stuff
canv.setFont("Verdana", 36)
canv.drawCentredString(0.5 * A4[0], 7 * inch, "Pdf Test")

canv.setFont("Verdana", 18)
canv.drawCentredString(0.5 * A4[0], 5 * inch, "Test Staff")

canv.setFont("Verdana", 12)
tx = canv.beginText(left_margin, 3 * inch)
tx.textLine("This is a test to a PDF Exporting Tool")
canv.drawText(tx)
canv.showPage()

canv.save()

print "Content-Type: text/html\n\n"
print "<a href=\"test.pdf\">PDF Test</a>"

</code>
I would like to create a simple pdf splitted in two column with a
vertical row.

|
Όνομα, Επώνυμο | John, Malkovic
Διεύθυνση (1)| 11 Main Street, Athens 54640
| Thessaloniki Greece
Διεύθυνση (2)|
Τηλ*φωνο | 00302310886995
Διεύθυνση| jo****@otenet.gr
ηλεκτρονικού |
ταχυδρομείου |
Κινητό τηλ*φωνο | 00345353453453
Τόπος γ*ννησης | Thessaloniki
Χώρα | Greece
Υπηκοότητα | Greek
Ημερομηνία |
γ*ννησης |
Μητρική γλώσσα | Greek
Rob Wolfe wrote:
"Perseo" <mt******@gmail.comwrites:
Hi guys,

I'm disprate with the Pdf Unicode. I try to create a class using ufpdf
but some chars are not correct and now I would like try Python because
a friend tolds me that it's very powerful.
I need a simple script in Python that grab all Records from a MySql
table and print in the pdf file.

The languages stored in my db are about 25 and they are:
Greek English French Hungarian Italian Lithuanian Dutch Portuguese
Albanian
Czech Danish German Spanish Estonian Finnish Irish Latvian Maltese
Polish Romanian
Russian Slovene Slovak Swedish

You can give reportlab [1] a try. It has support for TrueType fonts
and unicode translation using UTF-8. I used to use it for pdf files
with polish chars.

Some example code:

<code>
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.pdfgen import canvas

pdfmetrics.registerFont(TTFont('Verdana', 'Verdana.ttf'))
c = canvas.Canvas("pl.pdf")
c.setFont("Verdana", 12)
c.drawString(100, 600, "Witaj, ¶wiecie!".decode("iso-8859-2").encode("utf-8"))
c.showPage()
c.save()
</code>
[1] http://www.reportlab.org/

--
HTH,
Rob
Aug 23 '06 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Mariano Lpez | last post by:
I'm trying to make a multilanguage website. When the user enters the site, I want to detect the language and automatically make a redirection. How can I do this? And how should I organize my data...
1
by: Tosch | last post by:
I have to write a multilanguage application with the following criteria: - The language code can be set in a config file or similar. I don't want .NET do decide which language to use. This way...
3
by: Olivier | last post by:
i need to create a multilinguage site and i need help : first i want to know what is the best and simple solution for a multilinguage site with plone 2? i want some tutorial, how to and if...
1
by: Andrew Smith | last post by:
Hi, does anybody know to program multilanguage website, which are dependend on the browsers language settings? Does anybody know a nice jumpstart for this? Thanks in advance for any advice...
8
by: Aftab Alam | last post by:
Hello All I wanted to know that how can I build an application which takes arabic or urdu input I mean when I type something in my applications edit box it writes arabic. please do let me know...
7
by: Mat | last post by:
I would like to build multilanguage applications -user may have options, in runtime to change the language(switch). -i may need to update languages (grammar..) without rebuild to applications. ...
15
by: AG | last post by:
I have seen the samples for multilanguage support regarding what is normally static content. Can anyone point me to a good sample for multilanguage support for dynamic content. Like a gridview...
1
by: paolob | last post by:
I need to provide multilanguage support to my application. I alredy writed a multilanguage test application, using VS6 and resource only dll. Now i'm using Visual Studio 2005, I find out that it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.