Running the Docker Compose Stack
To get the system up and running, all you need is Docker and Docker Compose installed on your machine. All services are defined in the provided docker-compose.yml
file.
- Ensure all files are in the same directory: Make sure the
docker-compose.yml
file and then8n-workflow.json
file are located in the same folder. - Open your terminal and navigate to the project directory.
- Run the following command:
docker compose up -d
This command will build and start all the services (n8n, Gotenberg, nginx, and PHP-FPM) in detached mode, meaning they will run in the background.
Configuring n8n
The provided n8n-workflow.json
file contains a pre-built workflow. You just need to import it.
- Access the n8n UI: Open your web browser and navigate to
http://localhost:5678
. - Import the workflow:
- Click on the "Workflows" icon in the left sidebar.
- Click "New" -> "Import from File".
- Select the
n8n-workflow.json
file.
Activate the workflow: Once imported, click the "Active" toggle in the top-right corner to make the workflow live. The webhook will now be listening for incoming requests.
Generating a PDF
The workflow is triggered by an incoming HTTP POST request to a webhook. The request body should contain the data needed to populate the HTML template.
Webhook URL:
- You can find the exact webhook URL by opening the workflow in n8n and clicking on the "Webhook" node.
- The URL will look something like
http://[your-n8n-address]:5678/webhook/your-unique-id
.
Example Request:
You can use a tool like cURL or Postman to send a request. The data should be sent as a JSON payload in the request body.
- Endpoint:
POST /webhook/[your-unique-id]
- Headers:
Content-Type: application/json
Body (JSON):
{
"document": "Invoice",
"invoiceNumber": "INV-2023-001",
"clientName": "Acme Corp.",
"invoiceDate": "2023-10-26",
"items": [
{
"description": "Product Design",
"sku": "SF34RTD",
"quantity": 1,
"price": 500
},
{
"description": "Development",
"sku": "Y46SW34",
"quantity": 1,
"price": 1500
}
]
}
Expected Response:
- Upon a successful request, the webhook will respond with the generated PDF file. The
Content-Type
header will beapplication/pdf
, and the file content will be in the response body.
Troubleshooting
Containers not starting: Run
docker compose logs
to check the logs of each service for errors. This will help identify issues with specific containers.n8n not connecting to Gotenberg: Ensure the Gotenberg URL in the n8n workflow's HTTP Request node is correctly set. It should point to the Gotenberg service within the Docker network, which is typically
http://gotenberg:3000
.PDF is blank or has formatting issues:
- Check the PHP-FPM logs to see if there are any PHP errors during template rendering.
- Verify the data sent in the webhook request matches the variables expected by your PHP template.
For detailed information on creating and modifying the HTML/PHP templates, please refer to the templating.md file.