Skip to main content
Participating Frequently
February 17, 2014
Question

Getting the offset of a placed PDF within the container rectangle

  • February 17, 2014
  • 1 reply
  • 3676 views

I need to get the offset of a placed PDF inside of the container rectangle. I have figured out that this information should be available in the transformationMatrix of the placed file. So I do something like:

var pdfTransform = pdf.transformValuesOf(CoordinateSpaces.pasteboardCoordinates)[0];

var horzTranslation = pdfTransform.horizontalTranslation;

var vertTranslation = pdfTransform.verticalTranslation;

but the coordinates I get back are just weird. The horizontal value seems reasonable, but the vertical is way off what I expect.

There may be some precondition to doing this that I'm missing. Running the pageitems/TransformValuesOf.jsx sample from the Scripting Guide also gives weird values. That sample creates a rectangle with a center point of [0, 0] and then retrieves the transform. I would expect the translation to be [0, 0] but I actually get [5, -415.95] (horz, vert).

In that sample it talks about ruler coordinates, so I tried setting document.viewPreferences.rulerOrigin to different values, but that does nothing.

I'm stumped. Can someone please give me a hint on what's going on here?

This topic has been closed for replies.

1 reply

svenaxAuthor
Participating Frequently
February 20, 2014

Anyone?

Community Expert
February 20, 2014

What about the zero point? Reset it using myDoc.zeroPoint = [0,0], then try again.

If that doesn't help, maybe try comparing the geometricBounds of the PDF and those of its parent, the containing rectangle.

Peter

Community Expert
February 27, 2014

To answer your question: Because I didn't know I could use the geometric bounds for this. I am not an InDesign user, and am just starting to get into scripting it. So, I'm pretty much flying blind, looking at values in the ExtendScript Debugger and trying to figure out how they relate to what I want. Anyways, I just tried using the geometric bounds, and that gives me the same values as the coordinate space thing I did above. Good.

That still leaves the issue of the additional margin. Here's the problem:

This is what it looks like when I try to use the box coordinates extracted from the placed file, offsetting them by the difference of the geometric bounds. As you can see, the boxes are somewhat off to top left.

This is what happens when I place the PDF used above in a new document, using the default Crop to bounding box (visible layers) option. Apparently InDesign does not crop to the exact bounding box of the items, but adds a bit of margin for some reason. I haven't verified this yet, but it looks like this margin is the same as the offset I get above. And if you are wondering why the columns in the PDF appears to be swapped, the document above has placed the same PDF twice with different X offsets to get that effect.

Any idea?


The scripting model provides these crop types:

app.pdfPlacePreferences.pdfCrop = PDFCrop.cropArt

. . .cropPDF

. . .cropTrim

. . .cropBleed

. . .cropMedia

. . .cropContentAllLayers

. . .cropContentVisibleLayers

When I place a cropped PDF, the last two add a margin such as you describe, but the first four all place the PDF exactly cropped. What happens when you use the first four crop types?