Skip to main content
Participant
November 11, 2022
Question

How to copy frames from one InDesign document to the other?

  • November 11, 2022
  • 2 replies
  • 1659 views

Hello everyone,

 

I am trying to write a script to copy some specific frames (text/graphic) from one master indesign document to another document which has to be dynamically.

 

For example, if the master InDesign document has ten frames, i'd like to copy five specific frames based on the id and copy these frame to a new document created dynamically with the styles, alignment and all other criteria as same as in the master document. 

 

Could someone please guide me with any already available scripts , documentation or suggestions on how this can be achieved? 

This topic has been closed for replies.

2 replies

Willi Adelberger
Community Expert
Community Expert
November 11, 2022

Apply object styles to the frames with all relevant properties defined, copy them and paste them. 
For future use, save them in a CC Library. 

brian_p_dts
Community Expert
Community Expert
November 11, 2022

All the documentation you need is here: https://www.indesignjs.de/extendscriptAPI/indesign-latest/#about.html

 

Specifically, look at the Applicationn, Document, Documents, TextFrame, and TextFrames APIs. You'll need a way to reference the active document and the target document (generally app.documents[0] and app.documents[1]). Then, I would name the target text frames in the master document under the Layer panel, and target them with itemByName property, then use the duplicate() methord for a text frame. A sample line would be:

 

app.documents[0].textFrames.itemByName("trgt1").duplicate(app.documents[1].pages[0]);

 

But a lot more goes into it than that. Do you have any scripting knowledge? 

Participant
November 11, 2022

Hi @brian_p_dts , @Manan Joshi  I found this script and this seems to do the job, but there is one slight issue though. I want the frames to be aligned one after the other without any empty space. I think now it copies the frame with the same x, y cordinates. Basically what i am looking for is on the second image, the country frame should come right below the logo frame.

var textFramesCollection = new Array();
    var myDocHeight;
    var myDocWidth;
    main();

//https://stackoverflow.com/questions/28360706/copy-a-text-frame-from-one-indesign-file-to-another-and-then-compare-there-prope
    function main()
    { 
        app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
        app.scriptPreferences.measurementUnit = MeasurementUnits.millimeters;
        try
        {  
            myDocHeight = app.activeDocument.documentPreferences.pageHeight;
            myDocWidth = app.activeDocument.documentPreferences.pageWidth;
            textFramesCollection = app.activeDocument.textFrames;

            var newInddDoc = app.documents.add();
            newInddDoc.documentPreferences.pageHeight = myDocHeight;
            newInddDoc.documentPreferences.pageWidth = myDocWidth;

            for( var j = 0; j < textFramesCollection.length; j++)
            {
                if(textFramesCollection[j].contents == "Logo" || textFramesCollection[j].contents == "Country")
                {
                    var myPageItem = newInddDoc.pages.item(0);
                    var newPageItem = textFramesCollection[j].duplicate(myPageItem) ;
                }
            }
            //app.activeDocument.close(SaveOptions.NO);
        }
        catch(e)
        {
            alert(e);
        }
     }

 

Participant
November 16, 2022

You would have to implement the logic to identify the frames and that should be easy to do. Look at the sample provided by @rob day that should take care of the InDesign API that would be needed for copying/moving the objects to the new document.

Regarding the styles being copied over, yes they are copied over with some conditions. If the style does not exist in the destination it will be copied and applied on the copied object, if it exists in the destination then the style from the destination would be applied.

Styles in InDesign are document level, there is no way to restrict a styles scope to a frame/object.

-Manan


Hi @Manan Joshi ,
I have been playing around with the code snippet which @rob day  shared and that works in moving the objects.

 

One additional query here is, Is there any API for creating multiple columns in page? I did not see anything at the page/page item level.