Skip to main content
dg_huebel
Participant
December 1, 2020
Answered

Batch create multiple Documents with js

  • December 1, 2020
  • 1 reply
  • 512 views

I need help with a script I found and adapted for creating multiple documents from a tab separated text file.

The script creates the documents so far but it doesn't set the margin properties and I have no clue why.

 

This is the sample txt file:

210	297	20	Name1
2000	4000	300	Name2
210	297	10	Name3
220	440	20	Name4
330	200	15	Name5

 

and this the js:

var file = File.openDialog("Öffne Text Dokument", undefined, false);
var folder = Folder.selectDialog("Speicherort Dokumente");
file.open("r");
var content = file.read().split("\n");

for (var i = 0; i < content.length - 1; i++) {
    var curLine = content[i].split("\t");
    var h = curLine[0];
    var w = curLine[1];
	 var mar = curLine[2];
	 var n = curLine[3];
    docName = n + "_" + h + "×" + w;
    try {
       var newDoc = app.documents.add(false);
       newDoc.documentPreferences.pageHeight = h;
       newDoc.documentPreferences.pageWidth = w;
       newDoc.marginPreferences.properties = {top: mar,left: mar,right: mar,bottom: mar};
       newDoc.save(new File(folder + "/" + docName + " .indd"));
       newDoc.close(SaveOptions.no)
       } catch(myError){}
    }

 

Why does the "marginPreferences.properties" not work?

 

Thanks in advance for any help!

This topic has been closed for replies.
Correct answer SychevKA

hi, use this line:

newDoc.pages[0].marginPreferences.properties = {top: mar,left: mar,right: mar,bottom: mar};

1 reply

SychevKA
SychevKACorrect answer
Inspiring
December 1, 2020

hi, use this line:

newDoc.pages[0].marginPreferences.properties = {top: mar,left: mar,right: mar,bottom: mar};
dg_huebel
dg_huebelAuthor
Participant
December 1, 2020

Great Thanks!