Quickstart
On this page you start the service, send it a Word template and some JSON, and get back a filled invoice as a PDF. You need Docker and curl.
Start the service
Section titled “Start the service”docker run -d --name rusticdoc \ --read-only --cap-drop ALL --security-opt no-new-privileges \ --tmpfs /tmp --tmpfs /home/rusticdoc:uid=1001,gid=1001 \ -p 127.0.0.1:9027:9027 ghcr.io/vmosoti/rusticdoc:0.1.0With no credentials configured, the service answers anyone who can reach it. The -p 127.0.0.1: part keeps it on your machine. Install explains the other flags.
Check that it is up:
curl http://localhost:9027/readyThe answer is JSON that starts with {"status":"up".
Get the sample
Section titled “Get the sample”The sample is a Word file with tags such as {{ customer.name }} in it, and a JSON file with the values:
curl -o invoice.docx https://rusticdoc.com/samples/invoice-template.docxcurl -O https://rusticdoc.com/samples/invoice.jsonFill it and convert it
Section titled “Fill it and convert it”curl -F template=@invoice.docx -F "data=<invoice.json" -F steps=convert \ http://localhost:9027/v1/render -o invoice.pdfhead -c 5 invoice.pdfThe last line prints %PDF-. Open invoice.pdf and you will see invoice INV-2041 for Amani Otieno, with a row for each item and a total of KES 36,300.00.
The request has three parts:
| Part | What it does |
|---|---|
template=@invoice.docx |
Uploads the file as the template |
data=<invoice.json |
Sends the contents of the file as the text of the data field |
steps=convert |
Runs one step after filling the template: convert to PDF |
Leave out steps to get the filled Word file back:
curl -F template=@invoice.docx -F "data=<invoice.json" \ http://localhost:9027/v1/render -o filled.docxunzip -p filled.docx word/document.xml | grep -c 'Amani Otieno'-F "data=<invoice.json" sends the file’s contents as a text field, and needs the quotes so that your shell does not read the <. Uploading it as a file does the same thing:
curl -F template=@invoice.docx -F data=@invoice.json \ http://localhost:9027/v1/render -o filled.docxunzip -p filled.docx word/document.xml | grep -c 'Amani Otieno'Stop the service
Section titled “Stop the service”docker rm -f rusticdoc- Concepts explains what happened in that request.
- Template syntax shows how to write your own template.
- Install covers Compose, building from source and the CLI.
- Security lists what to set before anyone else can reach the service.