2.3 Drawing Operations: Need To See If It Really Works For All Tasks, and If Not Then Get Rid of It
2.3 Drawing Operations: Need To See If It Really Works For All Tasks, and If Not Then Get Rid of It
2.3 Drawing Operations: Need To See If It Really Works For All Tasks, and If Not Then Get Rid of It
If you have problems printing your document make sure you are using the right page size (usually either A4
or letter). Some printers do not work well with pages that are too large or too small.
Very often, you will want to calculate things based on the page size. In the example above we extracted the
width and height. Later in the program we may use the width variable to define a right margin as width -
inch rather than using a constant. By using variables the margin will still make sense even if the page size
changes.
The bottomup argument switches coordinate systems. Some graphics systems (like PDF and PostScript)
place (0,0) at the bottom left of the page others (like many graphical user interfaces [GUI's]) place the origin
at the top left. The bottomup argument is deprecated and may be dropped in future
Need to see if it really works for all tasks, and if not then get rid of it
The pageCompression option determines whether the stream of PDF operations for each page is
compressed. By default page streams are not compressed, because the compression slows the file generation
process. If output size is important set pageCompression=1, but remember that, compressed documents
will be smaller, but slower to generate. Note that images are always compressed, and this option will only
save space if you have a very large amount of text and vector graphics on each page.
The encoding argument is largely obsolete in version 2.0 and can probably be omitted by 99% of users. Its
default value is fine unless you very specifically need to use one of the 25 or so characters which are present
in MacRoman and not in Winansi. A useful reference to these is here:
http://www.alanwood.net/demos/charsetdiffs.html. The parameter determines which font encoding is used for
the standard Type 1 fonts; this should correspond to the encoding on your system. Note that this is the
encoding used internally by the font; text you pass to the ReportLab toolkit for rendering should always either
be a Python unicode string object or a UTF-8 encoded byte string (see the next chapter)! The font encoding
has two values at present: 'WinAnsiEncoding' or 'MacRomanEncoding'. The variable
rl_config.defaultEncoding above points to the former, which is standard on Windows, Mac OS X
and many Unices (including Linux). If you are Mac user and don't have OS X, you may want to make a
global change: modify the line at the top of reportlab/pdfbase/pdfdoc.py to switch it over. Otherwise, you can
probably just ignore this argument completely and never pass it. For all TTF and the commonly-used CID
fonts, the encoding you pass in here is ignored, since the reportlab library itself knows the right encodings in
those cases.
The demo script reportlab/demos/stdfonts.py will print out two test documents showing all code
points in all fonts, so you can look up characters. Special characters can be inserted into string commands
with the usual Python escape sequences; for example \101 = 'A'.
The verbosity argument determines how much log information is printed. By default, it is zero to assist
applications which want to capture PDF from standard output. With a value of 1, you will get a confirmation
message each time a document is generated. Higher numbers may give more output in future.
The encrypt argument determines if and how the document is encrypted. By default, the document is not
encrypted. If encrypt is a string object, it is used as the user password for the pdf. If encrypt is an
instance of reportlab.lib.pdfencrypt.StandardEncryption, this object is used to encrypt the
pdf. This allows more finegrained control over the encryption settings. Encryption is covered in more detail in
Chapter 4.
to do - all the info functions and other non-drawing stuff
Cover all constructor arguments, and setAuthor etc.
def hello(c):
from reportlab.lib.units import inch
# move the origin up and to the left
c.translate(inch,inch)
# define a large font
c.setFont("Helvetica", 14)
# choose some colors
Page 11