How to set up PDF generation as a service task
Overview
The app can generate PDFs as a standard service task that you add as a step in the process.
Previously, this functionality was not in a service task but was built into the general code for changing process steps. If you set up the app before version 8.9, you should disable the functionality that runs outside the process definition.
You do this by turning off “enablePdfGeneration” on all data types.
Benefits of migrating to a service task:
- You can retry if PDF generation fails, without running “process next” again. This avoids unintended side effects.
- You can create multiple PDFs from one task, or combine multiple tasks into one PDF.
- In the future, PDF generation can run as a background job with automatic retries and better scaling.
Setup
You can use the Arbeidsflyt tab in Altinn Studio to add a PDF service task.
Drag and drop the PDF service task to where in the process you want to generate a PDF, often right after a data task.
Once you have placed the task, a configuration panel opens on the right side of the screen. There you choose between two approaches: standard or custom PDF.
Filename
Including <altinn:filenameTextResourceKey> is optional. Here you specify a text resource key to use as the filename, with support for languages and variables. If you omit it, the PDF uses the application name as the filename.
{
"id": "pdfFileName",
"value": "My filename {0}",
"variables": [
{
"key": "DataModelFieldName",
"dataSource": "dataModel.model"
}
]
}
dataModel.default. You must use the actual ID of the data model, e.g. dataModel.model.Testing
Fill out the form and proceed. When you reach the PDF service task in the workflow, the app generates the PDF and automatically proceeds to the next step in the process, for example the receipt.
Troubleshooting
If you get an error message that the service task failed during PDF generation, you can open the form in the app and add the query parameter pdf=1. You will then see the same content the PDF should have displayed, and any error messages.


