Copy link to clipboard
Copied
FrameMaker 11 and DITA. We have a DITA document with some graphics imported by reference wider than a column. Is there a way to scale the image automatically to fit the column/anchored frame instead of cropping it when opening the document, f.ex in read/write rules?
Any help appreciated.
Copy link to clipboard
Copied
The images are in EPS format.
Copy link to clipboard
Copied
This script fits an image to an anchored frame within a selection.
Do not select all to avoid unexpected results.
I hope it helps you.
var doc = app.ActiveDoc;
var tr = doc.TextSelection;
var cmd1 = app.GetNamedCommand ("AlignGfxTBCenter");
var cmd2 = app.GetNamedCommand ("AlignGfxLRCenter");
// Get anchor frame from selection
var textItems = doc.GetTextForRange (tr, Constants.FTI_FrameAnchor);
for (var i=0;i<textItems.length;i++){
var aFrame = textItems[i].obj;
var graphic = aFrame.FirstGraphicInFrame;
var verticalRatio = aFrame.Height / graphic.Height;
var HorizontalRatio = aFrame.Width / graphic.Width;
var applicableRatio = verticalRatio > HorizontalRatio ? HorizontalRatio : verticalRatio;
graphic.Height = graphic.Height * applicableRatio;
graphic.Width = graphic.Width * applicableRatio;
// Align image to center of anchor frame
graphic.GraphicIsSelected = true;
Fcodes ([cmd1.Fcode]);
Fcodes ([cmd2.Fcode]);
}
Copy link to clipboard
Copied
This is a useful script. One suggestion is to avoid Fcodes for centering and set the properties LocX and LocY properties directly. You should be able to use this:
graphic.LocX = (aFrame.Width - graphic.Width) / 2;
graphic.LocY = (aFrame.Height - aFrame.Height) / 2;
And of course, you can expand this to work on all of the graphics in the document at once. You can also have a script triggered automatically when the document is opened.
Copy link to clipboard
Copied
Thank you for your wonderful suggestion.
I modified the script and it became about 2.9x faster.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more