I am playing with mapnik and trying to export multiple vector files as one pdf with multiple layers.

For the moment, my vectors get merged when rendering. Is there a way to keep each vector in a separate layer of my rendered pdf?

1 Answer 1


That's actually easier than what I expected.

The PDFPrinter needs to have its use_ocg_layers parameter set to True. The .finish() method implicitly calls the convert_pdf_pages_to_layers() method if use_ocg_layers is True.

The code looks like this in Python:

page = mapnik.printing.PDFPrinter(use_ocg_layers=True)
m = mapnik.Map(100,100) 
mapnik.load_map(m, "my.xml", True) 
page.render_map(m, "my.pdf")
page.finish()   # implicitly calls convert_pdf_pages_to_layers()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.