Você está na página 1de 19

extract. process. automate.

Lesson 4: Text and Images


Author: Oliver Huser <ohaeuser@fhcon.de>

For more Information please visit http://idmllib.com

About ?

Content
Lets get some Image and Text Information! Tutorial #1, #2 and #3 Need some JAVA coding experience Optional: InDesign CS 4 to create Demo Files

Targetskills & Prerequisites

Dont worry. Get Demoles from http://idmllib.com !

Why ?
You want to check out the IDMLlib in a few minutes You want to see how easy it is to code a QA workow

What have you learned so far ?

Export / Create IDML Files Access IDML Containers Brief overview of the IDML structure How to access basic information from IDML docs

Goal for this Tutorial

Load an IDML File Get a list of spreads

get some Information from the images on a spread get the content of text page items in the spreads

Basically we parse spread by spread through an IDML le and get the information we need! After this Tutorial you will be able to code your own Quality Assurance Workow!

something like: Are all images accesible correct color proles ? spellchecker for text content anyone ?

Sample InDesign Document

Image: 1 Page 1 & 2


5

The example two pager

Images
we got image on the rst spread and 3 on the second spread one text box on the rst spread, center alligned two text boxes on the second spread

Text Boxes

rst one is without allignment second is right alligned

And once more with code

In the next slides we will access all images


nd out the lename and path and where those les are stored and when they were placed into the document and the actual and the effective PPI of the images

actual ppi is the resolution of the image coming from the graphics program (e.g. Photoshop). Usually 300 ppi for offset printing. If this is 72 ppi it might be a lowres resolution image you do not want to use and maybe want to exchange! effective ppi tells you if an image was placed in Indesign and was then enlarged. What happens is that you now have less pixels of course and the nal result probably looks terrible. The way to do it is to resize and retouch the image in Photoshop! Not in the layout program. Or get a better quality image !
7

Again just a few lines of code ...

This is it:

Code reviewed

List<String> spreadIdList = document.getSpreadIdList();

get a list of all Spreads (see Tutorial #2 for explaination) now we iterate through all spreads

for (String spreadId : spreadIdList)

Spread theSpread = document.getSpreadById(spreadId); System.out.println("\nSpread: "+ spreadId + " with " + theSpread.getPageCount () + " page(s)");

and here we access the Spread ID and the number of pages. Remember a spread can have several pages!

List<Rectangle> rectangles = theSpread.getRectangleList(); now accessing all rectangles on the spread, rectangles can contain images.

for (Rectangle rectangle : rectangles) and we iterate through those

Code reviewed Part 2

if (rectangle.getImageList().size() > 0)

checking if there are any images at all

Image image = rectangle.getImageList().get(0); Link link = image.getLinkList().get(0); get the link that hold all kinds of information

Date linkImportTime = link.getLinkImportTime(); System.out.println("Imported Image Time: " + linkImportTime); for instance the time the image was imported into the document!

String linkResourceURI = link.getLinkResourceURI(); System.out.println(linkResourceURI); or the storage path to the image (local or from a server ?)

Double effectivePPI = image.getEffectivePpi().get(0); Double actualPPI = image.getActualPpi().get(0); System.out.println("actualPPI: " + actualPPI + " effectivePPI = " + effectivePPI) nally the actual and effective PPI - check for lowres images ...
10

Output

This is your output:

11

Now get the text content

The next code will ...


nd all text page items on each spread read it contents and the allignment spell check ? check content versus product databases extract text content from ID to CMS systems ...

What you can do with it ?

12

What have you learned ?

You know now how to ...

access images and text from the IDMLlib you can work with that content now probably have by now an idea about how powerful the IDMLlib can be for your workow

Next ...

add a spell checker for central spell checking modify and save documents (later in Q1/2010) access complex image groups

13

Code to access text content

Image: 2 Code for TextInfo


14

TextInfo code explained

List<String> spreadIdList = document.getSpreadIdList();

rst we get a list of all available spread ids then we iterate through those

for (String spreadId : spreadIdList) Spread theSpread = document.getSpreadById(spreadId System.out.println("\nSpread: " + spreadId + " with " + theSpread.getPageCount() + " page(s)"); get the spread id and the info how many pages are there now we access all the textframes on the spread iterate through all text frames on the spread

List<TextFrame> textFrameList = theSpread.getTextFrameList(); for (TextFrame textFrameId : textFrameList) String parentStoryId = textFrameId.getParentStory(); the parent story is the assigned story of the text frame
15

TextInfo code explained Part 2

Story story = document.getStoryById(parentStoryId);

then we get the story by id from the document get the rst paragraph style range from the PSR list get the allignment of the paragraph style range

ParagraphStyleRange psr = story.getParagraphStyleRangeList().get(0); Justication justication = psr.getJustication(); String content = psr.getCharacterStyleRangeList().get(0).getContent(); we get the rst character style range and access its content print out the content and print out the justication of the paragraph style range System.out.println(content); System.out.println("The Justication is: " + justication);

16

System.out.println(content);

and print it out and get the justication, like CenterAlligned

System.out.println("The Justication is: " + justication);

17

TextInfo output

And the output ...


the IDs such as ub9 can be found in the spread folder! remember that stories are separated from the text frame. the ParentStory property tells you which story belongs to which text frame. stories have an own folder, the Stories folder. all stories can be found inside this folder. If a property is not set, a null value can come back.

18

Ressources

For more information


watch the video visit http://idmllib.com follow us on Twitter http://twitter.com/IDMLlib write an email ohaeuser@fhcon.de

for dev info contact Mr. Fink instead: ank@fhcon.de Yes we were not kidding when we claimed the IDMLlib is easy to use !

Watch the usual channels for a new tutorial / video ! Please give feedback ! We love to hear from you

19

Você também pode gostar