Skip to content

DeepIDML is a parser focus on grabbing information from IDML file.

License

Notifications You must be signed in to change notification settings

Heng-xiu/DeepIDML

Repository files navigation

DeepIDML

NPM Version NPM Downloads Node.js Version License - MIT

DeepIDML is a parser focus on grabbing information from IDML file.

Usage

import { DeepIDML } from 'deep-idml';

const paraXml: string = `<ParagraphStyle 
  FillColor="Color/Black" 
  FontStyle="Regular" 
  PointSize="12"> 
  </ParagraphStyle>`

const deeper: DeepIDML = new DeepIDML();
deeper.setXML(paraXml);
console.log(deeper.getJSON());
console.log(deeper.getCss());

Getting started

$ npm i deep-idml

Examples

In most situations, any information about styles are in the Resources/Styles.xml which unzip from IDML file. And the snippet shows as below:

<idPkg:Styles>
	...
	<RootParagraphStyleGroup Self="u74">
    	<ParagraphStyle Self="ParagraphStyle/Table%3a12-13w table (7/9 80%25)" Name="Table:12-13w table (7/9 80%)">
	        <Properties>
            	<BasedOn type="object">ParagraphStyle/Table%3a12-13 table (7/9 80%25)</BasedOn>
            </Properties>
        </ParagraphStyle>
    </RootParagraphStyleGroup>
    ...
</idPkg:Styles>

With DeepIDML, people can simply set Resources/Style.xml file as parameter into function, and it will return parsed css property

const deeper: DeepIDML = new DeepIDML();
const parsedCssProps = deeper.getTraversaledParagraphStyleGroups(paraXml);
console.log(parsedCssProps);

// Result 
'Table:12-13w table (7/9 80%)': {
    transform: 'skewX(0)',
    'font-style': 'Regular',
    'text-indent': '0px',
    color: 'Black',
    letterSpacing: '0',
    textDecoration: 'underline',
    fontSize: '7',
    textAlign: 'left',
    marginLeft: '0',
    marginRight: '0',
    '@_BasedOn': 'Table:12-13 table (7/9 80%)'
  },

Other APIS(experiments)

import { DeepIDML } from 'deep-idml';

const styleXMLString: string = fs.readFileSync('./Resources/styles.xml', 'utf8');

const deeper: DeepIDML = new DeepIDML();
const css = deeper.getCSSFromXML(styleXMLString);

// Result 
.Table:10-11 table 03 DL (7/9 90%) { 
  transform:skewX(0);
  font-style:Regular;
  text-indent:0px;
  color:Black;
  letter-spacing:0;
  text-decoration:underline;
  font-size:7;
  text-align:left;
  margin-left:0;
  margin-right:0;
  font-family:CompositeFont/$ID/+Times;
  margin-top:0;margin-bottom:0; 
}

License

MIT

About

DeepIDML is a parser focus on grabbing information from IDML file.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published