A Node.js converter that transforms Adobe InDesign IDML (InDesign Markup Language) files into structured JSON format.
This project extracts content, styles, and layout information from IDML files and converts them into a JSON representation that can be used for further processing, analysis, or conversion to other formats. It handles various InDesign elements including text frames, rectangles, polygons, images, colors, and styles.
IDML (InDesign Markup Language) is Adobe InDesign's XML-based file format that represents an InDesign document as a collection of XML files packaged in a ZIP archive. This format allows for programmatic access to InDesign documents without requiring the InDesign application.
- Text Frames: Extracts text content with character and paragraph styling
- Rectangles: Processes rectangular shapes with fills, strokes, and transformations
- Polygons: Handles complex polygon shapes with paths
- Graphic Lines: Converts line elements
- Images: Extracts and processes embedded images (SVG and raster formats)
- Groups: Maintains hierarchical grouping of elements
- Character Styles: Font family, size, color, weight, and text decorations
- Paragraph Styles: Alignment, spacing, indentation, and text properties
- Object Styles: Fill colors, stroke properties, opacity, and effects
- Style Inheritance: Resolves cascading styles with "BasedOn" relationships
- CMYK to RGB Conversion: Automatic color space conversion
- RGB to CMYK Conversion: Reverse conversion support
- Spot Colors: Processes special spot color definitions
- Gradients: Extracts gradient definitions with stops and angles
- Page dimensions (width and height)
- Bleed settings (uniform or individual sides)
- Margins (uniform or per-side)
- Transformation matrices for element positioning
npm install- jszip: For reading IDML files (ZIP archives)
- xmldom: For parsing XML content within IDML files
- canvas: For image processing operations
- mathjs: For matrix transformations
- Place your
.idmlfiles in theinput/directory - Run the converter:
npm start- Find the converted JSON files in the
output/directory
const { processIdml } = require("./src/idmlProcessor");
async function convert() {
const jsonData = await processIdml("./path/to/file.idml");
console.log(JSON.stringify(jsonData, null, 2));
}
convert();idml-json-node/
├── index.js # Main entry point, processes all IDML files in input/
├── package.json # Project dependencies and metadata
├── input/ # Directory for input IDML files
│ └── bounded-text.idml # Example IDML file
├── output/ # Directory for output JSON files
│ └── bounded-text.json # Example output
└── src/ # Source code modules
├── idmlProcessor.js # Core IDML processing logic
├── characterStyles.js # Character style extraction and resolution
├── paragraphStyles.js # Paragraph style extraction and resolution
├── objectStyles.js # Object style extraction and resolution
├── colorOps.js # Color conversion and processing
├── imageOps.js # Image extraction and conversion
└── utils.js # Utility functions (pt to px conversion, etc.)
The main processing engine that:
- Unzips IDML files
- Parses XML documents (designmap, styles, graphics, preferences)
- Processes spreads and pages
- Handles all page items (text frames, shapes, images)
- Applies transformations and styles
- Assembles the final JSON structure
- Extracts character-level styling information
- Resolves style inheritance via "BasedOn" relationships
- Caches styles for performance
- Returns font, size, color, and decoration properties
- Processes paragraph-level formatting
- Handles text alignment, spacing, and indentation
- Resolves style inheritance
- Caches resolved styles
- Extracts object-level properties
- Processes fill colors and stroke properties
- Handles opacity and effects
- Resolves style cascading
- Converts CMYK to RGB and vice versa
- Retrieves color definitions from graphics resources
- Processes spot colors
- Extracts gradient information with stops and angles
- Detects and processes SVG images
- Compresses raster images
- Converts images to base64 encoding
- Handles various image formats
- Provides utility functions
- Converts points to pixels
- Additional helper functions for common operations
The converter generates a JSON structure with the following top-level properties:
{
"bleed": 0,
"fWidth": 612,
"fHeight": 792,
"originX": "left",
"originY": "top",
"transformMatrix": [1, 0, 0, 1, 0, 0],
"margin": 36,
"pages": [
{
"pageNumber": 1,
"elements": [
{
"type": "textFrame",
"content": "Sample text",
"styles": {...},
"geometry": {...}
}
]
}
]
}- File Reading: The IDML file (a ZIP archive) is loaded and unzipped
- XML Parsing: Key XML files are parsed:
designmap.xml: Document structure and spread referencesResources/Styles.xml: Style definitionsResources/Graphic.xml: Color and graphic resourcesResources/Preferences.xml: Document settings
- Spread Processing: Each spread is processed to extract pages
- Element Processing: Page items are processed recursively:
- Geometry and transformations are calculated
- Styles are resolved and applied
- Images are extracted and encoded
- Text content is parsed with formatting
- JSON Generation: The complete structure is assembled into JSON
- Output: JSON is written to the output directory
The converter handles complex transformations including:
- Translation (position offsets)
- Rotation
- Scaling
- Skewing
- Matrix multiplication for nested transformations
- Document Conversion: Convert InDesign files to web-ready formats
- Content Extraction: Extract text and images from IDML files
- Automated Publishing: Integrate InDesign content into automated workflows
- Analysis: Analyze InDesign document structure and styling
- Migration: Migrate content from InDesign to other systems
- Templating: Process InDesign templates programmatically
- Relies on IDML format (InDesign CS4 and later)
- Some complex InDesign features may not be fully represented
- Image processing requires the canvas library (native dependencies)
- Large files with many images may require additional memory
- Node.js (v12 or higher recommended)
- NPM or Yarn package manager
- Native build tools for canvas installation (Windows: Visual Studio Build Tools)
Potential areas for expansion:
- Support for additional InDesign elements (tables, footnotes, etc.)
- Enhanced image processing options
- Export to additional formats (HTML, PDF, etc.)
- Interactive preview generation
- Batch processing improvements
- Performance optimization for large documents
ISC
Created for converting Adobe InDesign IDML files to JSON format.
Note: This tool is designed for IDML files and does not work with native .indd files. Use Adobe InDesign's "Export > InDesign Markup (IDML)" feature to create IDML files from .indd documents.