ComfyUI Node

Text Pad

Zero-pad your numbers and align your text columns

By wwsmiao·Created 4 months ago·Updated 4 months ago· 0
Text Pad
    • text
    text
    modeleft
    width20
    pad_char

    Every now and then you need 123 to be 000123, or you're building text output that should line up in columns. TextPad is the padding node: it takes a string and pads it out to a width with a pad_char, aligned left, right, or center. It's the sort of tiny node you don't think about until the filename you generated comes out as img1.png when you wanted img001.png, and then it's exactly what you need.

    The three inputs that do the work: mode (left/right/center), width (default 20), and pad_char (default a space). The classic use is mode: right, width: 6, pad_char: "0" - that's how "123" becomes "000123", which matters more than it sounds when you're batch-saving files and want them to sort correctly, or generating image IDs with fixed-length digits. mode: left pads on the right (useful for building aligned label columns), and center pads both sides for that ---Hi---- effect.

    Two implementation details are worth knowing, and both come from reading the source. First, pad_char only uses its first character - the code grabs pad_char[0]. If you type "-=" expecting alternating characters, you get a wall of -s. That's a reasonable design choice (padding is character-based), but it's the kind of thing that surprises people. Second, the padding uses Python's ljust/rjust/center, and those count characters, not display width. A string with Chinese characters pads by character count, and since CJK glyphs render roughly twice as wide as Latin ones, a "centered" column of mixed text won't be visually centered on screen. If you're building a human-readable aligned block, don't expect pixel-perfect columns with mixed scripts.

    The width range is 1 to 9999, default 20. If the input is already longer than the width, padding does nothing - the string passes through unchanged (Python's ljust/rjust never truncate). So there's no "cap at width" behavior; if you need truncation, that's TextSubstring's job.

    Install is the same easy story for the whole pack:

    cd ComfyUI/custom_nodes
    git clone https://github.com/wwsmiao/comfyui-wwdm-aicd.git
    

    Restart ComfyUI, look under wwdm-aicd. Stdlib only; no requirements.txt in the repo despite what the README's install section implies. The author's README and code comments are in Chinese; widget labels are English.

    Honest verdict: this is the most niche node in the pack, and you'll likely never build a workflow around it. But it's the right tool for two specific jobs - zero-padding numeric IDs for filename sorting, and building aligned text blocks for logs or display output - and when those jobs come up, nothing else in the pack does them. Drop it after a TextCase or TextLength, before a save node, and your output filenames will thank you.

    Categorywwdm-aicd

    Inputs (4)

    NameTypeDefaultDescription
    textSTRING
    modeCOMBOleft3 options: left, right, center
    widthINT201–9999
    pad_charSTRING

    Outputs (1)

    NameTypeDescription
    textSTRING