Skip to content

Generate your first PDF

Submit a small HTML document, follow its job and save the PDF. This walkthrough uses Bash, curl and jq against a running DocKiln instance.

Open the workspace, sign in and choose Settings → API keys → Create key. Copy the key when it appears. For local development, start the Docker stack first.

Set the instance URL to the origin you use in your browser. For the default local stack:

Terminal
export DOCKILN_URL=http://localhost:3000
read -rsp 'Workspace API key: ' DOCKILN_API_KEY; echo
export DOCKILN_API_KEY
Terminal
curl --fail-with-body -sS "$DOCKILN_URL/v1/documents" \
-H "Authorization: Bearer $DOCKILN_API_KEY" \
-H "Content-Type: application/json" \
-d '{"html":"<h1>Order confirmed</h1><p>Order DK-1042</p>"}'

Copy the returned id. The status in the initial response describes the job at admission. Rendering continues on the worker.

Set JOB_ID to the ID from your response. This loop checks for up to one minute, stops on an error and only writes a file when the worker has finished.

download.sh
set -eu
: "${JOB_ID:?Set JOB_ID to the returned document ID}"
for attempt in {1..30}; do
job=$(curl -fsS -H "Authorization: Bearer $DOCKILN_API_KEY" \
"$DOCKILN_URL/v1/documents/$JOB_ID")
case "$(jq -r '.status' <<<"$job")" in
completed)
curl -fsS -H "Authorization: Bearer $DOCKILN_API_KEY" \
"$DOCKILN_URL$(jq -r '.download' <<<"$job")" -o order.pdf
exit 0 ;;
failed) jq -r '.error' <<<"$job" >&2; exit 1 ;;
esac
sleep 2
done
echo "Still processing. Keep JOB_ID and check again." >&2
exit 1

Open order.pdf. The first page should read Order confirmed and show Order DK-1042. The same job appears under Documents in the workspace.

Submit requests from your server so the workspace key stays private. The Next.js invoice guide and Node client example show how to integrate submission, bounded polling and downloads. Use idempotency keys when retrying a submission.