Markdown/HTML/Typst to PDF
Overview
Convert Markdown, HTML, or Typst files into PDF documents. The conversion runs locally; see the installation instructions below for the CLI's default telemetry and update-check network requests and how to disable them.
The CLI supports three modes:
(default, standard documents),
(arithmetic worksheets), and
(write characters using pinyin). The latter two modes accept plain-text input and are typeset directly by the CLI.
bash
cyeam pdf README.md # 从 Markdown 文件生成 PDF(base64 JSON)
cyeam pdf README.md -o out.pdf # 从 Markdown 文件生成并保存 PDF
cyeam pdf layout.typ -o out.pdf # 从 Typst 文件生成并保存 PDF(需要本机 typst)
cat index.html | cyeam pdf # 从 stdin 读 HTML,输出 base64 JSON
cat README.md | cyeam pdf -o out.pdf # 从 stdin 读 Markdown 并保存 PDF
Choosing an Input Method (Important)
supports multiple input methods. Choose the most reliable option for the current execution environment; do not guess the command syntax.
Choosing a Typesetting Format (Important)
- By default, prefer generating Markdown. This is suitable for standard documents, explanations, lists, code blocks, and other linear content.
- When the user explicitly requests a compact, space-saving layout that fills the page, multi-column presentation, free-form typesetting, or a more attractive layout, do not generate only ordinary single-column Markdown.
- Lightweight multi-column layouts can still use Markdown, but use the columns extension syntax.
- When a freer layout is needed, such as multiple columns, grids, explicit column breaks, or page-level typesetting, prefer generating a Typst file () and then running
cyeam pdf <file.typ> -o <file.pdf>
.
- Do not use HTML/CSS for compact or multi-column typesetting. The current HTML input is only suitable for simple structural conversion, and CSS is not executed as a PDF layout engine.
Markdown Multi-Column Extension
Use this when you want to retain the Markdown writing experience while making short content more compact. Syntax:
markdown
::: columns 3
::: column
第一列内容
:::
::: column
第二列内容
:::
::: column
第三列内容
:::
:::
Rules:
- The number after indicates the suggested number of columns, but the actual column count is determined by the number of blocks.
- Each can still contain ordinary Markdown.
- Use this only when the user requires a compact, space-saving, multi-column, or page-filling layout. Do not overuse it for standard documents.
Typst Free-Form Typesetting
Use this when the user requests free-form typesetting, explicit multi-column layouts, grids, card-style layouts, or greater page utilization. Example:
typst
#set page(paper: "a4", margin: 18mm)
#set text(size: 11pt)
#columns(3, gutter: 12pt)[
第一列内容
#colbreak()
第二列内容
#colbreak()
第三列内容
]
The Typst file must be saved with a
extension before execution:
bash
cyeam pdf /tmp/layout.typ -o /tmp/layout.pdf --pretty
If
is not installed locally, the command will report an error. In that case, switch to the Markdown columns extension or ask the user to install Typst.
Arithmetic Worksheet Format
The CLI natively supports
and does not require Typst. Input is UTF-8 plain text, with one problem per non-empty line; numbering is allowed, and blank lines are ignored. Do not mix in Markdown headings, metadata, tables, or answers. The CLI only performs typesetting; it does not generate problems, assign numbering, or supply answers.
bash
cyeam pdf questions.txt --mode arithmetic -o practice.pdf
cyeam pdf questions.txt --mode arithmetic --layout grade4 --title "四年级口算" -o practice.pdf
cyeam pdf questions.txt --mode arithmetic --layout vertical -o practice.pdf
accepts
(default),
,
,
,
, and
, as shown in the table below;
defaults to “宝宝口算” (“Baby Arithmetic”). These two parameters apply only to arithmetic mode. The default
retains automatic detection of Markdown/HTML/Typst; arithmetic mode takes precedence over the file extension and always parses the input line by line as problems, while supporting both file and stdin input and the existing base64 JSON output.
Use this mode whenever the user asks for an “arithmetic PDF,” “arithmetic worksheet,” or “typeset in the Baby Arithmetic format.” Reference
cyeam_web/controllers/baobao_controller.go
and its
; use the PDF backend layout as the source of truth, and do not use the frontend HTML printing logic's hard-coded 100-problem count.
- Uses A4 portrait orientation (210 × 297 mm) and a black-and-white borderless problem grid. The problem area starts 10 mm from the left, has a total width of 190 mm, and begins 32 mm from the top. The header separator line is at 30 mm and spans 5–205 mm.
- The default title is “宝宝口算” (“Baby Arithmetic”), 20 pt bold. Grade 4 uses a specific problem-type title at 13 pt bold. The top-left title position is approximately x=10 mm, y=7 mm. The standard website version places four brief prompts—“Check the problems, check the tens, check the ones, check the answers”—at the upper right at 8–10 pt; the Grade 4 version omits them. Native CLI mode uses a regular-weight title and does not add the prompts, QR code, or name/date fields; use custom Typst to reproduce these decorations fully.
- When reproducing the website version, place a 20 × 20 mm QR code at x=170 mm, y=7 mm in the upper-right corner, pointing to
https://www.cyeam.com/tool/arithmetic
. A custom worksheet may omit the QR code; retain title, name, and date metadata from the arithmetic skill and adjust the question start position and rows per page accordingly to avoid overlap.
| Problem type | Rows × columns per page | Capacity per page | Row height | Column width | Problem font size |
|---|
| Standard horizontal arithmetic | 20 × 5 | 100 problems | 12 mm | 38 mm | 11.5 pt |
| Grade 4 general problem types | 25 × 4 | 100 problems | 10 mm | 47.5 mm | 9 pt |
| Grade 4 large numbers , negatives | 25 × 3 | 75 problems | 10 mm | 190/3 mm | 10 pt |
| Grade 4 quantity relationships | 25 × 2 | 50 problems | 10 mm | 95 mm | 10 pt |
| Non-Grade-4 vertical arithmetic (website problem type identifiers end in ) | 5 × 5 | 25 problems | 48 mm | 38 mm | 11.5 pt |
- Fill the grid from left to right and then top to bottom. Horizontal problems are left-aligned and vertically centered; for vertical problems, place the prompt at the top and leave calculation space below. Use a Heiti-style font, or any available font that covers Chinese characters and operators.
- For standard Grade 4 blanks, retain ; for quantity relationships, use the wider . Preserve units and the complete problem text. If a long problem does not fit, prefer increasing the row height or reducing the number of columns, then recalculate the capacity per page. Never truncate the problem text.
- The counts in the table are reference page capacities. If the user specifies a count or provides problems, paginate according to the actual number, leave the remaining space blank on the final page, and do not invent problems merely to fill it. Only when the user requests a full-page output and does not specify a count should problems be generated to match the corresponding capacity. The website generator may also return fewer problems because of problem-bank or deduplication constraints.
- Keep problem content separate from answers, and do not include answers by default. If answers are needed, add a separate answer page. When generating problems, follow the grade, problem-type, and count constraints of the arithmetic skill. This format only defines PDF typesetting and does not expand the supported problem types.
- Use native CLI arithmetic mode by default, paginating according to the corresponding capacity and leaving the final page unfilled. Long problems wrap automatically within their cells; if the content exceeds the row height, the command reports an error and identifies the problem number. In that case, shorten the prompt or choose a wider layout. Vertical mode places the horizontal prompt at the top and leaves blank calculation space; it does not automatically generate a vertical expression. Use Typst when extra metadata, custom row heights, or vertical expressions are needed. The millimeter dimensions in this section override the generic 18 mm page margin mentioned above.
Pinyin Character-Writing Format
Use
whenever the user requests a “Look at Pinyin and Write Characters PDF” (看拼音写字 PDF) or a pinyin Mi-grid practice sheet (拼音米字格练习纸). The input is the original Chinese characters to practice (UTF-8), not pinyin; either a file or stdin can be used. Typst, network access, and login are not required.
bash
printf '%s' '你好' | cyeam pdf --mode pinyin -o practice.pdf
cyeam pdf words.txt --mode pinyin -o practice.pdf
- Reference the website route : A4 portrait orientation, an upper-left title reading “Look at Pinyin and Write Characters,” pinyin hints above blank Mi grids, and no displayed Chinese-character answers.
- The practice area begins at x=13 mm, y=20 mm. Mi grids are 11 × 11 mm, the pinyin area is 7 mm high, phrases are separated by 5 mm, and each row contains at most 17 cells. Spaces, line breaks, punctuation, and other non-Chinese separators do not occupy cells. Phrases longer than 17 characters are split automatically.
- Reserve “Correction:” at the bottom along with four horizontal lines at 255, 265, 275, and 285 mm. Long text is paginated automatically; each page repeats the title and correction area, and text is never silently truncated. Spacing between groups may cause a page to hold fewer than 204 characters.
- Pinyin is generated from a local dictionary, and readings of polyphonic characters should be checked in context. The command returns an error if the input contains no Chinese characters.
- The pinyin font is built in. The title and correction label use PDF Chinese-font detection and require an available Chinese font on the system. and apply only to arithmetic mode and cannot be combined with pinyin mode.
- As with the other PDF modes, saves the file; without it, base64 JSON is returned. The positional argument is always a file path. To pass text directly, use stdin or the existing
cyeam pinyin sheet "你好" -o practice.pdf
command.
Method 1: File Input (Recommended for Agent)
This is suitable when a Markdown/HTML file already exists, or when the Agent can first write the content to a temporary file. This method works with structured
tools, a normal shell, and a later
from Xiaoli.
bash
# 1. 先准备真实源文件,例如 /tmp/openclaw-install-guide.md
# 2. 再把源文件转成 PDF
cyeam pdf /tmp/openclaw-install-guide.md -o /tmp/openclaw-install-guide.pdf --pretty
Method 2: stdin Input
This is suitable when the execution environment can write body content to the command's stdin. The content can be Markdown or HTML.
bash
cyeam pdf -o /tmp/openclaw-install-guide.pdf --pretty
Note that the form above is correct only when stdin already contains content. Without stdin content, it fails with
no content provided (stdin is empty)
.
Method 3: Shell Pipeline Input
This is suitable for a human shell or an Agent/bash tool that explicitly supports shell pipelines.
bash
cat /tmp/openclaw-install-guide.md | cyeam pdf -o /tmp/openclaw-install-guide.pdf --pretty
printf %s "# 标题\n\n正文" | cyeam pdf -o /tmp/out.pdf --pretty
If the current tool accepts only structured
, does not provide stdin, and does not support shell pipelines, use Method 1: create the source file first, then run
cyeam pdf <source> -o <pdf> --pretty
.
After generating the PDF for the user, continue using the current channel's sending tool, such as
, to send the generated
file.
Installation
Before installing, read the commands below. The example pins v1.1.4 and does not follow latest; it downloads an executable archive.
Run these steps only when CLI installation is needed; do not repeat the installation for every command.
macOS / Linux: Verify and Install to the User Directory
Run this in Bash or Zsh. It requires
,
,
, and either
or
.
The script automatically selects arm64 or x86_64 on macOS/Linux and stops on other platforms.
bash
(
set -eu
version='v1.1.4'
case "$(uname -s)/$(uname -m)" in
Darwin/arm64)
asset='cyeam_Darwin_arm64.tar.gz'
sha256='06b5af004ab4f0f05d5829ea6bd18b97c4449c262af7df14c67175f7d3cb29db' ;;
Darwin/x86_64)
asset='cyeam_Darwin_x86_64.tar.gz'
sha256='107342bb9d2fa444b96155c468e71b8cc63e0f5ad0acc784698afe221548efa6' ;;
Linux/aarch64|Linux/arm64)
asset='cyeam_Linux_arm64.tar.gz'
sha256='ed87697f3948bead67b585e9881c3bef20e8d2d903beb5b125587281a5091c5b' ;;
Linux/x86_64)
asset='cyeam_Linux_x86_64.tar.gz'
sha256='873d6805fab8ab56540bb034aaf2f57f12eb672fcabd322ebe401e8250a5966d' ;;
*) echo '不支持的平台,请查看固定版本的 Release。' >&2; exit 1 ;;
esac
workdir=$(mktemp -d)
trap 'rm -rf "$workdir"' EXIT
cd "$workdir"
curl --fail --show-error --silent --location --proto '=https' --proto-redir '=https' \
--output "$asset" "https://github.com/mnhkahn/cyeam-cli/releases/download/$version/$asset"
printf '%s %s\n' "$sha256" "$asset" > expected.sha256
if command -v sha256sum >/dev/null 2>&1; then
sha256sum -c expected.sha256
else
shasum -a 256 -c expected.sha256
fi
# set -e 确保下载或校验失败时,不会解压或安装。
tar -xzf "$asset" cyeam
mkdir -p "$HOME/.local/bin"
install -m 0755 cyeam "$HOME/.local/bin/cyeam"
CYEAM_CLI_NO_UPDATE_NOTIFIER=1 "$HOME/.local/bin/cyeam" --no-analytics version
)
The script writes only to a temporary directory and
; an existing binary with the same name is replaced. It does not require administrator privileges and does not modify system directories, services, or shell configuration. For the current shell, use:
bash
export PATH="$HOME/.local/bin:$PATH"
To make the change permanent, you can optionally add the line above to your shell configuration.
You can verify the digest on the
v1.1.4 release page and
checksums.txt.
When upgrading a pinned version, you must verify and replace both the version number and its corresponding SHA-256.
The digest verifies the consistency of the release file; it is not equivalent to an independent signature or security audit.
External Requests and Permission Purposes
- Installation download: Downloads only the selected archive from the pinned GitHub Release; GitHub may redirect to its asset CDN. After downloading, verify the fixed SHA-256 documented above and then extract the single file. The installation check disables telemetry and update notifications.
- PDF generation: Reads the user-specified local file or stdin, and the document is not uploaded during conversion. / writes to the specified path, may overwrite an existing file, and requires no login. Typst input invokes the installed command and reads and writes temporary directories. Typst packages referenced by a document may trigger Typst's own package downloads, so use local dependencies when working offline.
- Usage analytics: By default, sends the command name, CLI version, system information, and a random installation ID to . The server may infer the region from the outbound IP address; command arguments, image content, and login credentials are not sent. The random ID is stored in . Disable it with or .
- Update notifications: By default, checks GitHub for the latest version at most once every 24 hours and caches the result in
~/.cyeam/update-state.json
. The notification itself does not replace the program. Set CYEAM_CLI_NO_UPDATE_NOTIFIER=1
to disable it. is an explicit upgrade command that downloads and verifies the latest Release, replaces the current program, and then attempts to synchronize skills through . Do not run it when a pinned version is required; use the selected-version installation steps above instead.
To disable CLI telemetry and update notifications without affecting network requests required by the business itself, set the following in the current shell:
bash
export CYEAM_CLI_NO_ANALYTICS=1
export CYEAM_CLI_NO_UPDATE_NOTIFIER=1
Output
json
{"ok":true,"data":"{\"pdf\":\"<base64>\"}"}
Use
to save the file directly:
bash
cyeam pdf README.md -o out.pdf --pretty
# saved: out.pdf
Without
, the CLI prints a JSON envelope:
{"ok":true,"data":"saved: out.pdf\n"}
Notes
- Format auto-detection: a suffix is treated as Typst; a / suffix or content beginning with / is treated as HTML; everything else is treated as Markdown
- Entirely local generation using goldmark + gofpdf
- Supported typesetting elements: H1–H4 headings, paragraphs, bold/italic text, inline code, code blocks, unordered/ordered lists, links, and horizontal rules
- Markdown additionally supports the / multi-column extension
- Typst input requires a local installation
- Automatic pagination with A4 paper
- No login required