• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

To place a few pages of an indd document to another document

Engaged ,
Mar 16, 2023 Mar 16, 2023

Copy link to clipboard

Copied

var targetDoc = app.activeDocument;

var sourceFile = File.openDialog("select indd file");

targetDoc.pages[0].place(sourceFile);

// this is working fine as it place first page on indd file

 

var sourceDoc = app.open(sourceFile);

for (i =0; i < sourceDoc.pages.length; i++)

{

var page = sourceDoc.pages[i]'

targetDoc.pages.add.place(page);  /// here I receive error => Invalid value for parameter. expected File but received page. Any suggestions are welcome.

 

}

 

TOPICS
Scripting

Views

354

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Mar 16, 2023 Mar 16, 2023

Hi @virender_CTS, you can do it like this:

function main() {

    var targetDoc = app.activeDocument;
    var sourceFile = File.openDialog("select indd file");
    if (sourceFile == null) return;
    var sourceDoc = app.open(sourceFile);

    app.importedPageAttributes.importedPageCrop = ImportedPageCropOptions.CROP_CONTENT;
    for (var i = 0; i < sourceDoc.pages.length; i++) {
        app.importedPageAttributes.pageNumber = i + 1;
        var importedPage = targetDoc.pages.add().place(sourceFi
...

Votes

Translate

Translate
Community Expert ,
Mar 16, 2023 Mar 16, 2023

Copy link to clipboard

Copied

Hi @virender_CTS, you can do it like this:

function main() {

    var targetDoc = app.activeDocument;
    var sourceFile = File.openDialog("select indd file");
    if (sourceFile == null) return;
    var sourceDoc = app.open(sourceFile);

    app.importedPageAttributes.importedPageCrop = ImportedPageCropOptions.CROP_CONTENT;
    for (var i = 0; i < sourceDoc.pages.length; i++) {
        app.importedPageAttributes.pageNumber = i + 1;
        var importedPage = targetDoc.pages.add().place(sourceFile, [0, 0])[0];
    }

} // end main

app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Import Indesign Document');

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 16, 2023 Mar 16, 2023

Copy link to clipboard

Copied

Hi m1b, it worked like a magic, thank you very much.

Just to tell you, i have changed this code from

targetDoc.pages.add().place(sourceFile, [0, 0])[0]; to

targetDoc.pages[i].place(sourceFile, [0, 0])[0]; 

 

Additionally, if you can spend fewmore mins then please explain the meaning of code in red below.

targetDoc.pages.add().place(sourceFile, [0, 0])[0];

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 16, 2023 Mar 16, 2023

Copy link to clipboard

Copied

LATEST

Hi @virender_CTS, the code in red:

1. targetDoc.pages.add() - you already know this part—it adds a new page and returns a Page specifier object.

2..place(sourceFile, [0, 0]) - the place method of Page—see documentation here. Takes a File, and a placePoint (I used coordinates). It has other parameters after the second which I didn't use, but you may like to set them.

3. [0] - the index of the first item of the array returned by Page.place method (in this case a single ImportedPage). Therefore if you are not capturing a reference to the placed object, then you have removed "var importedPage =" you can also remove the trailing "[0]". It isn't needed in your code.

- Mark

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines