OFD (Chinese document standard) to PDF on the command line, CJK font included.
92
Convert OFD — the Chinese national fixed-layout document standard, GB/T 33190-2016 — to PDF from the command line. Chinese text renders, because a working CJK font is built into the image.
docker run --rm -v "$PWD:/data" huuhuybn/ofd-to-pdf invoice.ofd
# → invoice.pdf, next to the input
docker run --rm -v "$PWD:/data" huuhuybn/ofd-to-pdf invoice.ofd out/receipt.pdf
/data is the working directory inside the container, so mount the folder
holding your files there.
The conversion itself is an npm package,
@miconvert/ofd-to-pdf.
The hard part is not the code — it is the fonts.
OFD files routinely reference system fonts instead of embedding them. With no
CJK font on the machine, the renderer falls back to Helvetica and every Chinese
character silently disappears: the conversion reports success and hands back an
unreadable document. Getting a usable CJK font in place turns out to need
three things that a plain apt install fonts-noto-cjk does not give you:
.ttc collections, which the PDF library cannot
subset-embed at all.This image extracts the WenQuanYi Micro Hei face (TrueType, subsets properly) into the filename the converter expects. The same invoice now converts to 10 KB with its Chinese text intact.
| Tag | Contents |
|---|---|
latest, 0.2.3 | @miconvert/ofd-to-pdf 0.2.3 on Node 20 (Debian bookworm-slim) |
The same conversion runs in the browser at miconvert.com/en/ofd-to-pdf.
Source: github.com/huuhuybn/miconvert-ofd-to-pdf · Apache-2.0
Content type
Image
Digest
sha256:d42fb4efc…
Size
76.9 MB
Last updated
3 months ago
docker pull huuhuybn/ofd-to-pdf