The pure Python PyFPDF library is a lightweight way to create PDFs including maps. Because the PDF format is a widely used standard, PDFs are commonly used to distribute maps. You can install it via PyPI as fpdf
. The official name of the software is PyFPDF because it is a part of the PHP language module called fpdf
. This module uses a concept called a cell to layout items at specific locations on a page. As a quick example, we'll import our hancock.png
image created from the PIL example into a PDF called map.pdf
to create a simple PDF map. The map will have the header text at the top that says Hancock County Boundary, followed by the map image:
>>> import fpdf >>> # PDF constructor: >>> # Portrait, millimeter units, A4 page size >>> pdf=fpdf.FPDF("P", "mm", "A4") >>> # create a new page >>> pdf.add_page() >>> # Set font: arial, bold, size 20 >>> pdf.set_font('Arial','B',20) >>> # Layout cell: 160 x 25mm...