Generate an IDML file from code
The minimum IDML package a program has to write — mimetype first and uncompressed, META-INF/container.xml, the design map, resources, spreads and stories.
A generated IDML file is a ZIP with a fixed first entry, a root part, and the parts the root names. Start from a package InDesign is known to open and change it.
In short Write a ZIP archive whose first entry is mimetype, stored without
compression, holding application/vnd.adobe.indesign-idml-package. Add
META-INF/container.xml pointing at designmap.xml. Write designmap.xml with an
<?aid ?> instruction and a Document element that references every other part. Then
the parts: resources (Graphic.xml, Fonts.xml, Styles.xml, Preferences.xml), a
master spread, the spreads and the stories. The sample below is the smallest such package
in this reference, and InDesign opens it as written.
Download it.
The package, entry by entry
| Entry | What it holds |
|---|---|
mimetype | application/vnd.adobe.indesign-idml-package, no newline. First entry, stored (not compressed). |
META-INF/container.xml | A rootfile pointing at designmap.xml. |
designmap.xml | The <?aid ?> instruction, then Document with DOMVersion, StoryList and one idPkg: reference per part. |
Resources/Graphic.xml | Colours and swatches, including Black and Paper. |
Resources/Fonts.xml | One <Font> per face the text applies. |
Resources/Styles.xml | At least the default styles the items name: [No paragraph style], [No character style], and the object style [None]. |
Resources/Preferences.xml | Document preferences such as page size, margins and units. The sample's is empty. |
MasterSpreads/MasterSpread_<id>.xml | The master the pages apply. |
Spreads/Spread_<id>.xml | Pages and page items. |
Stories/Story_<id>.xml | The text, one story per part. |
The XML/ parts (BackingStory.xml, Tags.xml, Mapping.xml) hold the tagged-XML layer.
InDesign writes them in every package; the sample includes them empty.
The smallest complete package in this reference: one page, one frame, one story, every part InDesign writes.
Steps
- Start from a known-good package. Unzip the sample (or an InDesign export of the version you target), and generate only the parts you change: usually spreads and stories.
- Keep the ids consistent. Every story's
Selfmust appear in the design map'sStoryListand in anidPkg:Storyreference, and a text frame names it inParentStory(see how parts reference each other). - Spell things the way InDesign does. An
ItemTransformon every spread, page and item;PageCountandBindingLocationon every spread; the font as<Properties><AppliedFont type="string">;<Br/>between paragraphs; tabs as	. The full list is on what InDesign needs to open a file. - Zip it with
mimetypefirst and uncompressed, then everything else. With the Info-ZIP command-line tool, from inside the unzipped folder:
zip -X0 ../out.idml mimetype
zip -rX9 ../out.idml . -x mimetype- Open the result in InDesign. Your own reader shares your writer's assumptions; only InDesign shows whether it reads the file the way you meant.
Things to get right
- The
mimetyperule is about bytes, not names. It must be the first entry in the archive and stored, so its text sits at a fixed place in the file. Most ZIP libraries compress by default; set the method to "stored" for that one entry. - Name parts in the design map, not by convention. A reader finds parts through the design map's references. A story part the design map does not reference is not in the document, and InDesign discards a story that no text frame references.
- Declare every face you apply. A face the text applies but
Fonts.xmldoes not declare is reported as not available when InDesign opens the file.
In Paged: the importer needs only the
mimetypeanddesignmap.xmlto start, and every part the design map names; the resource parts are optional to it. A package that Paged opens can still open differently in InDesign, which is why the examples in this reference are checked in InDesign. Supported · verified
Frequently asked questions
What is the minimum an IDML package must contain?
To be read at all: a first, uncompressed mimetype entry, designmap.xml, and every part
the design map names. To open in InDesign the way you intend, follow InDesign's own packages:
container file, resources, a master spread, spreads with transforms on everything, and
stories with paragraph marks. The sample has all of them.
Why must mimetype be the first entry and uncompressed?
So a program can recognise the file from its first bytes without unzipping it. It follows
the same container convention as other ZIP-based document formats; see
the ZIP container.
Can I generate only the stories and keep the rest from a template?
Yes, and it is the safest approach: keep every other part as InDesign wrote it, and make
sure the design map's StoryList and story references match the stories you write.
Extract text from an IDML file
Get the plain text out of an IDML package — unzip it, list the stories in the design map, and walk each story's Content and Br marks.
Swap text and images in a template
Fill an IDML template from code — find frames by Name, replace the Content of the story a text frame points at, and put a linked Image into a graphic frame.