Skip to main content
Participant
January 25, 2024
Question

Access indesign document contains using textrange

  • January 25, 2024
  • 1 reply
  • 185 views

Is there any way to get indesign document contains as a PMString ? cause I was trying to get paragraph return character as an unicode for a comparison but couldnt find a way to achive that

ex:- 

I tried using InDesign::TextRange to traverse around document contains and find each text parcel's length, start and end positions,  but couldnt found a way to get parcel contains into a PMString or wideString varible, 

 help me to that problem.. Thanks in advance.

 

below picture my target was to get paragraph return character which on last line 

 

 

This topic has been closed for replies.

1 reply

Community Expert
March 10, 2024

Hello

 

I'm quite sure I'm not the best person to answer this - but I'll give it a go - maybe it can inspire you to find a better solution

 

 

// Assuming you have a reference to an InDesign document called myDocument
var myDocument = app.activeDocument;

// Assuming you have a TextFrame or any other text container in the document
var textFrame = myDocument.textFrames[0]; // Replace [0] with the index of your desired text frame

// Get the text contents of the text frame
var text = textFrame.texts.everyItem().getElements();

// Loop through each text object
for (var i = 0; i < text.length; i++) {
    var textRange = text[i].characters.everyItem().getElements(); // Get all characters in the text object
    
    // Loop through each character in the text object
    for (var j = 0; j < textRange.length; j++) {
        // Convert the character to a PMString or WideString
        var character = textRange[j].contents; // This will give you the Unicode value of the character
        
        // You can perform any comparison or manipulation here using the character variable
        // For example, you can compare it with the Unicode value of the paragraph return character
        if (character.charCodeAt(0) === 13) {
            // Do something when the paragraph return character is found
        }
    }
}