Skip to main content
jenniferb13892332
Participant
June 30, 2022
Question

Writing a Script in Extendscript

  • June 30, 2022
  • 2 replies
  • 310 views

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!

    This topic has been closed for replies.

    2 replies

    Participating Frequently
    July 31, 2023

    Hi, jenniferb13892332

    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;
    	}
    })();

     

     

    Legend
    July 5, 2022

    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