PDF Content Editor with WholeWordsHyphenation option

I am trying to replace few text with the content editor. The wrap functionality is not working as expected.After_Text_replace.jpg (14.1 KB)
Before_Text_Replace.jpg (11.6 KB)

@venkatesh2382

Would you kindly share your source PDF document along with complete code snippet. We will test the scenario in our environment and address it accordingly.

@asad.ali Attached below is the code snippet, you can replace the destination string with any value. I am pulling it from a json file.

contentEditor.bindPdf(inputfilepath);
TextReplaceOptions textReplaceOptions = new TextReplaceOptions();
textReplaceOptions.setReplaceScope(TextReplaceOptions.Scope.REPLACE_ALL);
textReplaceOptions.setReplaceAdjustmentAction(TextReplaceOptions.ReplaceAdjustment.WholeWordsHyphenation);
contentEditor.setTextReplaceOptions(textReplaceOptions);
ReplaceTextStrategy replaceTextStrategy = new ReplaceTextStrategy();
contentEditor.replaceText(“MEMBER_NAME”, (String) emp.get(“MEMBER-NAME”));
contentEditor.replaceText(“MEMBER_DOB”, (String) emp.get(“YMDBIRTH”));
contentEditor.replaceText(“PCP_NAME”, (String) emp.get(“PCP-NAME”));
contentEditor.replaceText(“PCP_PHONE”, (String) emp.get(“PCP-PHONE”));
contentEditor.replaceText(“PCP_ADDRESS”,pcp_address);
contentEditor.save(outputfilepath);Peachstate_IDcards_p4hb_pip_wl.pdf (878.7 KB)

@venkatesh2382

We tested the scenario using recommended approach to find/replace text with Aspose.PDF for Java 20.6 and were able to notice the similar issue:

java.util.List<String> keywords = new java.util.ArrayList<String>();
keywords.add("MEMBER_NAME");
keywords.add("MEMBER_DOB");
keywords.add("PCP_NAME");
keywords.add("PCP_PHONE");
keywords.add("PCP_ADDRESS");
Document doc = new Document(dataDir + "Peachstate_IDcards_p4hb_pip_wl.pdf");
for(String s:keywords){
 TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber(s);         
 textFragmentAbsorber.getTextReplaceOptions().setReplaceAdjustmentAction(TextReplaceOptions.ReplaceAdjustment.WholeWordsHyphenation);
 doc.getPages().get_Item(1).accept(textFragmentAbsorber);
 TextFragmentCollection textFragmentCollection = textFragmentAbsorber.getTextFragments();
 for (TextFragment textFragment : textFragmentAbsorber.getTextFragments()) {
                if(s == "MEMBER_NAME"){
                    textFragment.setText("DERRICK WHITE");
                }
                else if (s == "MEMBER_DOB"){
                    textFragment.setText("11/19/2003");
                }
                else if (s == "PCP_NAME"){
                    textFragment.setText("Willie Claire");
                }
                else if (s == "PCP_PHONE"){
                    textFragment.setText("770-907-4949");
                }
                else if (s == "PCP_ADDRESS"){
                    textFragment.setText("1324 Highway 138 SE,Riverdale GA 30296");
                }
   }
}
doc.save(dataDir + "20.6_out.pdf");

Therefore, we have logged an issue as PDFJAVA-39598 in our issue tracking system. We will further look into its details and keep you posted with the status of its resolution. Please be patient and spare us some time.

We are sorry for the inconvenience.

@asad.ali thanks!!! how to track the issue and is there any ETA. We purchased aspose total recently hoping that these things will work out of box. Is there any paid support available? I see we are facing many more issues with the PDF’s converting to PDF/A as well.

@venkatesh2382

The issue has been logged in free support model where issues are resolved on first come first serve basis. The ticket is logged in our internal issue management system which you cannot access. However, we will keep you posted with the status of its resolution within this forum thread.

Yes, we also offer paid/priority support where issues have high priority and are resolved on urgent basis. You may please check it as well.

@venkatesh2382

We have further investigated the issue and found that a new paragraph could not be much wider than it was if WholeWordsHyphenation option is used then it leads to text wrapping. So there should another adjustment for the first (and maybe some next) line. Please see a code snippet below. Also pay attention on the option setAdjustmentNewLineSpacing().

java.util.List<String> keywords = new java.util.ArrayList<String>();
keywords.add("MEMBER_NAME");
keywords.add("MEMBER_DOB");
keywords.add("PCP_NAME");
keywords.add("PCP_PHONE");
keywords.add("PCP_ADDRESS");
Document doc = new Document(testdata + "PDFJAVA_39598/Peachstate_IDcards_p4hb_pip_wl.pdf");

for (String s : keywords) {
  TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber(s);
  textFragmentAbsorber.getTextReplaceOptions().setAdjustmentNewLineSpacing(1);

   if (s == "PCP_ADDRESS") {
       textFragmentAbsorber.getTextReplaceOptions().setReplaceAdjustmentAction(TextReplaceOptions.ReplaceAdjustment.WholeWordsHyphenation);       
   } else {                    
       textFragmentAbsorber.getTextReplaceOptions().setReplaceAdjustmentAction(TextReplaceOptions.ReplaceAdjustment.AdjustSpaceWidth);
   }            

  doc.getPages().get_Item(1).accept(textFragmentAbsorber);            
  for (TextFragment textFragment : textFragmentAbsorber.getTextFragments()) {
      if (s == "MEMBER_NAME") {
         textFragment.setText("DERRICK WHITE");                    
      } else if (s == "MEMBER_DOB") {
         textFragment.setText("11/19/2003");
      } else if (s == "PCP_NAME") {
         textFragment.setText("Willie Claire");
      } else if (s == "PCP_PHONE") {
         textFragment.setText("770-907-4949");
      } else if (s == "PCP_ADDRESS") {
         textFragment.setText("1324 Highway 138 SE, Riverdale GA 30296");
      }
   }
}