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.
}
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
...
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');
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];
Copy link to clipboard
Copied
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