Wrap and indent text inside table cell

Hi

I am working on wrapping and indenting text inside cell of a table (AbsorbedTable) in a pdf file. Is there a way/property of textFragments/ cell to format a longer text which is to be substituted in an existing table.

My code to traverse the table.

public Document wrapTableContent(@NonNull Document document, String replaceText){

        TableAbsorber absorber = null;
        for(int i = 1; i <= document.getPages().size(); i++) { //loop through pages
            absorber = new TableAbsorber();
            absorber.visit(document.getPages().get_Item(i));
            for(AbsorbedTable table : absorber.getTableList()){
                for(AbsorbedRow row : table.getRowList()){
                    for(AbsorbedCell cell : row.getCellList()){
                        for(TextFragment fragment : cell.getTextFragments()){
                            fragment.setText(replaceText);
                        }
                    }
                }
            }
        }
        return document;
    }

I want the replaceText value to get adjusted in the cell. Also, is there a property to set indentation of each line in a cell.

@Mojo3991

Thank you for contacting support.

Would you please share sample PDF document and the text you want to replace, in some specific cell so that we may investigate accordingly.

samplePdfAspose.pdf (67.9 KB)
Here in the first page, in the 2nd column of the first row of the table, there is indentation given to the text. I want to replace some text in the similar manner, and also want the text to wrap when given a larger string.

Example: replace “for UC 1.1 type A” with “for UC 1.1, UC 2.1, UC 3.1 and UC 4.2 type A, B C and D”

Hi
I have also tried this approach for giving some indentation to the text in the table, but it is disturbing the complete structure of the page:

public Document indentAndReplaceTokenValueInTables(@NonNull Document document, Map<String, String> map){

        if(CollectionUtils.isEmpty(map))
            return document;

        TableAbsorber absorber = null;
        System.out.println(" number of pages : " + document.getPages().size());
        for(int i = 1; i <= 4; i++) {// loop through pages
            absorber = new TableAbsorber();
            absorber.visit(document.getPages().get_Item(i));
            System.out.println("Page Number : " + i + "   Tables : " + absorber.getTableList().size());
            for(int j = 0; j < absorber.getTableList().size(); j++) { // loop through tables
                System.out.println(" ******* Table number : " + j + " *******");
                int rowInd = 0;
                for (AbsorbedRow row : absorber.getTableList().get_Item(j).getRowList()) { // loop through rows
                    System.out.println("row : " + rowInd);
                    rowInd++;
                    int cellInd = 0;
                    for (AbsorbedCell cell : row.getCellList()) { // loop through row's cells
                        int fragmentInd = 0;
                        System.out.println("cell : " + cellInd);
                        cellInd++;
                        for (TextFragment fragment : cell.getTextFragments()) {
                            String token = ((TextFragment)fragment).getText();
                            System.out.println("fragment "+ fragmentInd + " : " + token);
                            System.out.println(fragment.getPosition().getXIndent() + " : " + fragment.getPosition().getYIndent());
                            if(fragmentInd > 0){
                                Position position = new Position(fragment.getPosition().getXIndent() + 2,
                                        fragment.getPosition().getYIndent());
                                fragment.setPosition(position);
                                System.out.println(fragment.getPosition().getXIndent() + " : " + fragment.getPosition().getYIndent());
                            }
                            fragmentInd++;
                            if (map.containsKey(token)) {
                                //
                            }
                        }
                    }
                }
            }
        }

        return document;
    }

How can we alter the position of the text without affecting rest of the pdf?

@Mojo3991

We are afraid AbsorbedTable class may not detect the lines on the page so the text may not be indented or wrapped in a cell. Please note that Aspose.PDF for Java API mimics the behavior of Adobe Acrobat so please let us know if you are able to achieve these requirements. However, we have tried but text overflows with Adobe Acrobat as per attached screenshot. Acrobat.JPG