Package mapnik :: Module printing :: Class PDFPrinter

Class PDFPrinter

Main class for creating PDF print outs, basically contruct an instance with appropriate options and then call render_map with your mapnik map

Instance Methods
 
__init__(self, pagesize=(0.21, 0.297), margin=0.005, box=None, percent_box=None, scale=<function default_scale at 0x102da5500>, resolution=72, preserve_aspect=True, centering=1, is_latlon=False, use_ocg_layers=False)
Creates a cairo surface and context to render a PDF with.
 
finish(self)
 
add_geospatial_pdf_header(self, m, filename, epsg=None, wkt=None)
Postprocessing step to add geospatial PDF information to PDF file as per PDF standard 1.7 extension level 3 (also in draft PDF v2 standard at time of writing)
 
get_context(self)
allow access so that extra 'bits' can be rendered to the page directly
 
get_width(self)
 
get_height(self)
 
get_margin(self)
 
write_text(self, ctx, text, box_width=None, size=10, fill_color=(0.0, 0.0, 0.0), alignment=None)
 
render_map(self, m, filename)
Render the given map to filename
 
render_on_map_lat_lon_grid(self, m, dec_degrees=True)
 
render_on_map_scale(self, m)
 
render_scale(self, m, ctx=None, width=0.05)
m: map to render scale for ctx: A cairo context to render the scale to.
 
render_legend(self, m, page_break=False, ctx=None, collumns=1, width=None, height=None, item_per_rule=False, attribution={}, legend_item_box_size=(0.015, 0.0075))
m: map to render legend for ctx: A cairo context to render the legend to.
Method Details

__init__(self, pagesize=(0.21, 0.297), margin=0.005, box=None, percent_box=None, scale=<function default_scale at 0x102da5500>, resolution=72, preserve_aspect=True, centering=1, is_latlon=False, use_ocg_layers=False)
(Constructor)

 
Creates a cairo surface and context to render a PDF with.

pagesize: tuple of page size in meters, see predefined sizes in pagessizes dict (default a4)
margin: page margin in meters (default 0.01)
box: box within the page to render the map into (will not render over margin). This should be 
     a Mapnik Box2d object. Default is the full page within the margin
percent_box: as per box, but specified as a percent (0->1) of the full page size. If both box
             and percent_box are specified percent_box will be used.
scale: scale helper to use when rounding the map scale. This should be a function that
       takes a single float and returns a float which is at least as large as the value
       passed in. This is a 1:x scale.
resolution: the resolution to render non vector elements at (in DPI), defaults to 72 DPI
preserve_aspect: whether to preserve map aspect ratio. This defaults to True and it
                 is recommended you do not change it unless you know what you are doing
                 scales and so on will not work if this is False.
centering: Centering rules for maps where the scale rounding has reduced the map size.
           This should be a value from the centering class. The default is to center on the
           maps constrained axis, typically this will be horizontal for portrait pages and
           vertical for landscape pages.
is_latlon: Is the map in lat lon degrees. If true magic anti meridian logic is enabled
use_ocg_layers: Create OCG layers in the PDF, requires pyPdf >= 1.13

add_geospatial_pdf_header(self, m, filename, epsg=None, wkt=None)

 

Postprocessing step to add geospatial PDF information to PDF file as per PDF standard 1.7 extension level 3 (also in draft PDF v2 standard at time of writing)

one of either the epsg code or wkt text for the projection must be provided

Should be called *after* the page has had .finish() called

render_scale(self, m, ctx=None, width=0.05)

 
m: map to render scale for
ctx: A cairo context to render the scale to. If this is None (the default) then
    automatically create a context and choose the best location for the scale bar.
width: Width of area available to render scale bar in (in m)

will return the size of the rendered scale block in pts

render_legend(self, m, page_break=False, ctx=None, collumns=1, width=None, height=None, item_per_rule=False, attribution={}, legend_item_box_size=(0.015, 0.0075))

 
m: map to render legend for
ctx: A cairo context to render the legend to. If this is None (the default) then
    automatically create a context and choose the best location for the legend.
width: Width of area available to render legend in (in m)
page_break: move to next page if legen over flows this one
collumns: number of collumns available in legend box
attribution: additional text that will be rendered in gray under the layer name. keyed by layer name
legend_item_box_size:  two tuple with width and height of legend item box size in meters

will return the size of the rendered block in pts