[reportlab-users] converting entire text file

John Pywtorak reportlab-users@reportlab.com
Tue, 31 Aug 2004 12:58:02 -0700


On Friday 27 August 2004 06:44 pm, r2b2 wrote:
> How can i convert an entire text file to pdf?
> when i run my programs only 1 line of the text file i'm trying to convert
> to pdf is brought over. my text file is probably 20 lines or more yet when
> i run the program only one line is brought over and converted to pdf.
>
> from reportlab.pdfgen import canvas
>
> x = open("c:\compda37","r")
> whole_thing = x.read()
> x.close()
> def hello(c):
>     c.drawString(-160,825, whole_thing )
> c = canvas.Canvas("comppdf.pdf")
> hello(c)
> c.showPage()
> c.save
>

Ok, I am fairly sure you need to make multiple calls to drawString for each 
line in your text file and change your coordinates as you process each line.

However, text 2 pdf has been done by many.  ActiveStates ASPN has a recipe for 
it which does not require reportlab, also I think reportlab has an example 
script that does it.  If you really want to do this yourself read the users 
guide and look at the test cases that come with reportlab.

Johnny P

-- 
Windows
Start Here
Frustrating Hanging Crashing
Blue Screen of Death
Reboot