PDF Map Generation as Headless Chrome Service
07-18, 14:30–15:00 (Europe/Sarajevo), SA01

Summary

In the context of a project for Swisstopo, the Federal Office of Topography of Switzerland, we analyzed the current technological landscape for generating PDF files for print from vector tile-based maps in online map services. One of our main goals was to identify potential technology stacks supporting full backend rendering, full frontend rendering, or hybrid approaches. While testing various options, we developed a universal print backend based on Headless Chrome, Puppeteer and Node, which corresponds to a full backend rendering approach and ultimately became our main focus. We will present our findings about the various options we have identified and elaborate in more detail on the developed print backend by presenting technical details as well as test results regarding performance, stability and quality.

Description

The demand for generating PDF files (e.g., for print) from online map services remains strong. Given the opportunities offered by vector tile-based maps and their resulting widespread adoption, particularly Mapbox Vector Tiles, providing this functionality in the context of web applications presents technical challenges that reveal shortcomings of existing solutions (e.g., mapfish print) and call for new approaches.\
By analyzing and testing well-established technologies, we identified several issues leading to unsatisfactory map renderings and PDF outputs. Some flaws are subtle, such as text cut-offs at tile seams, while others result in entirely unusable outputs, such as difficulties handling transparent layers.
To address these shortcomings, we developed an alternative approach by delegating both map rendering and PDF generation to a Headless Chrome instance controlled by Puppeteer, running inside a dedicated Node.js Docker container. This solution offers significant flexibility in choosing the rendering engine (e.g., MapLibre GL JS or OpenLayers) and defining the print frame (a simple HTML page with a map canvas for displaying raw maps is sufficient but can be extended with custom elements as required). \
Furthermore, by explicitly adding GPU support to the container, which is not available by default, we achieved good performance in map rendering and PDF generation while ensuring the same rendering quality as in the online map display.

Key Points

The primary factors motivating our choice of this setup included:
- Identical map display as online with MapLibre GL (WYSIWYG – What You See Is What You Get)
- Stability of the server even under heavy load
- Scalability on AWS server
- Maximum flexibility for layout design, defined directly in HTML

Optimizations crucial for performance:
- GPU support
- Caching

Comparative analysis of:
- Conventional services (MapFish Print)
- TileServer GL
- Frontend-based solutions (InkMap)


Indicate what is (are) the open source project(s) essential in your talk Assign a number between 1 and 3 indicating the level of technical complexity of your contribution.

2 - background knowledge helpful

Select at least one general theme that best defines your proposal

State of software, or new features

I make my conference contribution available under the CC BY 4.0 license. The conference contribution comprises the abstract, the text contribution for the conference proceedings, the presentation materials as well as the video recording and live transmission of the presentation – yes

MSc in Computer Science from the University of Bern, Switzerland

6 years of experience as Software Engineer
Since May 2024 I have been working as Software Engineer in the Geospatial Department of Camptocamp SA, Switzerland

This speaker also appears in: