[reportlab-users] Combine DocTemplates into one PDF

John Pywtorak reportlab-users@reportlab.com
15 Mar 2004 13:28:17 -0800


Nice when you answer your own question.  I would add that the
SimpleDocTemplate is great and easier to use.  I started out extending
the base class BaseDocTemplate and later realizing that the simple
encapsulated what I needed.

Since your pagesize is not changing only the frame is I would opt toward
the simple as well.  BaseDocTemplate appears most useful when you want
multiple frames per page.  That way you can avoid Templates and Frame
objects that would automatically be handled by SimpleDocTemplate.

With SimpleDocTemplate you follow the same pattern:
doc = SimpleDocTemplate(...)
story = []
story.append(SomeFlowableLikeParagraph)
doc.build()

Using PageBreak, Table, and Paragraph flowables I think you can achieve
the same results.

Of course you might need more than what I see here.

John Pywtorak
Cal Poly

On Sun, 2004-03-14 at 07:43, Remy C. Cool wrote:
> On Saturday 13 March 2004 16:48, Remy C. Cool wrote:
> 
> > What I want to do is to create a mailing containing one or more
> > pages per client and store these into one single PDF file.
> >
> > So I will need a sort of MailingTemplate class or function which
> > holds the DocTemplate and generates the PDF using this DocTemplate
> > per client.
> >
> > def MailingTemplate(clientList, myDocTemplate):
> >
> > 	for client in clientList:
> > 		# retrieve client data from database
> > 		...
> > 		# create flowables
> > 		...
> > 		# use my DocTemplate to generate PDF data
> > 		...
> > 	# close PDF
> > 	...
> 
> Found the/one simple solution:
> 
> styles = getSampleStyleSheet() 
> styleN = styles['Normal'] 
> styleH = styles['Heading1'] 
> 
> frame_1 = Frame(inch, inch, 6*inch, 7*inch, showBoundary=1)
> frame_2 = Frame(inch, inch, 6*inch, 9*inch, showBoundary=1)
> 
> page_1 = PageTemplate(id='page_1',frames=[frame_1])
> page_2 = PageTemplate(id='page_2',frames=[frame_2])
> 
> story = []
> clients = range(5)
> partext = 'testing ' * 21
> 
> for client in clients:
>   story.append(NextPageTemplate('page_2'))
>   # append addres info here
>   story.append(Paragraph("Client %d address" % client, styleH))
>   # append content      
>   for i in range(50): 
>      story.append(Paragraph(partext, styleN))
>      if client != clients[-1]:
>         story.append(NextPageTemplate('page_1'))
>         story.append(PageBreak())
>         
> doc = BaseDocTemplate('mydoc.pdf',
>                       pagesize=letter,
>                       pageTemplates=[page_1, page_2]) 
> doc.build(story)
> 
> 
> Remy
> 
> _______________________________________________
> reportlab-users mailing list
> reportlab-users@reportlab.com
> http://two.pairlist.net/mailman/listinfo/reportlab-users