Sign inSign up

huuhuybn/ofd-to-pdf

By huuhuybn

•Updated 3 months ago

OFD (Chinese document standard) to PDF on the command line, CJK font included.

Image
0

92

huuhuybn/ofd-to-pdf repository overview

⁠ofd-to-pdf

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.

⁠Why the image exists

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:

  • Debian ships CJK fonts as .ttc collections, which the PDF library cannot subset-embed at all.
  • The converter locates fonts by exact filename, and the collection filenames are not among the ones it looks for.
  • Noto CJK has CFF outlines, which embed without subsetting — a 3 KB invoice came out as a 13.8 MB PDF.

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.

⁠Tags

TagContents
latest, 0.2.3@miconvert/ofd-to-pdf 0.2.3 on Node 20 (Debian bookworm-slim)

⁠Prefer not to install anything?

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

Tag summary

Content type

Image

Digest

sha256:d42fb4efc…

Size

76.9 MB

Last updated

3 months ago

docker pull huuhuybn/ofd-to-pdf