Generate Thai-language PDF receipts from n8n, Make or Zapier with one HTTP request
If you build automations for Thai businesses, you will eventually be asked for this: "Can the system send the customer a PDF receipt, in Thai, after they pay?"
It sounds easy. In practice, Thai text is where many PDF tools fall over: missing glyphs, vowels floating in the wrong place, tone marks overlapping the letter below. The fix is not complicated, but you have to know where to look.
This post shows a setup that works from any tool that can send an HTTP request (n8n, Make, Zapier, a plain script). The idea is simple:
- Build the receipt as HTML (you already know how).
- Include a Thai web font in that HTML.
- POST the HTML to a PDF API and save the file it returns.
I'll use Leafkiln, a small HTML-to-PDF API I built, for step 3. Disclosure: it's my project, and I'm sharing it because I'd like feedback. The technique works with any renderer that runs a real browser engine.
Why Thai text breaks
Thai is written with stacked combining marks: a base consonant, a vowel above or below it, and a tone mark above that. A renderer needs two things to get this right:
- A font that actually contains Thai glyphs. A server with only Latin fonts will show empty boxes.
- Proper text shaping, so the marks stack on the right letter.
A browser-based renderer handles shaping well, so the practical job is just making sure a Thai font is available. The easiest way is to load one from Google Fonts inside the HTML itself. Sarabun is a good default for documents.
Step 1: The receipt HTML
<!doctype html>
<html lang="th">
<head>
<meta charset="utf-8">
<link href="https://fonts.googleapis.com/css2?family=Sarabun:wght@400;700&display=swap" rel="stylesheet">
<style>
body { font-family: 'Sarabun', sans-serif; font-size: 14px; color: #222; }
h1 { margin: 0 0 4px; }
table { width: 100%; border-collapse: collapse; margin-top: 16px; }
th, td { padding: 8px; border-bottom: 1px solid #ddd; text-align: left; }
td.num, th.num { text-align: right; }
.total { font-weight: 700; font-size: 16px; }
</style>
</head>
<body>
<h1>ใบเสร็จรับเงิน</h1>
<div>เลขที่ INV-2026-0042 · วันที่ 22 พฤศจิกายน 2569</div>
<table>
<tr><th>รายการ</th><th class="num">จำนวน</th><th class="num">ราคา (บาท)</th></tr>
<tr><td>ชาเขียวอุจิ ถุงละ 100 กรัม</td><td class="num">2</td><td class="num">480.00</td></tr>
<tr><td>ค่าจัดส่ง</td><td class="num">1</td><td class="num">50.00</td></tr>
<tr class="total"><td>รวมทั้งสิ้น</td><td></td><td class="num">530.00</td></tr>
</table>
<p>ขอบคุณที่อุดหนุนครับ</p>
</body>
</html>
Tip: this is a normal web page, so you can open it in your browser first and fix the layout before touching any automation.
Step 2: Send it as a request
curl -X POST https://leafkiln.somboon0241-c27.workers.dev/v1/pdf \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"html":"<h1>ใบเสร็จรับเงิน</h1><p>รวมทั้งสิ้น 530.00 บาท</p>","format":"A4"}' \
--output receipt.pdf
The response body is the PDF itself (application/pdf), so --output writes it straight to disk.
Two parameters worth knowing for receipts:
margin: an object such as{"top":"15mm","right":"15mm","bottom":"15mm","left":"15mm"}printBackground: on by default, so table header colors and logos are kept
The response also includes x-leafkiln-used and x-leafkiln-limit headers, so you can see where you are against your monthly quota. A request that fails to render returns an error and is not counted.
Example output: the receipt HTML from Step 1, rendered to PDF with Sarabun.
Step 3: Wire it into n8n
In n8n, the pattern is two nodes after your "payment received" trigger:
- Code (or Set) node that builds the HTML string, inserting the order number, items and total from the incoming data. Have it return two fields:
html(the receipt HTML) andformat(set toA4). - HTTP Request node:
- Method: POST
- URL:
https://leafkiln.somboon0241-c27.workers.dev/v1/pdf - Authentication: add a header named
Authorizationwith the valueBearer YOUR_API_KEY - Send Body: on, Body Content Type:
JSON, Specify Body: Using Fields Below - Add two body fields,
htmlandformat, and drag the matching fields from the Code node's output into the value boxes - Options > Response > Response Format: File, so the PDF flows into the next node as an attachment
From there, attach the binary file in a Gmail, LINE or S3 node. Make and Zapier work the same way: an HTTP module that POSTs JSON and returns a file.
Using "Fields Below" has a bonus: n8n serializes the body for you, so quotes and newlines in the HTML are escaped correctly. If you hand-write a JSON string from an HTML string, those characters will break the request.
Common gotchas
- Fonts load from the network. If the Google Fonts request is slow, the first render can fall back to a default font. Setting
waitUntiltonetworkidlemakes the renderer wait for those requests to finish. - Page breaks. For long item lists, add
tr { page-break-inside: avoid; }so rows don't split across pages. - Rendering a URL instead. If your receipt already exists as a web page, send
urlinstead ofhtml. You send exactly one of the two. - Request size. Request bodies are limited to 6 MB, so avoid embedding large base64 images. Link to hosted images instead.
What I'd like feedback on
I built this because I kept hitting the Thai-PDF problem in client automations. It runs on Cloudflare Workers with Browser Rendering, doesn't store your HTML or PDFs, and there's a free tier of 100 files per month with every parameter available.
If you try it, I'd really like to know:
- Did the Thai text render correctly in your layout?
- Where did you get stuck in the n8n / Make / Zapier setup?
- Which option is missing that would stop you from using it?
Free key and live demo: https://leafkiln.somboon0241-c27.workers.dev/
Comments here are the fastest way to reach me.
Comments
No comments yet. Start the discussion.