[reportlab-users] Implementation of drawImage anchoring
Andy Robinson
andy at reportlab.com
Wed Sep 3 02:44:52 EDT 2008
2008/8/22 Yoann Roman <yroman-reportlab at altalang.com>:
> I've been reading (and re-reading) the doc for drawImage in Canvas, and I'm
> pretty sure the implementation doesn't match what's described. To quote:
>
Yoann, I wasn't following this last week, but I have just read this thread
and I think you (and the docs) are right and our implementation is wrong.
This started out as a feature to align a VECTOR image within a box, using
our commercial PageCatcher library. Within RML, it was very convenient
to be able to say "draw 'logo.pdf' in a box on the page". We therefore tried
to add the corresponding extra arguments to our bitmap, open-source
drawImage code, but got it wrong and never eyeballed the results.
I attach the docstring from rlextra.pagecatcher.pagecatcher.drawPdfImage:
def drawPdfImage(fileName, canv, x=0, y=0, width=None, height=None,
preserveAspectRatio=False, pageNumber=0,
showBoundary=False,anchor='sw', boxType='MediaBox'):
"""Like a PDF version of canvas.drawImage...used by RML2PDF.
This is designed to make it easy to place EPS artwork by distilling
to PDF.
- it will use the PDF file's MediaBox to determine the 'image' size, unless
you explicitly request a different box such as the ArtBox in the boxType
parameter (drawings made in Illustrator may use this)
- if x and y are not set, it presumes 0
- if width and height are given, it will stretch and squeeze the image to
fit in the given rectangle.
- if width and height are NOT given, it will take the natural size
as defined
by the media box (or other box) of the PDF file
- if width and height are given and preserveAspectRatio is set, it will
shrink/grow the image to fit centered inside the defined box. Note that
it can only look at the bounding box of the EPS file and has no idea of
the visual shape of whatever logos or designs that might contain!
- showBoundary will draw a small line around the image box to help in
seeing what's going on.
"""
We will try to fix this and add a test case in the open source distro.
- Andy
More information about the reportlab-users
mailing list