Change Page Header text if size is too long

Community Beginner ,
Jun 07, 2018 Jun 07, 2018

Copy link to clipboard

Copied

Hello! I'm currently having an issue with headers with long texts, and I can't find a good way to solve it.

I'm using a TextVariable of "Running Header (Paragraph Style)" type in order to insert a Page Header in the top of every page.  This Paragraph style i'm using matches a Chapter Name so when the chapter is changed, the page header is changed too.

The issue comes when this text is bigger than the width of the page, so it doesn't fits properly. I've tried solving this issue via scripts, but can't find a way of changing the value of the Text Variable.

Example of what I want to achieve:

Page 1:

Chapter name: "This is a big big big big big big chapter name, so it does not fit properly in my page boundries, I s should be cut."

Resulting Header for Page 1: "This is a big big big big big big chapter name, so it does not fit properly in my page boundries, so you should be cut."

Expected Header:"This is a big big..."  (This is what I want to get, for example)

Page 5: (Here everything is ok, so no need to change it)

Chapter two: "Short beautiful name"

Resulting header: "Short beautiful name"

These are some approaches I've tried:

One of them was searching for the text with my paragraph Style for the Header, and change it to my desired text. The problem with this, is that the paragraph Style is tied with the variable, so I must change the paragraph Style text in order to change the value of the header. I can't change one without changing the other (or did not find a way to do it.)

function findText(para) {

//param is the paragraphStyle name

//Search the chapter Text

//If the text length is bigger than x number, it will slice the text when it finds a space after x chars, and places ...

    app.findTextPreferences = NothingEnum.NOTHING;

    paraStyle = app.activeDocument.

    paragraphStyles.itemByName(para);
    app.findTextPreferences.appliedParagraphStyle = paraStyle;

    var foundText = app.activeDocument.findText();
    var textoAnterior;
    for (var i = 0; i < foundText.length; i++) {

        var textoPara = foundText;
        var texto = textoPara.contents;

        //if (textoAnterior == texto) {


            if (texto.length > 40) {
                var pStyle = app.activeDocument.paragraphStyles.itemByName(para);
                var indexHastaEspacio = texto.indexOf(" ",40);
                var textoHastaEspacio;
                if (indexHastaEspacio > 0 && indexHastaEspacio < 66) {
                    textoHastaEspacio = texto.split(0, indexHastaEspacio);
                } else {
                    textoHastaEspacio = texto.split(0, 40);
                }

                textoHastaEspacio = textoHastaEspacio + "...";  
                alert(textoHastaEspacio);
                findChange(texto, textoHastaEspacio, paraStyle, paraStyle, '', '');

   /*         } else {
                textoAnterior = texto;
            }
            */
        }

    }
}
    function findChange(findWhat, changeTo, findStyle, changeStyle, findChrStyle, changeChrStyle) {
        var doc = app.activeDocument;
        try {
            app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;
            if (findWhat) app.findTextPreferences.findWhat = findWhat;
            if (changeTo) app.changeTextPreferences.changeTo = changeTo;
            if (findStyle) app.findTextPreferences.appliedParagraphStyle = findStyle;
            if (findChrStyle) app.findTextPreferences.appliedCharacterStyle = findChrStyle;


            doc.changeText();         
        } catch (e) {
            alert("Hola" + e);
        }
        app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;
    }

After some searching, seems that the "Running Header (Paragraph Style)" type" can't be changed easily as the Custom Text Type (It does not have a variableOptions.contents option for setting it).

Another solution I tried was changing the appliedParagraph option:

app.activeDocument.textVariables.item("HeaderVariable").variableOptions.appliedParagraphStyle = "AnotherParapraphStyle";

The problem with this, is that I do not have any other parapraph to apply, I just want a slice of my text.

If it helps I'm working  in Indesign 2018, with a template, and placing a Word Document in order to get the text. The variables are set in the Master Pages.

Any help on how to deal with this? Maybe Text Variables are not the best thing for this?

Thanks!

TOPICS
Scripting

Views

597

Likes

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 Beginner , Jun 30, 2018 Jun 30, 2018
Sorry for my late response. I've used a similar approach of what you have said.I change the variable type to a Running Character Style, and via script I add the character style to the amount of chars I want in the header. (The header now has a paragraph style, and a portion of my text has an empty character style)The chracter style I use is blank, so it doesn't change any of my paragraph formatting.

Likes

Translate

Translate
Enthusiast ,
Jun 08, 2018 Jun 08, 2018

Copy link to clipboard

Copied

Never ran into this problem. Let's say you have created a Running Header text variable (call it "FolioLeft"), the style is defined as "Headline1" with Use: First on Page.  Assign the Running Header to a master page text frame. Style the text for this frame as "Folio". The running header text will be that of the first paragraph of the page styled "Headline1".  If the the text for the first paragraph on the page styled "Headline1" is way long, the text for the running header becomes scrunched to fit the frame. The solution, put a hard return in the target paragraph (styled "Headline1") to split it into two paragraphs. Only the text of the first of the resulting two paragraphs is now the text for the running header. (You might need to create a separate paragraph style for the second line in order to set appropriate space above/below values.)

Hope this helps.

Likes

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 Beginner ,
Jun 30, 2018 Jun 30, 2018

Copy link to clipboard

Copied

Sorry for my late response. I've used a similar approach of what you have said.

I change the variable type to a Running Character Style, and via script I add the character style to the amount of chars I want in the header. (The header now has a paragraph style, and a portion of my text has an empty character style)

The chracter style I use is blank, so it doesn't change any of my paragraph formatting.

Likes

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
New Here ,
Apr 09, 2021 Apr 09, 2021

Copy link to clipboard

Copied

LATEST

Hello, I have the same problem, could you comment on how you did the script?
Thank you

Likes

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