[reportlab-users] Newbie - Basic BaseDocTemplate

Riaan Bekker riaan.bekker at kapabiosystems.com
Mon Jan 29 01:34:38 EST 2007




Tim,

____________________________________________________________________________

Yes it is Microsoft Great Plains.

I used the root directory for the example code I sent because giving my
directory structure over a mailing list is not a good idea.

I also know that I am adding to the list in the example where I am printing
to frames, that will give me a idea of how the wrapping is done.

Thanks for the advice on the "c:\r" I will remember that, in the real code
it is not an r, so does not affect me yet, but I will change it.

I did add a coaDocTemplate.build now, but I am still struggling to get it
going, will do some more work on it today, and then post again. This is
really a frustrating way to try and solve something, there is no where on
the web to find a good working basic example, and all the examples are based
on the easy SimpleDocTemplate, why when it comes to little more complex
stuff, all the documentation ENDS...

____________________________________________________________________________


Riaan Bekker wrote:

>

> I can not get my BaseDocTemplate example to work.

>

>

>

> If I move the BaseDocTemplate.__init__(self,name) after my variable

> declaration, it never gets executed, if I move it before my variable

> declaration, it never executes my variable declares. I am newbie to

> this, so still struggling with it.

>


What makes you think this is happening? I don't see anything in the
code that should cause this. I added "print self.fileName" at the end
of your __init__, and when I add a call to makeDocument(), the name
prints as expected.

The code you showed us doesn't actually create any content or generate
the PDF, so I couldn't test the whole thing.



> doc = coaDocTemplate("c:\riaan.pdf")

>


You probably don't realize that this is creating a file name with a
carriage return in it: \r. You need to do it one of these ways:
doc = coaDocTemplate("c:\\riaan.pdf")
doc = coaDocTemplate(r"c:\riaan.pdf")
doc = coaDocTemplate("c:/riaan.pdf")

You should probably get out of the habit of putting files in the root of
your hard disk. For organizational purposes, you should create
subdirectories to hold your development scripts and their data.

There's also another issue here:

data1 = []

par1 = Paragraph("This is to the left",styles['Normal'])
data1.append(par1)
self.frameLeft.addFromList(data1, self.canv)

par2 = Paragraph("This is to the middle",styles['Normal'])
data1.append(par2)
self.frameMiddle.addFromList(data1, self.canv)

par3 = Paragraph("This is to the right",styles['Normal'])
data1.append(par3)
self.frameRight.addFromList(data1, self.canv)


Notice that you never empty data1, so it just grows and grows. What you
pass to frameMiddle has both [par1,par2], and what you pass to
frameRight is [par1,par2,par3]. You can turn a paragraph into a list
like this:

par1 = Paragraph("This is to the left",styles['Normal'])
self.frameLeft.addFromList([par1], self.canv)

par2 = Paragraph("This is to the middle",styles['Normal'])
self.frameMiddle.addFromList([par2], self.canv)

par3 = Paragraph("This is to the right",styles['Normal'])
self.frameRight.addFromList([par3], self.canv)

But if you only want to pass one thing, there's no reason to use
addFromLlist. Instead:

par1 = Paragraph("This is to the left",styles['Normal'])
self.frameLeft.add(par1, self.canv)

par2 = Paragraph("This is to the middle",styles['Normal'])
self.frameMiddle.add(par2, self.canv)

par3 = Paragraph("This is to the right",styles['Normal'])
self.frameRight.add(par3, self.canv)



> I also did not get the self.canv variable before, but I hope with this

> kind of sub-classing that I can get hold of it and creaty my frames.

> Am I on the right track here ? I just want to do a page with 3 columns

> and the top and a detail section below that 2 columns, that is why I

> used 3 frames at the top, and 1 frame for the body. The body will

> contain some kind of grid to display row data, the top 3 frames will

> display data from static tables, but still needs to be populated from

> the database.

>


I suspect you are basically on the right track, especially if you have
data that needs to "flow" between the 2 columns. If it's just a bunch
of detail rows of fixed size, this may be more trouble than you really need.



> Where will be the best to populate the tables and grid? I am

> connecting to a postgre-sql DB and also to Microsoft GP.

>


"Microsoft GP"? Is that "Great Plains"?

--
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.

_______________________________________________
reportlab-users mailing list
reportlab-users at reportlab.com
http://two.pairlist.net/mailman/listinfo/reportlab-users



More information about the reportlab-users mailing list