Copy link to clipboard
Copied
I am trying to write a script in Extendscript that will allow us to import a multi-page PDF into the FrameMaker document using the script instead of inserting one page at a time.
We are currently using FrameScript to do this, but I know that FrameScript is going away at some point and we will eventually need to convert to Extendscript. So I am trying to stay ahead of the curve.
Does anyone already have a script that they use that does this? Or any tips for how to begin to create this script?
Thanks for your help!
Copy link to clipboard
Copied
Hi, I have a series of samples for the beginner here:
http://www.weststreetconsulting.com/WSC_ExtendScriptSamples.htm
There is no example that does specifically what you are asking for, but maybe there is something there that can help you understand scripting in general. Hope this helps.
Russ
Copy link to clipboard
Copied
Try running the sample code below with the document open.
Note that PDF scaling is determined dynamically by FrameMaker.
(function (){
var pdfFile = File.openDialog ("Select pdf file", "*.pdf", false);
if (!pdfFile) return;
var doc = app.ActiveDoc;
if (!doc.ObjectValid()) return;
var numOfPages = prompt ("Enter number of pages in pdf", 1);
numOfPages = parseInt (numOfPages, 10);
if (isNaN (numOfPages)||numOfPages==0) return;
var textItems, textItem, textloc, imgFrame, insetObj;
for (var i=0;i<numOfPages;i++){
// Create an anchor frame at the end of the last line
textItems = doc.MainFlowInDoc.GetText(Constants.FTI_PgfEnd);
textItem = textItems[textItems.length - 1];
textloc = new TextLoc (textItem.obj, textItem.offset);
imgFrame = doc.NewAnchoredAFrame (textloc);
imgFrame.AnchorType = Constants.FV_ANCHOR_BELOW;
imgFrame.Alignment = Constants.FV_ALIGN_CENTER;
imgFrame.AFrameIsFloating = false;
// Create an inset object inside the anchor frame and place the PDF
insetObj = doc.NewGraphicObject (Constants.FO_Inset, imgFrame);
insetObj.InsetFile = pdfFile.fsName;
insetObj.PageNum = i; // PDF page number, beginning with 0
insetObj.Pen = 15;
// Match the size of the anchor frame to the size of the PDF
imgFrame.Width = insetObj.Width;
imgFrame.Height = insetObj.Height;
}
})();