Hello Team,
I recently started working with Aspose PDF for Java to perform Text Replacement that should automatically re-arrange page contents. However, I am encountering issues when dealing with tables:
- When I use
ReplaceAdjustment
asWholeWordsHyphenation
, the table lines disappear, as shown in the attached image.
textFragmentAbsorber.getTextReplaceOptions().setReplaceAdjustmentAction(TextReplaceOptions.ReplaceAdjustment.WholeWordsHyphenation);
with-whole-words-hyphenation.PNG (51.7 KB)
- When I do not use
ReplaceAdjustment
or if I useReplaceAdjustment
asNone
, the lines are present, but the contents are not rearranged properly. Specifically, the columns in the table do not adjust correctly if I replace a large text.
textFragmentAbsorber.getTextReplaceOptions().setReplaceAdjustmentAction(TextReplaceOptions.ReplaceAdjustment.None);
without-replace-adjustment.PNG (58.3 KB)
The original PDF file looks like this.
original-pdf-file.png (50.0 KB)
Here is the relevant code snippet:
Document document = new Document(Files.newInputStream(Paths.get(SOURCE_PDF_FILE)));
PageCollection pages = document.getPages();
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("Lorem Ipsum is");
TextSearchOptions textSearchOptions = new TextSearchOptions(true);
textFragmentAbsorber.setTextSearchOptions(textSearchOptions);
textFragmentAbsorber.getTextReplaceOptions().setReplaceAdjustmentAction(TextReplaceOptions.ReplaceAdjustment.WholeWordsHyphenation);
document.getPages().accept(textFragmentAbsorber);
TextFragmentCollection textFragmentCollection = textFragmentAbsorber.getTextFragments();
for (TextFragment textFragment : textFragmentCollection) {
textFragment.setText("Lorem Ipsum is simply dummy text of the printing and typesetting industry.");
}
document.save(Files.newOutputStream(Paths.get(DEST_PDF_FILE)));
Is this a known limitation with tables, or is there a way to achieve the desired behaviour where the table lines are also adjusted, and the content is rearranged correctly?
I am using Aspose PDF with Java 8.
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-pdf</artifactId>
<version>24.6</version>
</dependency>
Thank you for your assistance. Regards.