Skip to main content
vze26m98
Known Participant
May 30, 2011
Question

Placing a PDF graphic into an existing XML hierarchy?

  • May 30, 2011
  • 1 reply
  • 755 views

I have an existing XML hierarchy that has a picture element that looks like this:

<picture href=""></picture>

which is already placed in a TextFrame.

I'd like to place a PDF graphic at the location of this element, in essence updating it.

I'm able to update the href attribute with the correct filename, but this doesn't create a placed graphic AFAICT.

I can place a graphic in my TextFrame, but don't understand how to specify this <picture> element as its location.

Any pointers to example code, or hints/tips?

Greatly appreciated!

Charles

This topic has been closed for replies.

1 reply

John Hawkinson
Inspiring
May 31, 2011

InDesign will only place images if the imported tag matches the tag associated with images in Tagging Preset Option. Do you have the tag defined to be <picture/>? Because I believe the default is <image/>.

Are you referring to an anchored object? If not, your comment about placed inside a textframe is confusing. As always, a screenshot is very useful.

vze26m98
vze26m98Author
Known Participant
May 31, 2011

Hi John-

Here's what my situation looks like. I get this for the FileMaker XML that I'm given:

So I can programmatically specify where I want the placed PDF as an XML reference:

app.documents[0].selection[ROW].associatedXMLElement.xmlElements[COL].xmlElements[0].xmlElements[0].xmlAttributes[0].value

and obviously I can get a filename. I just don't know what to do with this information to place the graphic.

Thanks again,

Charles

John Hawkinson
Inspiring
May 31, 2011

Oh, right. Did we forget to tell you that trying to use XML in InDesign is usually a bad idea and that you could do much better without it?

Anywhohowwhichwhywhere...

In keeping with that theme, XML doesn't really come into play. If you have a rectangular frame rect and a filename filename and you want to place  filename in the rect then you just use: rect.place(filename);

So in your case, it's just about defining the two. I guess:

var rect, filename;

rect = app.documents[0].selection[ROW].associatedXMLElement.

    xmlElements[COL].xmlElements[0].xmlElements[0];

filename = new File(rect.xmlAttributes[0].value);

rect.place(filename);

Of course, if your filename is really a URL you'll have a spot of trouble there, maybe.

And you might be better off using XPath, i.e. .evaluteXPathExpression("//picture") to get your rectangle.

And what if href= isn't the first attribute of the <picture/> tag?

I suppose that perhaps you should consider using the .placeIntoFrame() and .placeXML() methods of the XMLElement class. I suspect you'll be sorry if you try, but go ahead :-).