[reportlab-users] positionate flowable in frame ?!
Andy Robinson
andy at reportlab.com
Thu Mar 27 05:08:16 EDT 2014
Hi Tamer,
Some basic concepts:
You don't precisely position things in a frame. If you want to
precisely position something (e.g. a table), then call wrap() to get
its size, and draw() to place it exactly where YOU want on the canvas.
Frames are supposed to consume from a list of content, moving
downwards automatically, and onto the next page, like a word
processor. The frame, not you, decides where to position your
flowables. Usually, just below the previous flowable.
Now for the details: paragraphs are usually the full width of the
frame, so horizontal alignment of "the whole object" does not apply.
But for something with a smaller width, like a table, all flowables
have a property hAlign. Tables also have a property 'colWidths'. so
you can do
myTable.colWidths = [100,50,50,50] #units in points
myTable.hAlign = 'CENTER' #or 'LEFT' or 'RIGHT'
and it will be positioned accordingly.
You will also find it very helpful to read the RML examples and user
guide on our site. It's a commercial product but the XML tags
correspond pretty much one-for-one to the underlying Python objects,
and it's well documented and full of visual examples, so you can see a
style you like and guess with 90% accuracy what Python properties you
need.
https://www.reportlab.com/software/documentation/
I hope this helps,
Andy
On 27 March 2014 04:33, Tamer Higazi <th982a at googlemail.com> wrote:
> Hi!
>
> I have red the Reportlab Guide, and I am not getting smart howto
> positionate Flowables in a frame.
> I have created a table, now I want to positionate the table to be
> aligned right, but don't know how.
>
> Is there a way to positionate flowables in a frame defining this with
> the X,Y position ?!
>
> And beside this proble, can somebody tell me how to set the cell's width ?!
>
> Thanks for your support....
>
>
> Tamer
>
>
>
> from reportlab.pdfgen.canvas import Canvas
> from reportlab.platypus import SimpleDocTemplate,
> Paragraph,Table,Frame,TableStyle
> from reportlab.lib.styles import getSampleStyleSheet
> from reportlab.lib.units import inch
> from reportlab.lib.pagesizes import A4
> from reportlab.lib.styles import getSampleStyleSheet
>
>
> class Invoice(object):
>
> def __init__(self):
> self.__styles = getSampleStyleSheet()
> self.__Canvas = Canvas("MyFile.pdf", pagesize=A4)
>
> #Header Frame
> #int(round(A4[1]/5,0))
>
> PPart = int(round(A4[1]/6,0))
>
> #Frame(x1, y1, width, height)
>
> #Logo Frame
> self.__LFrame = Frame(
> 30,A4[1]-PPart,
> A4[0]-60,PPart,
> leftPadding=0, bottomPadding=0, rightPadding=0,
> topPadding=0, showBoundary=0)
>
> self.__LFrame.addFromList([Table([[0,1],[0,1]])],self.__Canvas)
>
> #Header Frame
> self.__HFrame = Frame(
> 30,A4[1]-(PPart*2),
> A4[0]-60,PPart,
> leftPadding=0, bottomPadding=0, rightPadding=0,
> topPadding=0, showBoundary=0)
>
> #Body Frame
> self.__BFrame = Frame(
> 30,A4[1]-(PPart*5),
> A4[0]-60,PPart*3,
> leftPadding=0, bottomPadding=0, rightPadding=0,
> topPadding=0, showBoundary=0)
>
> #Footer Frame
> self.__FFrame = Frame(
> 30,A4[1]-(PPart*6),
> A4[0]-60,PPart,
> leftPadding=0, bottomPadding=0, rightPadding=0,
> topPadding=0, showBoundary=0)
>
> TableX = Table([['Rechnungsnr.:','2000'],['Kundennr.:','2000']])
>
> #Elemente setzen
> prg = Paragraph("This is a heading Part
> 1",self.__styles['Heading1'])
> prg2 = Paragraph("This is a heading, Part
> 2",self.__styles['Heading1'])
>
> self.__HFrame.addFromList([TableX],self.__Canvas)
>
> self.__Canvas.save()
>
> def __delete__(self):
> pass
>
> InvoiceX = Invoice()
> _______________________________________________
> reportlab-users mailing list
> reportlab-users at lists2.reportlab.com
> http://two.pairlist.net/mailman/listinfo/reportlab-users
--
Andy Robinson
Managing Director
ReportLab Europe Ltd.
Thornton House, Thornton Road, Wimbledon, London SW19 4NG, UK
Tel +44-20-8405-6420
More information about the reportlab-users
mailing list