[reportlab-users] Combine DocTemplates into one PDF
Remy C. Cool
reportlab-users@reportlab.com
Tue, 16 Mar 2004 08:03:43 +0100
On Monday 15 March 2004 22:28, John Pywtorak wrote:
> 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.
The weird thing is that often when I post my question to a list, I
find the answer myself, and mostly within the hour :)
> 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.
The example was somewhat simplefied. For the firstPage I need two
frames, one for the address data and one for the content. The one for
the address data needs to be exactly positioned for the type of
envelope that's in use.
> 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.
Maybe it would be possible to use SimpleDocTemplate, but I don't want
to linit my program that's going to be extended later on.
Thanks for your input.
Remy
> 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
>
> _______________________________________________
> reportlab-users mailing list
> reportlab-users@reportlab.com
> http://two.pairlist.net/mailman/listinfo/reportlab-users