lohriialo/indesign-scripting-python

Insert image into selected frame

robertjiang77 opened this issue · 3 comments

Hi Lohrrialo,

I need to insert an image (png/jpg) into a frame. But I am struggling with how to read the image in. Could you kindly review the below code and show me a way to fix it?

app = win32com.client.Dispatch('InDesign.Application.CC.2019')
myInddFile = r'C:\Users\zhijia\Documents\Robertjiang\Tracker\In-Design Project\Tracker Template_test_old.indd'
myDocument = app.Open(myInddFile)
myPage = myDocument.Pages.Item(1)

myRectangle = myPage.Rectangles.Add()
myRectangle.GeometricBounds = ["6p", "6p", "18p", "18p"]
myRectangle.StrokeWeight = 0
myRectangle.place('C:\Users\zhijia\Documents\Robertjiang\Tracker\In-Design Project\AA.jpg'')

The problem occurred at the end line of the above code.
What I need is to

  1. place a picture into the rectangle frame
  2. and then fit content to frame.

Could you kindly teach me how to achieve both in python please?

Great thanks!

Hi Lohrii, could you kindly show me how to solve the problem? I tried to read in the image by Plotly but the place function doesn't work. Should I use the PlaceIntoFrame function? Please help, thanks!

@robertjiang77 the place method should start with an upper case myRectangle.Place()
See, scripting reference line #64592

And to fit content to frame

idContentToFrame = 1668575078   # from enum idFitOptions
myRectangle.Fit(idContentToFrame)

See, scripting reference line #802