Search code examples
c#adobe-indesign

How to place a photo in a specific location in Indesign document using C#?


I need to place photos on Indesign pages, few on each of 100 pgs. I use Place function and it causes to the photo to be loaded on the cursor, and then I need to click on the location I want it. But I need it to be automatic! I mean, to finish placing the photos on the page, but it waits to the user to click.

This is the code:

Indesign.Page pg = doc.Pages[1];
Indesign.TextFrame frm = pg.TextFrames[1];
string txt = frm.Contents;

if (txt.Contains("ploni"))
{
    app.Place("C:\\User\\Directory\\PhotoFile.png");
}

I have noticed that Indesign.Page has another parameter in its Place function that called "InsertionPoint". But I didn't understand what is it.


Solution

  • I know nothing about C#, but in Extendscript InDesign DOM Page object has place() method. http://jongware.mit.edu/idcs6js/pc_Page.html And it doesn't wait any click from a user.

    You can place image at top-left corner of a page this way:

    app.activeDocument.pages[0].place("c:/temp/image.jpg")

    I believe C# uses the the more or less same object model as Extendscript.