Skip to content

pagopa/pagopa-pdf-engine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

pagoPA Generate PDF function

Quality Gate Status

Java Azure Function that exposes REST API to generate a PDFA/2a document based on the provided data and HTML template.


Summary πŸ“–


API Documentation πŸ“–

See the OpenApi 3 here.


Technology Stack

  • Java 11
  • IText7
  • Handlebars
  • Zip4j

Start Project Locally πŸš€

Run locally with Docker

Prerequisites

  • docker

Run docker container

docker build -t pagopa-pdf-engine .

docker run -p 7071:80 pagopa-pdf-engine

Run locally with Maven

Prerequisites

  • maven

Run the project

mvn clean package

mvn azure-functions:run

Test

curl --location 'http://localhost:7071/generate-pdf' \
--header 'Ocp-Apim-Subscription-Key;' \
--form 'template=@"template.zip"' \
--form 'data="{
		\"transaction\": {
			\"id\": \"F57E2F8E-25FF-4183-AB7B-4A5EC1A96644\",
			\"timestamp\": \"2020-07-10 15:00:00.000\",
			\"amount\": 300.00,
			\"psp\": {
				\"name\": \"Nexi\",
				\"fee\": {
					\"amount\": 2.00
				}
			},
			\"rrn\": \"1234567890\",
			\"paymentMethod\": {
				\"name\": \"Visa *1234\",
				\"logo\": \"https://...\",
				\"accountHolder\": \"Marzia Roccaraso\",
				\"extraFee\": false
			},
			\"authCode\": \"9999999999\"
		},
		\"user\": {
			\"data\": {
				\"firstName\": \"Marzia\",
				\"lastName\": \"Roccaraso\",
				\"taxCode\": \"RCCMRZ88A52C409A\"
			},
			\"email\": \"[email protected]\"
		},
		\"cart\": {
			\"items\": [{
				\"refNumber\": {
					\"type\": \"codiceAvviso\",
					\"value\": \"123456789012345678\"
				},
				\"debtor\": {
					\"fullName\": \"Giuseppe Bianchi\",
					\"taxCode\": \"BNCGSP70A12F205X\"
				},
				\"payee\": {
					\"name\": \"Comune di Controguerra\",
					\"taxCode\": \"82001760675\"
				},
				\"subject\": \"TARI 2022\",
				\"amount\": 150.00
			}],
			\"amountPartial\": 300.00
		},
		\"noticeCode\": \"noticeCodeTest\",
		\"amount\": 100
	}"' \
--form 'applySignature="false"' \
--form 'generateZipped="false"'

As you can see in the provided curl the first field template hold a zip file. The zip file contains the HTML template file and other optional attachments, such as CSS files, that will be used to generate the PDF document.

Warning
The HTML template file must be named to match the value of the HTML_TEMPLATE_FILE_NAME environment variable (default is template) (example of HTML template file name: template.html)

Playwright version

In order to use the newly introduced engine you may use the parameter

...
--form 'generatorType="PLAYWRIGHT"'

The two values available are PLAYWRIGHT and ITEXT (the value defaults to ITEXT currently)


Develop Locally πŸ’»

Prerequisites

  • git
  • maven
  • jdk-11

Testing πŸ§ͺ

Unit testing

To run the Junit tests:

mvn clean verify

Integration testing

From ./integration-test/src

  1. yarn install
  2. yarn test

Performance testing

Contributors πŸ‘₯

Made with ❀️ by PagoPa S.p.A.

Maintainers

See CODEOWNERS file