ZH-Docx文本分割器
Feeding a Word document into ComfyUI, one paragraph at a time
- 文本段落
ZH-Docx文本分割器 ("ZH-Docx text splitter") reads a .docx, .doc, or .txt file and turns it into a list of text paragraphs inside ComfyUI. That's the whole job, and it fills a hole the built-in nodes never bothered with: ComfyUI is full of text boxes, but it has no native way to pull a long document in and slice it up. If you've ever sat there copy-pasting a novel chapter or a spec sheet into a node one chunk at a time, you know exactly why this exists.
It lives in the tiny ComfyUI_pandai pack, and its natural partner in crime is the same pack's Pandai DSK node. A genuinely handy loop: split a script into paragraphs, feed each one into the DeepSeek node as a user_prompt, and generate an image prompt per scene. Long-document batch prompting is the use case this is built for.
How it works. Drop a file into ComfyUI/input and it shows up in the node's dropdown (the list is scanned when the menu refreshes). The node resolves the real path, then reads it: .txt files are decoded with chardet auto-detection unless you turn 编码检测 off, and .docx files are parsed with python-docx (paragraph by paragraph, joined with newlines), with a fallback that unzips word/document.xml and scrapes the text straight out of the XML if python-docx chokes. Then it splits on your 分隔符 (delimiter, default \n), strips each chunk, drops empties, and applies the slicing parameters.
The inputs that matter. Only a few, and they're all Chinese-labeled (the whole node is - one of its quirks):
文档文件- the dropdown of.docx/.doc/.txtfiles sitting inComfyUI/input.分隔符- what to split on. Default\nis per-line;\n\ngets you paragraph blocks.起始位置,跳过间隔,最大数量- the three slicing knobs. 起始位置 skips the first N chunks, 跳过间隔 takes every Nth chunk (great for sampling a long doc), 最大数量 caps the output. Output is a list called文本段落, which is exactly what you feed into a per-item loop or the DSK node.
There's also an optional 自定义路径 that overrides the dropdown with an absolute path, and 输出编码 (utf-8 / gbk / auto) for forcing encoding on the output strings - handy for the GBK-heavy world this node clearly lives in.
Install. Same pack as the DSK node, same install:
cd ComfyUI/custom_nodes
git clone https://github.com/pandaer119/ComfyUI_pandai
cd ComfyUI_pandai
pip install -r requirements.txt
Restart ComfyUI, or use ComfyUI Manager and search "ComfyUI_pandai". No models, no heavy deps - python-docx and chardet are the only ones this node actually touches. Everything runs on CPU in milliseconds.
Where people get burned. Three things. First, the dropdown only lists files that were in input/ when you last refreshed the node menu - drop the file in and refresh, or use 自定义路径 to skip the guessing game. Second, that .doc option is a lie: true old-binary .doc files can't be opened by python-docx or the zip fallback, so they'll throw a "DOCX解析失败" error. Convert to .docx and stop fighting it. Third, everything - labels, errors, debug output - is in Chinese, so if that's not your language, you'll be squinting at the schema. Also note it prints [ZH_DEBUG] chatter to the console while it works; harmless, just noisy.
It's a niche utility from a one-person pack, not a polished ecosystem staple - but for document-driven workflows it's the difference between scripting a file parser and dragging in a node. If you batch-generate from text documents, grab it.
Inputs (8)
| Name | Type | Default | Description |
|---|---|---|---|
| 文档文件 | COMBO | 1 options: None | |
| 分隔符 | STRING | — | |
| 起始位置 | INT | 00–10000 | — |
| 跳过间隔 | INT | 00–10 | — |
| 最大数量 | INT | 1001–1000 | — |
| 编码检测 | BOOLEAN | true | — |
| 自定义路径opt | STRING | — | |
| 输出编码opt | COMBO | auto | 3 options: utf-8, gbk, auto |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| 文本段落 | STRING | — |