Need RenderedDocument

Hi , i would like to get RenderedDocument.java file. I m not able to download from other forums.

@VishalPro

Can you please provide more details about what you are trying to achieve with the RenderedDocument.java file? Are you looking for a specific functionality or example code?

I would like to get paragraph lines using RenderedCoument
Reference → Paragraph lines/word count

@VishalPro RenderedDocument class has been deprecated and is not provided in the example anymore. You can use LayoutCollector and LayoutEnumerator classes to get layout information from the document. You can use the following code to split the document into lines:

Document doc = new Document("C:\\Temp\\in.docx");

// Split all Run nodes in the document to make them not more than one word.
Node[] runs = doc.getChildNodes(NodeType.RUN, true).toArray();
for (Node n : runs)
{
    Run current = (Run)n;
    while (current.getText().indexOf(' ') >= 0)
        current = SplitRun(current, current.getText().indexOf(' ') + 1);
}

// Wrap all runs in the document with bookmarks to make it possible to work with LayoutCollector and LayoutEnumerator
runs = doc.getChildNodes(NodeType.RUN, true).toArray();
    
ArrayList<String> tmpBookmakrs = new ArrayList<String>();
int bkIndex = 0;
for (Node r : runs)
{
    // LayoutCollector and LayoutEnumerator does not work with nodes in header/footer or in textboxes.
    if (r.getAncestor(NodeType.HEADER_FOOTER) != null || r.getAncestor(NodeType.SHAPE) != null)
        continue;
        
    BookmarkStart start = new BookmarkStart(doc, "r" + bkIndex);
    BookmarkEnd end = new BookmarkEnd(doc, start.getName());
        
    r.getParentNode().insertBefore(start, r);
    r.getParentNode().insertAfter(end, r);
        
    tmpBookmakrs.add(start.getName());
    bkIndex++;
}

// Now we can use collector and enumerator to get runs per line in MS Word document.
LayoutCollector collector = new LayoutCollector(doc);
LayoutEnumerator enumerator = new LayoutEnumerator(doc);
    
Object currentLine = null;
for (String bkName : tmpBookmakrs)
{
    Bookmark bk = doc.getRange().getBookmarks().get(bkName);
        
    enumerator.setCurrent(collector.getEntity(bk.getBookmarkStart()));
    while (enumerator.getType() != LayoutEntityType.LINE)
        enumerator.moveParent();
            
    if (!enumerator.getCurrent().equals(currentLine))
    {
        currentLine = enumerator.getCurrent();
            
        System.out.println();
        System.out.println("-------=========Start Of Line=========-------");
        // Here you can get coordinates of the line.
        System.out.println(enumerator.getRectangle());
    }
        
    Node nextNode = bk.getBookmarkStart().getNextSibling();
    if (nextNode != null && nextNode.getNodeType() == NodeType.RUN)
        System.out.print(((Run)nextNode).getText());
}
private static Run SplitRun(Run run, int position)
{
    Run afterRun = (Run)run.deepClone(true);
    run.getParentNode().insertAfter(afterRun, run);
    afterRun.setText(run.getText().substring(position));
    run.setText(run.getText().substring(0, position));
    return afterRun;
}
```java
private static Run SplitRun(Run run, int position)
{
    Run afterRun = (Run)run.deepClone(true);
    run.getParentNode().insertAfter(afterRun, run);
    afterRun.setText(run.getText().substring(position));
    run.setText(run.getText().substring(0, position));
    return afterRun;
}