• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
8

Script to reverse characters whole page or document

Contributor ,
Aug 12, 2023 Aug 12, 2023

Copy link to clipboard

Copied

Hi All

I have a document that have text frames containes characters are in reverse order

Ex : ( olleh ymar ) intstead of  ( hello ramy )

I want to script that change these reverse to be correct sentences in the curret page or in whole document

Thanks in advance

 

TOPICS
Scripting

Views

1.1K

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
Contributor ,
Aug 12, 2023 Aug 12, 2023

Copy link to clipboard

Copied

Any help Here

Votes

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
Contributor ,
Aug 12, 2023 Aug 12, 2023

Copy link to clipboard

Copied

help here please

Votes

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 Expert ,
Aug 12, 2023 Aug 12, 2023

Copy link to clipboard

Copied

Maybe this will help:

 

https://community.adobe.com/t5/indesign-discussions/how-do-i-change-text-direction-adobe-indesign/m-...

 

ID-Tasker - most powerful tool ever created for InDesign

Votes

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 Expert ,
Aug 12, 2023 Aug 12, 2023

Copy link to clipboard

Copied

Just confirming, your situation is:

1. Ex : ( olleh ymar ) intstead of  ( hello ramy )

or

2. Ex : ( ymar olleh ) intstead of  ( hello ramy )

?

Votes

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
Contributor ,
Aug 12, 2023 Aug 12, 2023

Copy link to clipboard

Copied

1. Ex : ( olleh ymar ) intstead of  ( hello ramy )

Votes

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 Expert ,
Aug 13, 2023 Aug 13, 2023

Copy link to clipboard

Copied

Interesting! I am very curious how you got a document with words that are reversed. Quite unique! I have written a script that will reverse each word. Give it a try and see if it helps.

- Mark

 

 

/**
 * @discussion https://community.adobe.com/t5/indesign-discussions/script-to-reverse-characters-whole-page-or-document/m-p/14003574
 */
app.doScript(reverseWords, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Script');


/**
 * Reverse order of characters of words of
 * (a) selection, if any, or of
 * (b) the entire active document.
 * @author m1b
 * @version 2023-08-13
 * @Param {Text|TextFrame|Document} [texts] - the text or contiainer to reverse (default: active document).
 */
function reverseWords(texts) {

    texts = texts || app.selection[0];

    if (!texts)
        texts = app.activeDocument.stories.everyItem().getElements();

    if (texts.hasOwnProperty('stories'))
        texts = texts.stories.everyItem().getElements();

    if (texts.constructor.name !== 'Array')
        texts = [texts];

    /* uncomment the following lines to customize the deinfition of "word"
        app.findGrepPreferences = NothingEnum.NOTHING;
        app.changeGrepPreferences = NothingEnum.NOTHING;
        app.findGrepPreferences.findWhat = '[[:alnum:]]+';
    */

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

        if (
            !texts[i].isValid
            || !texts[i].hasOwnProperty('words')
        )
            continue;

        /* use the following definition of "words" if using findGrep */
        // var words = texts[i].findGrep();

        /* ... otherwise use Indesign's definition */
        var words = texts[i].words;

        for (var w = 0; w < words.length; w++) {

            var charCount = words[w].characters.length - 1;

            // add characters in reverse order
            for (var j = charCount; j >= 0; j--)
                words[w].characters[j].duplicate(LocationOptions.AT_END, words[w]);

            // remove the original text
            words[w].characters.itemByRange(0, charCount).remove();

        }

    }

};

 

 

Edit 2023-08-13: changed definition of "words" to use Indesign's normal definition.

Votes

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 Expert ,
Aug 13, 2023 Aug 13, 2023

Copy link to clipboard

Copied

Out of curiosity - why do you assume that numbers are not reversed as well? 

 

ID-Tasker - most powerful tool ever created for InDesign

Votes

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 Expert ,
Aug 13, 2023 Aug 13, 2023

Copy link to clipboard

Copied

@Robert Tkaczyk, because I had no idea what I was talking about! 🙂  I see now that numbers will be reversed as well.

Votes

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 Expert ,
Aug 13, 2023 Aug 13, 2023

Copy link to clipboard

Copied

I think everything between whitespaces should be reversed - as long as really each part is reversed individually... 

 

"ramy hello" is perfectly valid phrase ... 

 

ID-Tasker - most powerful tool ever created for InDesign

Votes

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 Expert ,
Aug 13, 2023 Aug 13, 2023

Copy link to clipboard

Copied

I think you are probably right and so I have updated script.

Votes

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 Expert ,
Aug 13, 2023 Aug 13, 2023

Copy link to clipboard

Copied

Why not "move" instead of "duplicate" characters? You are going in reverse anyway so it should work?

 

ID-Tasker - most powerful tool ever created for InDesign

Votes

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 Expert ,
Aug 13, 2023 Aug 13, 2023

Copy link to clipboard

Copied

I don't know why, except I couldn't get move to work (it was my first choice). It said something about not able to move text into itself I think.

Votes

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 Expert ,
Aug 13, 2023 Aug 13, 2023

Copy link to clipboard

Copied

Maybe it would work if you select as a destination InsertionPoint after the Word - instead of the Word itself? 

 

words[w].characters[j].move(LocationOptions.AT_END, words[w].insertionPoints[-1]);

 

ID-Tasker - most powerful tool ever created for InDesign

Votes

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 Expert ,
Aug 13, 2023 Aug 13, 2023

Copy link to clipboard

Copied

I get:

Exception has occurred: 519
Text cannot be moved to its current location.

Votes

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 Expert ,
Aug 13, 2023 Aug 13, 2023

Copy link to clipboard

Copied

Right... 

 

How about referring to the character of the parent Story for the character to be moved - not the character of the word?

 

Something like:

 

word[w]. parentStory.characters[word[w].characters[j].index].move(...)

 

Or with "()" to get a reference to the character. 

 

But in the end it's probably unnecessary complication, that will work much slower than your initial deletion of the source part of the word?

 

ID-Tasker - most powerful tool ever created for InDesign

Votes

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 Expert ,
Aug 12, 2023 Aug 12, 2023

Copy link to clipboard

Copied

Did you try to choose a different composer in the paragraph style settings > Fine Tuning?

Votes

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
Contributor ,
Aug 13, 2023 Aug 13, 2023

Copy link to clipboard

Copied

The subject is that I installed a plugin that convert from pdf to indd that works only LTR , when i tried it on an arabic pdf , arabic characters are reversed , I want the script for this reason

Votes

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 Expert ,
Aug 13, 2023 Aug 13, 2023

Copy link to clipboard

Copied

Ah! So what happens to punctuation?

Is "hello ramy." written as (1) "olleh .ymar" or (2) "olleh ymar."

Votes

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 Expert ,
Aug 13, 2023 Aug 13, 2023

Copy link to clipboard

Copied

@r28071715i111 - can you post example screenshot?

 

ID-Tasker - most powerful tool ever created for InDesign

Votes

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
Guide ,
Aug 13, 2023 Aug 13, 2023

Copy link to clipboard

Copied

Reversing the character order is the wrong approach.

There are ME versions of InDesign for a reason.

https://helpx.adobe.com/indesign/using/arabic-hebrew.html

 

 

Votes

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 Expert ,
Aug 13, 2023 Aug 13, 2023

Copy link to clipboard

Copied

The source is something extracted from the PDF - not the original INDD file... 

 

ID-Tasker - most powerful tool ever created for InDesign

Votes

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 Expert ,
Aug 13, 2023 Aug 13, 2023

Copy link to clipboard

Copied

You are right @Dirk Becker, (and @Willi Adelberger too of course), but I am assuming the OP has reached for a last resort. It will not be pretty, but it may save them some time.

Votes

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 Expert ,
Aug 13, 2023 Aug 13, 2023

Copy link to clipboard

Copied

@m1b 

Mark -- Reversing each individual word (i.e. changing the character direction but not the paragraph direction) may not be the correct approach, but, just for interest's sake, there is a much shorter and quicker way to do it. Copying (or moving) characters as character objects is very slow. Just reverse the strings:

 

words = app.documents[0].stories.everyItem().words.everyItem().getElements();
for (var i = words.length-1; i >= 0; i--) {
  words[i].contents = words[i].contents.split('').reverse().join('');
}

 

See also https://community.adobe.com/t5/indesign-discussions/reversing-selected-text-or-paragraph/m-p/6497724

 

P.

Votes

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 Expert ,
Aug 13, 2023 Aug 13, 2023

Copy link to clipboard

Copied

But I think you are forgetting about one thing @Peter Kahrel - what if there are different CharStyles applied - or local formatting?

 

ID-Tasker - most powerful tool ever created for InDesign

Votes

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