### Update Application Capabilities and Examples Source: https://github.com/mapfish/mapfish-print/blob/master/core/src/main/webapp/index.html Fetches and updates the available output formats and example requests for a selected application. ```javascript function updateApp() { var appId = $('#selectSpec').val(); $.ajax({ type: 'GET', url: 'print/' + appId + '/capabilities.json', success: function (data) { var i = 0; var formatSelect = $('#selectFormat'); formatSelect.empty(); var select = data.formats[0]; for (i = 0; i < data.formats.length; i++) { if (data.formats[i] === 'pdf') { select = data.formats[i]; } formatSelect.append(new Option(data.formats[i], data.formats[i])); } formatSelect.val(select); $('#spec').attr('action', 'print/' + appId + '/buildreport.' + select); var caps = $('#capabilities'); caps.attr('url', 'print/' + appId + '/capabilities.json?pretty=true'); }, }); $.ajax({ type: 'GET', url: 'print/' + appId + '/exampleRequest.json', dataType: 'Json', success: function (data) { var setExample = true; requestExamples = data; var exampleSelect = $('#selectExample'); exampleSelect.empty(); for (var att in data) { if (data.hasOwnProperty(att)) { exampleSelect.append(new Option(att, att)); if (setExample) { $('#specText').val(data[att]); validateJSON(); setExample = false; } } } }, }); } ``` -------------------------------- ### Build and Start Acceptance Test Composition Source: https://github.com/mapfish/mapfish-print/blob/master/README.md These commands build the project and start the Docker composition for running acceptance tests. ```bash make build cp docker-compose.override.sample.yaml docker-compose.override.yaml make acceptance-tests-up ``` -------------------------------- ### Install and Activate Pre-commit Hooks Source: https://github.com/mapfish/mapfish-print/blob/master/CONTRIBUTING.md Install the pre-commit tool and activate the hooks in your repository. This command should be run once per repository. ```bash sudo apt install pre-commit pre-commit install --allow-missing-config ``` -------------------------------- ### Basic Configuration Example Source: https://github.com/mapfish/mapfish-print/blob/master/docs/src/main/resources/templates/configuration.html Illustrates a basic configuration setting for error handling on extra parameters. ```yaml throwErrorOnExtraParameters: true ``` -------------------------------- ### Proxy Configuration Source: https://github.com/mapfish/mapfish-print/blob/master/docs/src/main/resources/templates/configuration.html Provides an example of setting up proxy configurations. ```yaml proxies: - !proxy ... ``` -------------------------------- ### Mapfish Print Template Configuration Example Source: https://github.com/mapfish/mapfish-print/blob/master/docs/src/main/resources/templates/jasperreports.html Example snippet from the 'config.yaml' file showing how to define a new template named 'A3 portrait'. This configuration tells Mapfish Print which report template to use and its associated attributes. ```yaml 3 A3 portrait: !template reportTemplate: Baselland_A3_Portrait.jrxml attributes: title: !string {} comment: !string {} map: maxDpi: 400 width: 802 height: 1033 ... ``` -------------------------------- ### Basic Input/Output Mapper Configuration Source: https://github.com/mapfish/mapfish-print/blob/master/docs/src/main/resources/templates/processors.html Example of configuring inputMapper and outputMapper for a processor when a single mapping is needed. ```yaml - !createMap inputMapper: {attributeName: defaultInputParamName} outputMapper: {defaultOutputName: templateParamName} ``` -------------------------------- ### Copy Example Request to Text Area Source: https://github.com/mapfish/mapfish-print/blob/master/core/src/main/webapp/index.html Copies a selected example request into the text area and validates the JSON. ```javascript function copyRequestToTextArea() { var att = $('#selectExample').val(); $('#specText').val(requestExamples[att]); validateJSON(); } ``` -------------------------------- ### Multiple Input/Output Mapper Configuration Source: https://github.com/mapfish/mapfish-print/blob/master/docs/src/main/resources/templates/processors.html Example of configuring inputMapper and outputMapper for a processor when multiple mappings are required. ```yaml - processorName inputMapper : attributeName1 : inputName1 attributeName2 : inputName2 ``` -------------------------------- ### Run Acceptance Tests (Standard) Source: https://github.com/mapfish/mapfish-print/blob/master/examples/README.md Execute the standard acceptance tests by first starting the test server, then running the tests, and finally stopping the server. ```bash make acceptance-tests-up make acceptance-tests-run make acceptance-tests-down ``` -------------------------------- ### Kubernetes Environment Variables for Database Credentials Source: https://github.com/mapfish/mapfish-print/blob/master/docs/src/main/resources/templates/scaling.html Example of how to set environment variables in Kubernetes to retrieve database credentials from a secret. ```yaml env: - name: PGHOST valueFrom: secretKeyRef: key: hostname name: database-credential-secret - name: PGPORT valueFrom: secretKeyRef: key: port name: database-credential-secret - name: PGUSER valueFrom: secretKeyRef: key: username name: database-credential-secret - name: PGPASSWORD valueFrom: secretKeyRef: key: password name: database-credential-secret - name: PGDATABASE valueFrom: secretKeyRef: key: database name: database-credential-secret - name: PGSCHEMA value: print - name: PGOPTIONS value: '-c statement_timeout=30000' - name: PRINT_POLL_INTERVAL value: '1' - name: CATALINA_OPTS value: >- -Ddb.host=$(PGHOST) -Ddb.port=$(PGPORT) -Ddb.username=$(PGUSER) -Ddb.password=$(PGPASSWORD) -Ddb.name=$(PGDATABASE) -Ddb.schema=$(PGSCHEMA) ``` -------------------------------- ### Prepare Table with Image Column Source: https://github.com/mapfish/mapfish-print/blob/master/docs/src/main/resources/templates/tableimages.html Example of configuring a table with an 'icon' column that contains image URLs. The `urlExtractor` is used to capture the URL. ```yaml ... - !prepareTable dynamic: true columns: icon: !urlImage # This interprets the text contained in the column icon as an image URL. urlExtractor: (. *) # Use Regex expression to retrieve the URL of the image in the text of the icon column. urlGroup: 1 ... ``` -------------------------------- ### Start MapFish Print in Debug Mode Source: https://github.com/mapfish/mapfish-print/blob/master/README.md This command starts the print service in debug mode, exposing the debugging port on 5005. ```bash docker compose up -d ``` -------------------------------- ### JasperReports Detail Band Example Source: https://github.com/mapfish/mapfish-print/blob/master/docs/src/main/resources/templates/tableimages.html An example snippet from a JasperReports JRXML file, showing a detail band with a text field configured to adjust height and handle blank values, typically used in conjunction with dynamic table generation. ```xml ... ``` -------------------------------- ### Get the capabilities for a print configuration Source: https://github.com/mapfish/mapfish-print/blob/master/docs/src/main/resources/templates/api.html Return the capabilities for a specific print configuration, including available layouts, formats, and email settings. ```APIDOC ## GET /:appId/capabilities.json ### Description Return the capabilities for a specific print configuration. ### Method GET ### Endpoint /:appId/capabilities.json ### Parameters #### Path Parameters - **appId** (string) - Required - The identifier of one of the available print configurations. ### Request Example Request URI: `GET /simple/capabilities.json` ### Response #### Success Response (200) - **Object**: Contains details about the print configuration, including `app`, `layouts`, `formats`, and `smtp` settings. ``` -------------------------------- ### Get Print Configuration Capabilities Source: https://github.com/mapfish/mapfish-print/blob/master/docs/src/main/resources/templates/api.html Retrieves the capabilities for a specific print configuration. The appId should be the identifier of an available print configuration. ```http GET /:appId/capabilities.json ``` -------------------------------- ### YAML Aliasing Example Source: https://github.com/mapfish/mapfish-print/blob/master/examples/src/test/resources/examples/config_aliases_defaults/README.md Illustrates declaring a YAML alias with '&' and dereferencing it with '*'. Changes to the aliased object affect all references. ```yaml maxDpi: &MAX_DPI 254 ref: *MAX_DPI ``` -------------------------------- ### Run Mapfish Print from Command-Line Source: https://github.com/mapfish/mapfish-print/blob/master/docs/src/main/resources/templates/download.html Execute a print task using the Mapfish Print command-line application. Ensure Java 7+ is installed. The script accepts configuration, request specifications, and an output file path. ```bash bin/print -config config.yaml -spec requestData.json -output out.pdf ``` -------------------------------- ### List Available Print Configurations Source: https://github.com/mapfish/mapfish-print/blob/master/docs/src/main/resources/templates/api.html Lists the identifiers of all print configurations available in the MapFish Print instance. This is a simple GET request to the /apps.json endpoint. ```http GET /apps.json ``` -------------------------------- ### List Available Fonts Source: https://github.com/mapfish/mapfish-print/blob/master/docs/src/main/resources/templates/api.html Lists all fonts installed in the Java Runtime on the server that can be used in Jasper Report Templates. ```APIDOC ## GET /fonts ### Description Lists fonts installed in Java Runtime on the server that can be used in Jasper Report Templates. ### Method GET ### Endpoint /fonts ### Response #### Success Response (200) A JSON array containing all the available font face names on the server. ``` -------------------------------- ### Submit Print Job (POST and Get) Source: https://github.com/mapfish/mapfish-print/blob/master/core/src/main/webapp/index.html Submits a print job using POST and initiates a process to download the report when ready. ```javascript function post() { var data = encodeURIComponent($('#specText').val()); var appId = $('#selectSpec').val(); var format = $('#selectFormat').val(); disableUI(true); var startTime = new Date().getTime(); $('#messages').text('Waiting for report...'); $.ajax({ type: 'POST', url: 'print/' + appId + '/report.' + format, data: data, success: function (data) { downloadWhenReady(startTime, data); }, error: function (data) { $('#messages').text('Error creating report: ' + data.statusText); disableUI(false); }, dataType: 'Json', }); } ``` -------------------------------- ### Example Git Commit Message Format Source: https://github.com/mapfish/mapfish-print/blob/master/CONTRIBUTING.md Follow this format for clear and concise Git commit messages. The header should be short and imperative, followed by a detailed body with proper word-wrapping. ```git Header line: explaining the commit in one line Body of commit message is a few lines of text, explaining things in more detail, possibly giving some background about the issue being fixed, etc etc. The body of the commit message can be several paragraphs, and please do proper word-wrap and keep columns shorter than about 74 characters or so. That way "git log" will show things nicely even when it's indented. Further paragraphs come after blank lines. ``` -------------------------------- ### Print Job Status Response Sample Source: https://github.com/mapfish/mapfish-print/blob/master/docs/src/main/resources/templates/api.html Example JSON response for a print job status request, indicating if the job is done, its current status, and timing information. ```json { "done": false, "status": "running", "elapsedTime": 507, "waitingTime": 0, "downloadURL": "/print/report/15179fee-618d-4356-8114-cfd8f146e273" } ``` -------------------------------- ### List Available Fonts Source: https://github.com/mapfish/mapfish-print/blob/master/docs/src/main/resources/templates/api.html Retrieves a list of all fonts installed on the server's Java Runtime. These fonts can be used in Jasper Report Templates. ```http GET /fonts ``` -------------------------------- ### Dynamic Table with Jasper Template and Image Column Source: https://github.com/mapfish/mapfish-print/blob/master/docs/src/main/resources/templates/tableimages.html Configure a dynamic table using a JasperReports template for styling. The 'icon' column is set to display images, with `urlExtractor` defining how to get the URL. ```yaml ... - !prepareTable excludeColumns: - not_shown_in_print # Columns that will not be shown in the printed table maxColumns: 8 dynamic: true jasperTemplate: table_a4_portrait.jrxml # - If dynamic is true this template will be used to obtain the column styles and the size of the subreport. firstDetailStyle: column_style_1 # - optional detailStyle: column_style_2 # - required when dynamic = true lastDetailStyle: column_style_3 # - optional firstHeaderStyle: header_style_1 # - optional headerStyle: header_style_2 # - required when dynamic = true lastHeaderStyle: header_style_3 # - optional columns: icon: !urlImage # This interprets the text contained in the column icon as an image URL. urlExtractor: (. *) # Use Regex expression to retrieve the URL of the image in the text of the icon column. urlGroup: 1 ... ``` -------------------------------- ### Initialize OpenLayers Map with Custom Projection Source: https://github.com/mapfish/mapfish-print/blob/master/core/src/test/resources/map-data/ol-demo.html Configures map options including a custom projection (EPSG:900913 for Spherical Mercator), units, max resolution, and bounds. This setup is crucial for integrating commercial map layers. ```javascript var options = { // the "community" epsg code for spherical mercator projection: 'EPSG:900913', // map horizontal units are meters units: 'm', // this resolution displays the globe in one 256x256 pixel tile maxResolution: 78271.51695, // these are the bounds of the globe in spherical mercator maxExtent: new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508), }; // construct a map with the above options map = new OpenLayers.Map('map', options); ``` -------------------------------- ### Example Map Attribute with Map Layers Source: https://github.com/mapfish/mapfish-print/blob/master/docs/src/main/resources/templates/layers.html This JSON snippet demonstrates how to define multiple map layers, including GeoJSON and OSM types, within the `map` attribute of a Mapfish Print request. It also shows other common map properties like projection, DPI, scale, and center. ```json { "attributes": { "map": { "layers": [ { "geoJson": "http://host.org/data.geojson", "type": "geojson" }, { "baseURL": "http://host.org/tiles", "type": "OSM", "imageExtension": "png" } ], "projection": "EPSG:3857", "dpi": 128, "scale": 100000, "center": [ -8233518.5005945, 4980320.4059228 ] } }, "layout": "A4 landscape" } ``` -------------------------------- ### Graceful Stop PreStop Hook in Kubernetes Source: https://github.com/mapfish/mapfish-print/blob/master/docs/src/main/resources/templates/docker.html Configure a preStop hook in Kubernetes to gracefully shut down the Mapfish Print container. This ensures that new jobs are not started and existing jobs are allowed to complete before the container is terminated. ```yaml lifecycle: preStop: exec: command: - /usr/local/tomcat/bin/docker-pre-stop-print - $(PRINT_TERMINATION_GRACE_PERIOD_SECONDS) ``` -------------------------------- ### Build Documentation Source: https://github.com/mapfish/mapfish-print/blob/master/docs/README.md Run this command in the project root to build the documentation website. The output will be placed in the docs/build/site folder. ```bash ./gradlew buildDocs ``` -------------------------------- ### Build MapFish Print Documentation Source: https://github.com/mapfish/mapfish-print/blob/master/README.md Run this command to specifically build the project documentation. ```bash > ./gradlew docs:build ``` -------------------------------- ### Credentials Configuration Source: https://github.com/mapfish/mapfish-print/blob/master/docs/src/main/resources/templates/configuration.html Demonstrates how to configure credentials within the YAML file. ```yaml credentials: - !credential ... ``` -------------------------------- ### Initialize Application Selection Source: https://github.com/mapfish/mapfish-print/blob/master/core/src/main/webapp/index.html Fetches the list of available print applications and populates the application selection dropdown. ```javascript function init() { $.ajax({ type: 'GET', url: 'print/apps.json', success: function (data) { data.sort(); var specSelect = $('#selectSpec'); for (var i = 0, len = data.length; i < len; i++) { specSelect.append(new Option(data[i], data[i])); } specSelect.val(data[0]); updateApp(); }, }); } ``` -------------------------------- ### Run Acceptance Tests (Context Path) Source: https://github.com/mapfish/mapfish-print/blob/master/examples/README.md For context path related tests, use the specified docker-compose file and the dedicated run command. ```bash DOCKER_COMPOSE_ARGS=--file=docker-compose-context-path.yaml make acceptance-tests-up DOCKER_COMPOSE_ARGS=--file=docker-compose-context-path.yaml make acceptance-tests-run-context-path DOCKER_COMPOSE_ARGS=--file=docker-compose-context-path.yaml make acceptance-tests-down ``` -------------------------------- ### Run MapFish Print with Command Line Options Source: https://github.com/mapfish/mapfish-print/blob/master/README.md Execute this command to run the MapFish printer with specified arguments, including help. ```bash > ./gradlew print -PprintArgs="-help" ``` -------------------------------- ### Open Capabilities Window Source: https://github.com/mapfish/mapfish-print/blob/master/core/src/main/webapp/index.html Opens a new window to display the print capabilities URL. ```javascript function openCapabilities() { var url = $('#capabilities').attr('url'); window.open(url, '_capabilities'); } ``` -------------------------------- ### Get Print Job Status Source: https://github.com/mapfish/mapfish-print/blob/master/docs/src/main/resources/templates/api.html Retrieves the current status of a print job. Use this to monitor progress and check for completion or errors. ```http GET /status/15179fee-618d-4356-8114-cfd8f146e273.json ``` -------------------------------- ### Run MapFish Print with Configuration and Output Source: https://github.com/mapfish/mapfish-print/blob/master/README.md This command runs the MapFish printer, specifying the configuration, request specification, and output file. ```bash > ./gradlew print -PprintArgs="-config ../examples/src/test/resources/examples/simple/config.yaml -spec ../examples/src/test/resources/examples/simple/requestData.json -output ./output.pdf" ``` -------------------------------- ### Run Acceptance Tests (Cluster Mode) Source: https://github.com/mapfish/mapfish-print/blob/master/examples/README.md To run acceptance tests in cluster mode using a PostgreSQL database, specify the appropriate docker-compose file using the DOCKER_COMPOSE_ARGS environment variable before executing the make commands. ```bash DOCKER_COMPOSE_ARGS=--file=docker-compose-cluster.yaml make acceptance-tests-up DOCKER_COMPOSE_ARGS=--file=docker-compose-cluster.yaml make acceptance-tests-run DOCKER_COMPOSE_ARGS=--file=docker-compose-cluster.yaml make acceptance-tests-down ``` -------------------------------- ### Get the status for a print job Source: https://github.com/mapfish/mapfish-print/blob/master/docs/src/main/resources/templates/api.html Returns the status for a print job using its reference ID. This should not be called if the report was requested to be sent by email. ```APIDOC ## GET /status/:referenceId.json ### Description Returns the status for a print job. ### Method GET ### Endpoint /status/:referenceId.json ### Parameters #### Path Parameters - **referenceId** (string) - Required - The reference id of a print job, which is returned when creating a job. ``` -------------------------------- ### Template Configuration Source: https://github.com/mapfish/mapfish-print/blob/master/docs/src/main/resources/templates/configuration.html Illustrates the configuration for defining print templates. ```yaml templates: A4 Landscape: !template ... ``` -------------------------------- ### Get Print Job Status Source: https://github.com/mapfish/mapfish-print/blob/master/docs/src/main/resources/templates/api.html Returns the status for a print job using its reference ID. This API should not be called if the report was requested via email. ```http GET /status/:referenceId.json ``` -------------------------------- ### Initialize OpenLayers Map with WMS and WFS Layers Source: https://github.com/mapfish/mapfish-print/blob/master/core/src/test/resources/map-data/wfs-t.html Sets up the OpenLayers map, adds WMS layers for political boundaries and water bodies, and WFS layers for roads and cities. WFS layers are configured for feature typename and namespace. ```javascript OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3; var map; function init() { map = new OpenLayers.Map('map'); var political = new OpenLayers.Layer.WMS('State', '/geoserver/wms', { layers: 'topp:tasmania_state_boundaries', format: 'image/png' }); var water = new OpenLayers.Layer.WMS('Water', '/geoserver/wms', { layers: 'topp:tasmania_water_bodies', transparent: 'true', format: 'image/png' }); var roads = new OpenLayers.Layer.WFS( 'Roads', '/geoserver/wfs', { typename: 'topp:tasmania_roads' }, { typename: 'tasmania_roads', featureNS: 'http://www.openplans.org/topp', extractAttributes: false } ); roads.style = OpenLayers.Util.applyDefaults({ strokeColor: '#ff0000' }, OpenLayers.Feature.Vector.style['default']); var cities = new OpenLayers.Layer.WFS( 'Cities', '/geoserver/wfs', { typename: 'topp:tasmania_cities' }, { typename: 'tasmania_cities', featureNS: 'http://www.openplans.org/topp', extractAttributes: false } ); cities.style = OpenLayers.Util.applyDefaults({ strokeColor: '#0000ff' }, OpenLayers.Feature.Vector.style['default']); map.addLayers([political, water, roads, cities]); ``` -------------------------------- ### Build MapFish Print Artifacts Source: https://github.com/mapfish/mapfish-print/blob/master/README.md Execute this command to build the WAR and JAR artifacts for MapFish Print. ```bash > make build ``` -------------------------------- ### Multiple Image Columns Configuration Source: https://github.com/mapfish/mapfish-print/blob/master/docs/src/main/resources/templates/tableimages.html Configure multiple columns ('Icon' and 'Image') to display images within the same or different tables. Each column uses `!urlImage` with its own `urlExtractor`. ```yaml ... - !prepareTable excludeColumns: - not_shown_in_prinit # Columns that will not be shown in the printed table maxColumns: 10 dynamic: true jasperTemplate: table_a4_portrait.jrxml detailStyle: column_style_2 headerStyle: header_style_2 columns: Icon: !urlImage # Declare the column icon to contain an image urlExtractor: (. *) urlGroup: 1 Image: !urlImage # Declare the column image to contain an image urlExtractor: (. *) urlGroup: 1 ... ``` -------------------------------- ### Certificate Store Configuration Source: https://github.com/mapfish/mapfish-print/blob/master/docs/src/main/resources/templates/configuration.html Shows the structure for defining a certificate store in the configuration. ```yaml certificateStore: !certificateStore ... ``` -------------------------------- ### Remove North Arrow Configuration from config.yaml Source: https://github.com/mapfish/mapfish-print/blob/master/docs/src/main/resources/templates/jasperreports.html Example of removing configuration for a north arrow from the 'config.yaml' file. This is part of the process when removing subreports like the north arrow from a template. ```yaml northArrow: !northArrow, size: 51 ``` -------------------------------- ### Generate Eclipse Project Metadata Source: https://github.com/mapfish/mapfish-print/blob/master/README.md Run this command to generate the necessary Eclipse project metadata for importing the project into Eclipse. ```bash > ./gradlew eclipse ``` -------------------------------- ### List available print configurations Source: https://github.com/mapfish/mapfish-print/blob/master/docs/src/main/resources/templates/api.html Lists the identifiers of all print configurations that are available in the MapFish Print instance. ```APIDOC ## GET /apps.json ### Description Lists the identifiers of all print configurations that are available in the MapFish Print instance. ### Method GET ### Endpoint /apps.json ### Response #### Success Response (200) - **Array of strings**: List of available print configuration identifiers (e.g., ["simple", "default"]) ``` -------------------------------- ### Get Print Job Status Source: https://github.com/mapfish/mapfish-print/blob/master/docs/src/main/resources/templates/api.html Retrieves the current status of a print job, including whether it's done, its status (waiting, running, finished, canceled, error), elapsed time, waiting time, and potential error messages or download URLs. ```APIDOC ## GET /status/:referenceId.json ### Description Retrieves the current status of a print job. ### Method GET ### Endpoint /status/:referenceId.json ### Parameters #### Path Parameters - **referenceId** (string) - Required - The unique identifier of the print job. ### Response #### Success Response (200) - **done** (boolean) - Indicates if the print job has finished. - **status** (string) - The current status of the job (waiting, running, finished, canceled, error). - **elapsedTime** (integer) - The elapsed time in ms since the job started. - **waitingTime** (integer) - Estimated time in ms the job has to wait in the queue (only when status is 'waiting'). - **error** (string) - An error message, if an error occurred. - **downloadURL** (string) - The URL to download the report once the job is finished. ### Response Example { "done": false, "status": "running", "elapsedTime": 507, "waitingTime": 0, "downloadURL": "/print/report/15179fee-618d-4356-8114-cfd8f146e273" } ``` -------------------------------- ### Download Report When Ready Source: https://github.com/mapfish/mapfish-print/blob/master/core/src/main/webapp/index.html Periodically checks the status of a print job and initiates download upon completion, with a timeout. ```javascript function downloadWhenReady(startTime, data) { if (new Date().getTime() - startTime > 30000) { $('#messages').text('Gave up waiting after 30 seconds'); disableUI(false); } else { updateWaitingMsg(startTime, data); setTimeout(function () { $.getJSON( data.statusURL, function (statusData) { if (!statusData.done) { downloadWhenReady(startTime, data); } else { window.location = statusData.downloadURL; $('#messages').text('Downloading: ' + data.ref); disableUI(false); } }, function error(data) { $('#messages').text('Error occurred requesting status'); } ); }, 500); } } ``` -------------------------------- ### Create Print Job and Download Report Source: https://github.com/mapfish/mapfish-print/blob/master/docs/src/main/resources/templates/api.html Triggers the creation of a print job and downloads the report. This method is not recommended for high concurrency as it can strain server resources. ```http POST /simple/buildreport.pdf ``` -------------------------------- ### Create Print Job and Download Report Source: https://github.com/mapfish/mapfish-print/blob/master/docs/src/main/resources/templates/api.html Triggers the creation of a print job and downloads its report. Note that in a cluster environment, the job might be processed by a different server. This method is not recommended for high concurrency. ```APIDOC ## POST /:appId/buildreport.:format ### Description Triggers the creation of a print job and downloads its report. This method is not recommended for high concurrency. ### Method POST ### Endpoint /:appId/buildreport.:format ### Parameters #### Path Parameters - **appId** (string) - Required - The identifier of the print configuration. - **format** (string) - Required - The desired output format (e.g., pdf, png). ### Request Body Refer to the [Create a print job](#create) request sample for the request body structure. ``` -------------------------------- ### Configure Java Run Configuration in Eclipse Source: https://github.com/mapfish/mapfish-print/blob/master/README.md These are the settings for a Java Run Configuration in Eclipse to run MapFish Print from the IDE. ```java -config samples/config.yaml -spec samples/spec.json -output $HOME/print.pdf ``` -------------------------------- ### Add Map Controls and Set Initial Extent Source: https://github.com/mapfish/mapfish-print/blob/master/core/src/test/resources/map-data/ol-demo.html Adds LayerSwitcher and MousePosition controls to the map and zooms the map to a predefined extent for the US. This sets up essential user interaction and initial view. ```javascript map.addControl(new OpenLayers.Control.LayerSwitcher()); map.addControl(new OpenLayers.Control.MousePosition()); var usBounds = new OpenLayers.Bounds(-14392000, 2436200, -7279500, 6594375); map.zoomToExtent(usBounds); ``` -------------------------------- ### Print Job Creation Response Source: https://github.com/mapfish/mapfish-print/blob/master/docs/src/main/resources/templates/api.html The response after creating a print job, containing a reference ID, status URL, and download URL for the report. ```json { "ref": "15179fee-618d-4356-8114-cfd8f146e273@3067ade6-0768-4fc6-b41d-40422d0cdb8b", "statusURL": "/print/status/15179fee-618d-4356-8114-cfd8f146e273.json", "downloadURL": "/print/report/15179fee-618d-4356-8114-cfd8f146e273" } ``` -------------------------------- ### Provide Attributes in request.json Source: https://github.com/mapfish/mapfish-print/blob/master/docs/src/main/resources/templates/attributes.html Supply attribute values in the 'attributes' section of the JSON request, matching the names and types defined in the configuration. ```json { "layout": "A4 portrait", "outputFormat": "pdf", "attributes": { "number": 45, "title": "The map", "description": "A map showing...", "map": { "bbox": [100, -1, 106, 2], "projection": "CRS:84", "dpi": 72, ... } } } ``` -------------------------------- ### Submit Print Job (POST Only) Source: https://github.com/mapfish/mapfish-print/blob/master/core/src/main/webapp/index.html Submits a print job using POST and schedules it without waiting for immediate download. ```javascript function postOnly() { var data = encodeURIComponent($('#specText').val()); var appId = $('#selectSpec').val(); var format = $('#selectFormat').val(); disableUI(true); var startTime = new Date().getTime(); $('#messages').text('Scheduling the job...'); $.ajax({ type: 'POST', url: 'print/' + appId + '/report.' + format, data: data, success: function (data) { $('#messages').text('Job scheduled'); disableUI(false); }, error: function (data) { $('#messages').text('Error creating report: ' + data.statusText); disableUI(false); }, dataType: 'Json', }); } ``` -------------------------------- ### Basic Image URL Extraction Source: https://github.com/mapfish/mapfish-print/blob/master/docs/src/main/resources/templates/tableimages.html Configure a table column to interpret its content as an image URL using a regular expression. The `urlExtractor` filters the URL from potentially more complex text. ```yaml ... icon: !urlImage urlExtractor: (. *) # Use regular expression (regex) to retrieve the URL of the image in the text of the icon column. urlGroup: 1 ... ``` -------------------------------- ### Run MapFish Print in Debug Mode with JVM Debugging Source: https://github.com/mapfish/mapfish-print/blob/master/README.md This command runs the MapFish printer with JVM debugging enabled, along with configuration and output parameters. ```bash > ./gradlew print --debug-jvm -PprintArgs="-config ../examples/src/test/resources/examples/simple/config.yaml -spec ../examples/src/test/resources/examples/simple/requestData.json -output ./output.pdf" ``` -------------------------------- ### Update Online Documentation Repository Source: https://github.com/mapfish/mapfish-print/blob/master/docs/README.md These commands are used to update the gh-pages branch of the mapfish-print-doc repository with the newly built documentation. Ensure you are in the mapfish-print-doc directory. ```bash cd mapfish-print-doc git fetch origin git checkout gh-pages git merge --ff-only origin/gh-pages git rm --ignore-unmatch -rqf . cp -r ../mapfish-print/docs/build/site/. . git add -A . git commit -m 'Update docs' git push origin gh-pages ``` -------------------------------- ### Define Attributes in config.yaml Source: https://github.com/mapfish/mapfish-print/blob/master/docs/src/main/resources/templates/attributes.html Declare attributes with their types (e.g., integer, string, map) within the !template block in your configuration YAML. ```yaml templates: A4 portrait: !template reportTemplate: simpleReport.jrxml attributes: number: !integer {} title: !string {} description: !string {} map: !map height: 200 width: 400 ``` -------------------------------- ### Display a Parameter using a TextField Source: https://github.com/mapfish/mapfish-print/blob/master/docs/src/main/resources/templates/jasperreports.html Embed a parameter's value into a report using a element with a that references the parameter. ```xml ``` -------------------------------- ### Create a print job Source: https://github.com/mapfish/mapfish-print/blob/master/docs/src/main/resources/templates/api.html Send a print request to create a print job. The report can be generated in various formats and optionally sent via email. ```APIDOC ## POST /:appId/report.:format ### Description Send a print request to create a print job. ### Method POST ### Endpoint /:appId/report.:format ### Parameters #### Path Parameters - **appId** (string) - Required - The identifier of one of the available print configurations. - **format** (string) - Required - One of the formats supported by the specified print configuration (e.g. `pdf` or `png`). #### Request Body - **Object** - The print request, either as JSON or form-encoded in the `spec` field. - **layout** (string) - Required - One of the available layouts of the specified print configuration. - **attributes** (Object) - Required - A list of attributes that are required by the specified layout. - **smtp** (Object) - Optional - Email settings if the report must be sent by email. - **to** (string) - Required - Recipient email address. - **subject** (string) - Optional - The email subject. - **body** (string) - Optional - The email body (HTML is supported). ### Request Example Request URI: `POST /simple/report.pdf` Request body: ```json { "layout": "A4 Portrait", "attributes": { "map": { "center": [ 957352.8034848921, 5936844.140278816 ], "dpi": 72, "layers": [ ... ], "projection": "EPSG:3857", "rotation": 0, "scale": 25000 }, "scalebar": { "projection": "EPSG:21781" }, "title": "Sample Print" } } ``` ### Response #### Success Response (200) - **Object**: Contains the print job reference and URLs. - **ref** (string) - A reference id for the print job. - **statusURL** (string) - The URL to request the status of the print job. - **downloadURL** (string) - The URL to download the finished report. #### Response Example ```json { "ref": "15179fee-618d-4356-8114-cfd8f146e273@3067ade6-0768-4fc6-b41d-40422d0cdb8b", "statusURL": "/print/status/15179fee-618d-4356-8114-cfd8f146e273.json", "downloadURL": "/print/report/15179fee-618d-4356-8114-cfd8f146e273" } ``` ``` -------------------------------- ### Execute MapFish Print within Docker Composition Source: https://github.com/mapfish/mapfish-print/blob/master/README.md This command executes the MapFish printer within the Docker composition environment, specifying configuration and output paths. ```bash docker compose exec builder gradle print -PprintArgs="-config /src/examples/src/test/resources/examples/simple/config.yaml -spec /src/examples/src/test/resources/examples/simple/requestData.json -output /src/examples/output.pdf" ``` -------------------------------- ### Mapfish Print Parameters Requiring Prompting Disabled Source: https://github.com/mapfish/mapfish-print/blob/master/docs/src/main/resources/templates/jasperreports.html List of parameters that must have 'isForPrompting' set to 'false' for proper Mapfish Print functionality. Ensure these are configured correctly in your JasperReports template. ```text mapContext mapSubReport numberOfTableRows tableSubReport tableDataSource numberOfLegendRows legend scalebarSubReport orthArrowSubReport ``` -------------------------------- ### Download Report Source: https://github.com/mapfish/mapfish-print/blob/master/docs/src/main/resources/templates/api.html Downloads a finished print job report. The report format is determined by the format requested when the job was created. ```APIDOC ## GET /report/:referenceId ### Description Downloads a finished print job report. ### Method GET ### Endpoint /report/:referenceId ### Parameters #### Path Parameters - **referenceId** (string) - Required - The reference id of the print job. ### Response Returns the report in the format that was requested when created the print job. ``` -------------------------------- ### Request Print Job (PDF) Source: https://github.com/mapfish/mapfish-print/blob/master/docs/src/main/resources/templates/api.html Submits a print request to create a print job for a PDF report. The POST body must be a JSON-encoded print request specifying layout and attributes. ```http POST /simple/report.pdf ``` ```json { "layout": "A4 Portrait", "attributes": { "map": { "center": [ 957352.8034848921, 5936844.140278816 ], "dpi": 72, "layers": [ ... ], "projection": "EPSG:3857", "rotation": 0, "scale": 25000 }, "scalebar": { "projection": "EPSG:21781" }, "title": "Sample Print" } } ``` -------------------------------- ### Download Finished Print Job Report Source: https://github.com/mapfish/mapfish-print/blob/master/docs/src/main/resources/templates/api.html Downloads a completed print job report. The report format is determined by the request made when the job was created. ```http GET /report/15179fee-618d-4356-8114-cfd8f146e273 ``` -------------------------------- ### Set PDF Font for a Static Text Element Source: https://github.com/mapfish/mapfish-print/blob/master/docs/src/main/resources/templates/jasperreports.html Configure the PDF font for a static text element directly in the source code. Ensure a valid PDF font name is used. ```xml ```