Hier finden Sie die deutsche Version dieses Artikels.
One of the most asked questions of our customers is: “Is the IDMLlib able to import Snippets (.idms) into IDML documents?”. Fortunately we have been able to answer this question with yes since the very first IDMLlib 1.1 milestones. But until now this has been a very source code intensive task. I will show you later how easy it is with the current build using our new IDMLlib-Utility-Framework. But let me first explain what’s the idea behind snippets and what it needs to import the snippet.
Snippets are a very convenient way to to modularize pages. The idea behind this is to export one or more pageitems into an external datastructure that can be easily reused on different pages or documents. Pageitems can be exported by using the Selection-Tool, select one or more PageItem and export them by using File/Export. Select InDesign-Snippet (this is only available with the Selection-Tool) and export the pageitems as .idms file.
This Snippet is nothing more than a XML File based on the IDMarkupLanguage schema that contains all information regarding the exported pageitems. Basically it is a one file IDML file. The snippet can be re-imported using the File/Place command in the same or a different document.
So what´s the big deal about this ? As the IDML, the snippet only contains references to all used assets like fonts and images and is therefore very small and easy to use. It is a very powerful concept in InDesign® but it is much more powerful in an IDML workflow. Imagine advertising with different claims or different images that could be assembled and composed outside of InDesign® and later finished and processed in InDesign® or InDesign® Server. Think of an Advertising construction kit provided by a webapplication.
The additional benefit using IDML and snippets outside of InDesign is the ability to modify the snippets to your needs, change images or text used in the snippets or add additional pageitems. So what do we have to do import the snippet in the IDML file outside of InDesign to mimic the File/Place command ?
The following steps are needed to import the snippet. This can either be done programmatically or with a tool like Oxygen XML that simplifies the processing of IDML by providing support for IDML container files :
- Unpack the IDML
- Locate the Spread where the snippet-pageitems will be appended
- Load the IDMS snippet and locate the pageitems to import
- Append the pageitems to the selected Spread
- Create new Stories/Story_xxx.xml files for each imported TextFrame pageitem
- Copy each Story node from the snippet to the corresponding Stories/Story_xxx.xml
- Check Self-ID collisions for each imported object and create new IDs for collided pageitems and update the pageitems Self-ID
- Create new IDML Package
This was simplified by importing the snippet to the document where it was exported from, so no importing of Styles/Colors/Fonts has been necessary.
This has been quite a task – even with the help of the IDMLlib this would have been around 20-30 lines of code. But with the current build we were able to reduce the amount of code dramatically without loosing flexibility:
Idml idml = new Idml("docs/4pager.idml"); Idml idms = new Idml("docs/product.idms"); DocumentUtil.importSnippet(idml,idms,1); idml.saveAs("processes/merged.idml"); idml.close(); idms.close();
The actual importing is just one line of code, that is handling all of above listed tasks, the rest is loading, saving and closing the IDML files:
DocumentUtil.importSnippet(idml,idms,1);
The importSnippet() method takes 3 or 5 arguments :
- targetIdml
- sourceIdms
- targetSpreadIndex
- xOffset (optional)
- yOffset (optional)
With the x- and y-Offset you are able to move the imported PageItems from their original position to a different location on the spread.
But I need to post-process the the imported PageItems and change text, images and layer, how do I know which PageItems were imported, I hear you asking. Nothing easier than that: the DocumentUtil.importSnippet() methods return a PageItemIterator which makes it really easy to iterate over all imported PageItems and modify the PageItems to your liking, for example put all PageItems on the layer u3b:
PageItemIterator pageItemIterator = DocumentUtil.importSnippet(idml, idms, 1); while(pageItemIterator.hasNext()) { AbstractIdmlPageItem pageItem = pageItemIterator.next(); pageItem.setItemLayer("u3b"); }
This was the first blog-post about our new IDMLlib-Utility-Framework inside the IDMLlib, that makes working with IDML easier than ever. Over the next couple of days and weeks we will introduce more parts of this framework here in this blog.
I hope you enjoyed this little article about IDML Snippets and how easy it is to work with them in the IDMLlib, feedback is welcome and comments are open.
Thanks for your attention.