Skip to main content
Participant
July 10, 2017
Question

Text frames disappearing after applying a ParagraphStyle

  • July 10, 2017
  • 3 replies
  • 1821 views

I don't have a lot of Indesign experience to say the least but I was asked to investigate if it was possible (using indesign server of scripting) to start a new document, apply a master spread page, insert some paragraphs and applying some paragraph styles.

The solution I came up is this

// define template

var indesignTemplate = new File("/e/boek_NL.indt");

// open the template

var doc = app.open(indesignTemplate);

// get master page

var masterPage = doc.masterSpreads.item("A-Master");

// get first page

var page = doc.pages.item(0);

// apply master page to our first page

page.appliedMaster = masterPage

// get paragraph style

var paragraphStyle = doc.paragraphStyles.item("_2.ondertitel_bladzijde");

for (var i = 0; i < masterPage.textFrames.length; i++) {

     var textframe = masterPage.textFrames.item(i);

    if (textframe.label === "flow") {

        for (var x = 0; x < 5; x++) {

            // insert another new paragraph

            textframe.parentStory.insertionPoints.item(-1).contents = "text \r\r";

        }

       for (var x = 0; x < textframe.paragraphs.length; x++) {

         textframe.paragraphs.item(0).applyParagraphStyle(paragraphStyle);

       }

     }

}

//Save the document (fill in a valid file path).

doc.save(new File("/c/boek_nl.indd"));

// Save the document as an PDF

doc.exportFile(ExportFormat.pdfType, new File("/c/boek_nl.pdf"));

// close the document.

app.documents.item(0).close();

This works and can see my text when I comment out the applyParagraphStyle code.

From the moment that I try to apply a paragraphStyle the text gets hidden, that in the generated PDF as the INDD file. When I then open the saved indd file in Indesign and command+shift click in the empty text frame, the text appears and I also see an extra layer appearing.

I also tried applying CharacterStyles in more or less the same way but that doesn't give any problems.

I assume that the problem lays in the fact that I'm may approaching this in the wrong way ?

This topic has been closed for replies.

3 replies

Participant
July 10, 2017

Hi,

text is not overflowwing and setting for example the paragraph style through parentStory.apliedParagraphStyle results also in the same behaviour   (Although in reality it will be that I may need to set each paragraph with a different paragraph style)

I will try to investigate further

Jump_Over
Legend
July 10, 2017

Is your goal to apply and format text on MasterSpread?

Do it first and apply Master to page after, maybe...

Jarek

Participant
July 11, 2017

No, I must stress that I'm a total noob in the indesign department so I could be doing something horrible wrong.

My idea is that I select a master spread, apply it to a page, fill in the text frames (with a scripting label flow) that came with the spread, alter some paragraphs and save it as a PDF for now.

.recompose() was also something I tried but didn't fix my problem unfortunately.

Jump_Over
Legend
July 10, 2017

Hi,

If your goal is to apply the same paraStyle to every para (entire story) - use:

textframe.parentStory.appliedParagraphStyle = paragraphStyle;

Basically it does not look like a wrong way (iterate through paragraphs using 'x' instead of '0').

Search for the reason in your paraStyle definition or textFrame properties.

Jarek

tpk1982
Legend
July 10, 2017

Is it the texts overflowed?