We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Multiple setText() on fragments of a table are breaking the pdf

Using java 8 and aspose.pdf v19.10.
The below code replace all blank cells with the “REPLACED TEXT”. But when changing font and font size, the table gets haywire.
Screenshot from 2019-12-02 12-51-43.png (4.8 KB)

All the empty cells, except the first one gets gibrish placed in them.
see the following code

for (AbsorbedCell cell : row.getCellList()) {
    for (TextFragment fragment : cell.getTextFragments()) {
        String token = fragment.getText().trim();
        if (token.length()==0) {
            fragment.setText("REPLACED TEXT");


Would you kindly share the sample PDF document along with complete code snippet that you are using. Also, please share the values for font size and font name so that scenario can be tested and addressed accordingly.

Here is the code -

import com.aspose.pdf.AbsorbedCell;
import com.aspose.pdf.AbsorbedRow;
import com.aspose.pdf.AbsorbedTable;
import com.aspose.pdf.Document;
import com.aspose.pdf.Font;
import com.aspose.pdf.FontRepository;
import com.aspose.pdf.TableAbsorber;
import com.aspose.pdf.TextFragment;

import java.util.LinkedList;
import java.util.List;

public class Test {
    private static final String INPUT_FILE = "/Downloads/d.pdf";
    private static final String OUTPUT_FILE = "test.pdf";

    private static final Font FONT = FontRepository.openFont("ARIALN.TTF"); //Arial Narrow
    private static final float FONT_SIZE = 10f;

    public static void main(String[] args) {
        Document document = new Document(INPUT_FILE);
        replaceBlanks(document, 1, 1);

    // consider pageNumber and tableNumber index starting from 1
    public static void replaceBlanks(Document document, int pageNumber, int tableNumber) {
        String toReplaceWith = "REPLACED TEXT";
        List<AbsorbedTable> absorbedTables = new LinkedList<>();

        TableAbsorber absorber = new TableAbsorber();

        for (int j = 0; j < absorber.getTableList().size(); j++) {
        // sorting according to the Y co-ordinate of the table rectangle
        absorbedTables.sort((t1, t2) -> (int) (t2.getRectangle().getLLY() - t1.getRectangle().getLLY()));

        for (AbsorbedRow row : absorbedTables.get(tableNumber - 1).getRowList()) { // loop through rows
            for (AbsorbedCell cell : row.getCellList()) { // loop through row's cells
                for (TextFragment fragment : cell.getTextFragments()) {
                    String token = fragment.getText().trim();
                    if (token.length() == 0) {

d.pdf (11.9 KB)


Thanks for sharing requested information.

We have tested the scenario using Aspose.PDF for Java 19.11 and were able to notice the issue. For the purpose of correction, we have logged it under the ticket ID PDFJAVA-39033 in our issue tracking system. We will further look into details of the issue and keep you informed with the status of its correction. Please spare us little time.

We are sorry for the inconvenience.

1 Like