Extensions/Adobe SVG
ComfyUI Extension

Adobe SVG

Make SVGs (e.g. from Unlimited-SVG) open in Adobe Illustrator: expand <use, inline CSS, rewrite text, normalize viewBox

By biaoto·Created a day ago·Updated about 11 hours ago· 2
biaoto/ComfyUI-AdobeSVG
Nodes—
On cloudLocal install
Stars2
Updatedabout 11 hours ago
Readme

ComfyUI Adobe SVG

License: MIT test ComfyUI

Make SVGs that Adobe Illustrator actually opens — especially the ones produced by Unlimited-SVG and similar image-to-vector models.

English | 中文


The problem

Unlimited-SVG (and many similar tools) emit perfectly valid SVG that browsers render fine, but Illustrator refuses with one of these:

此 SVG 无效。请在打开之前进行验证。      (This SVG is invalid.)
无法完成操作,因为出现未知错误。[STEX]   (Unknown error [STEX])

Needless to say, the files are not corrupt — the XML parses, Chrome renders them. Illustrator's SVG 1.1 importer is simply much stricter than the spec, and only reliably accepts the exact dialect it writes itself.

What Illustrator chokes on

| Original markup | Illustrator's reaction | What this node does | |---|---|---| | font-size / font-weight / text-anchor on a parent <g>, inherited by <text> | text engine throws STEX | makes every text property explicit, no inheritance | | font-family="'Arial','Helvetica',sans-serif" (multi-value fallback stack) | treated as one literal font name → lookup fails | writes a single font family | | textLength + lengthAdjust | silently ignored, layout drifts | removed; coordinates recomputed from real glyph advances | | <use href="#gear"> (SVG 2 bare href) | rejected at validation: invalid SVG | <use> flattened into real <path> elements | | viewBox="68 0 887.5 1024" (non-zero origin) | artboard misplaced | wrapped in a translate so the origin is 0 0 | | a 4 KB <metadata> blob (ComfyUI workflow JSON) | "unsupported feature" dialog | stripped | | .st0{} classes in <style> | hit or miss | inlined into presentation attributes, then rebuilt the way Illustrator writes them |

Install

cd ComfyUI/custom_nodes
git clone https://github.com/biaoto/ComfyUI-AdobeSVG

or download the zip and unzip it under custom_nodes/, then restart ComfyUI.

Dependencies:

  • lxml — required
  • fonttools — optional. Enables exact glyph advances and text-outlining; without it we fall back to a CJK ≈ 1 em heuristic (accurate to < 0.5 % for Chinese text)

Both are already present in most ComfyUI environments.

Nodes

Adobe SVG

SVG in → SVG out, no disk I/O. Chain it into the core Save SVG node.

| Input | Description | |---|---| | keep_editable_text | on: text stays as <text> and remains editable in Illustrator<br>off: text is converted to outlines — opens in any Illustrator version, not editable | | keep_editable_text | on: text stays as <text> and remains editable in Illustrator<br>off: text is converted to outlines — opens in any Illustrator version, not editable | | svg / svg_text | either a link from an Unlimited-SVG node or the markup pasted in |

Fonts are auto-detected (Microsoft YaHei on Windows, PingFang SC on macOS, Noto Sans CJK on Linux) — there is no font setting to get wrong.

Outputs: svg (for downstream nodes) and svg_text (plain string).

Adobe SVG (Save)

Converts, writes ComfyUI/output/svg/adobe_00001_.svg (auto-numbered) and previews the SVG right on the node. Single output: svg.

Wiring

[Load / Generate Image]
   │
[Unlimited-SVG node]
   │ SVG
[Adobe SVG]            ← here
   │ SVG
[Adobe SVG (Save)]     → output/svg/adobe_00001_.svg

Unlimited-SVG → Adobe SVG (Save) also works if you don't need the intermediate node.

Editable text, or outlines?

| Situation | Setting | |---|---| | Illustrator 2020+, you want to retype / restyle the text | on | | Illustrator still refuses the file with STEX | off — outlines always open | | You're sending the file to someone else | off — no font dependency, renders identically everywhere | | Text has to remain real text for downstream layout | on |

How it works

adobe_svg_core.py is a fixed pipeline, and the order matters:

  1. Flatten <use> — deep-copy the target, merge attributes, compose transforms (max depth 6, cycle-safe)
  2. Inline <style> — parse .class{...} rules into attributes, drop the <style> block
  3. Rewrite text — compute each run's width from real font advances, fold text-anchor="middle" into the left edge, emit transform="matrix(1 0 0 1 x y)" plus a CSS class; or convert glyphs to <path>
  4. Normalize viewBox — wrap in a translate when the origin isn't 0 0
  5. Clean up — <metadata>, <title>/<desc>, duplicate ids, baseProfile
  6. Serialize — with an Illustrator-style header comment

It also round-trips Illustrator's own exports: those carry a <!DOCTYPE ... [entity declarations]> block that makes lxml fail, so DOCTYPE/entity pre-cleaning happens before parsing.

Known limitations

  • If the upstream node produces no SVG at all (generation failed or was interrupted), both nodes silently do nothing — no error, no log line, no file. Wire the upstream svg_code into a preview node if you need to know why
  • Complex <tspan> layout is flattened into one text run (content is kept, per-character styling is not)
  • Embedded raster images (<image>) are left untouched
  • <filter> elements pass through; support depends on your Illustrator version
  • If keep_editable_text is on and the target machine lacks the font, Illustrator substitutes it and the layout shifts. For byte-stable output, use outlines
  • Handles a subset of SVG 1.1; SVG 2 features are not guaranteed

Tests

python tests/smoke_test.py

Asserts: <use> flattening, CSS inlining, textLength removal, metadata stripping, anchor elimination, viewBox normalization, outline conversion, and file writing.

License

MIT — see LICENSE.