Copy link to clipboard
Copied
Hi,
I'm beginner of Indesign Javascript developer.
Does anyone know how to flow the text into Indesign template and apply styles to text flow.
Kindly help on this.
Regards,
KPS
Copy link to clipboard
Copied
You will have to be more specific with your question. This is a broad spectrum that you are alluding to, do you have a workflow to cater to? Do you use or wanna use data merge? Is this solution to be based on importing XML? or is to be a custom solution, what considerations did drive you to seek a custom solution?
I maybe adding to complexity that you have in mind currently, but we or rather you would need to have a standing point from where things can be sorted out. If you haven't thought of anything yet about what i asked, maybe you could start with what you have/or think of as input and what you need as an output. Then maybe ask in the InDesign user forum to see what experts there advice, i see this more as a workflow/solution picking problem at this point than a scripting question.
Hope this helps
-Manan
Copy link to clipboard
Copied
Hi,
I was trying this below script. But, it doesn't work properly.
Or else, anyone have how to do flow the normal text/word file into indesign template also apply styles as well.
var myFolder = Folder("/f/Scripts");
var myWordDocuments = myFolder.getFiles("*.docx");
for (var i = 0; i < myWordDocuments.length; i++) {
(function()
{
var newDoc = app.documents.add();
var myDoc = app.activeDocument;
with (myDoc.documentPreferences)
{
pageHeight = "215.9mm";
pageWidth = "279.4mm";
pageOrientation = PageOrientation.portrait;
}
with (myDoc.pages.item(0).marginPreferences)
{
columnCount = 2;
}
var myTextFrame = app.activeWindow.activePage.textFrames.add();
myTextFrame.geometricBounds = [279.4 - 12.7,0 + 12.7,0 + 12.7, 215.9 - 12.7];
myTextFrame.place(myWordDocuments);
app.scriptPreferences.userInteractionLevel=UserInteractionLevels.neverInteract;
var oldDocument = File("/f/Scripts/Template.indt")
app.activeDocument.loadMasters(oldDocument, GlobalClashResolutionStrategyForMasterPage.LOAD_ALL_WITH_OVERWRITE);
app.scriptPreferences.userInteractionLevel=UserInteractionLevels.INTERACT_WITH_ALL;
})();
(function() {
var myDoc = app.activeDocument;
var myFrames = myDoc.textFrames;
for (var j = 0; j < myFrames.length; j++) {
while (myFrames
var newPage = myDoc.pages.add();
var pageMargins = newPage.marginPreferences;
var newPageMargins = [pageMargins.top, pageMargins.left, myDoc.documentPreferences.pageHeight - pageMargins.bottom, myDoc.documentPreferences.pageWidth - pageMargins.right];
var oldRuler = myDoc.viewPreferences.rulerOrigin;
myDoc.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;
with (myDoc.pages[-1].textFrames.add()) {
geometricBounds = newPageMargins;
previousTextFrame = myDoc.pages[-2].textFrames[0];
}
myDoc.viewPreferences.rulerOrigin = oldRuler;
}
}
})();
(function() {
var fileExpression = new RegExp(":", "gi");
var fileName = myWordDocuments.name.replace(fileExpression,"_");
var newFileNameAndPath = myFolder.absoluteURI + "/" + fileName + ".indd";
var newFile = new File(newFileNameAndPath);
app.activeDocument.save(new File(newFile));
//app.activeDocument.close();
})();
}
Copy link to clipboard
Copied
Hi karuppasamyr60357373 ,
just a remark on your code adding a new document:
Best try to add all needed properties while adding the document. Not after the document is added.
Also define properties like documentPreferences.facingPages and documentPreferences.createPrimaryTextFrame.
Or use a predefined document preset.
Below just an example. Note, that master A of a new document is controlling the pages. Margins for master A could be set as app.marginPreferences before adding the document:
// Remember current app margin preferences:
var oldAppMarginPrefs = app.marginPreferences.properties;
// Desired margin preferences for A master of the new document:
app.marginPreferences.properties =
{
bottom : "30 mm" ,
left : "20 mm" ,
right : "15 mm",
top : "15 mm" ,
columnCount : 2 ,
columnGutter : "5 mm"
};
// Add new document with some preferences already set with add():
var newDoc = app.documents.add
(
{
documentPreferences :
{
intent : DocumentIntentOptions.PRINT_INTENT ,
facingPages : true ,
createPrimaryTextFrame : true ,
pageOrientation : PageOrientation.PORTRAIT ,
pagesPerDocument : 12 ,
startPageNumber : 2 ,
pageHeight : "279.4mm" ,
pageWidth : "215.9mm"
},
viewPreferences :
{
rulerOrigin : RulerOrigin.SPREAD_ORIGIN ,
horizontalMeasurementUnits : MeasurementUnits.MILLIMETERS ,
verticalMeasurementUnits : MeasurementUnits.MILLIMETERS
}
}
);
// Reset margin preferences of app to values before:
app.marginPreferences.properties = oldAppMarginPrefs;
About the marginPreferences issue see this old, but still valid reply by Marc Autret here:
[JS][CS4] Minimum document size in javascript?
Correct Answer by Marc Autret, Aug 18, 2011
Regards,
Uwe Laubender
( Adobe Community Professional )
PS: Edited 220613
Fixed the link to Marc Autret's post.
Did also code formatting.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more