we have a list of some words and we want to strikout those words in existing pdf. so any body can tell me how can i strikout words in pdf using StrikOutAnnoation class?
This is my code which is iam trying to strikout but it is not working?
Document document = new Document(pdf);
String[] scaryArray =inputScaryWords.split(",");
//text will be searched and replaced here
for (String wrd : scaryArray) {
String pattern = wrd;
Pattern r = Pattern.compile(pattern, Pattern.DOTALL);
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("(?i:" +"\\b" + r + "\\b" + ")"
, new TextSearchOptions(true));
for (int i = 1; i <= document.getPages().size(); i++) {
Page page = document.getPages().get_Item(i);
page.accept(textFragmentAbsorber);
}
// Create a collection of Absorbed text
TextFragmentCollection textFragmentCollection = textFragmentAbsorber.getTextFragments();
//Iterate on above collection
for (int j = 1; j <= textFragmentCollection.size(); j++) {
TextFragment textFragment = textFragmentCollection.get_Item(j);
com.aspose.pdf.Rectangle rect = new com.aspose.pdf.Rectangle(
(float)textFragment.getPosition().getXIndent(),
(float)textFragment.getPosition().getYIndent(),
(float)textFragment.getPosition().getXIndent()+
(float)textFragment.getRectangle().getWidth(),
(float)textFragment.getPosition().getYIndent() +
(float)textFragment.getRectangle().getHeight());
StrikeOutAnnotation strikeOut = new StrikeOutAnnotation(textFragment.getPage(), rect);
//Create a new section in the Pdf object
strikeOut.setOpacity(.80);
strikeOut.setBorder(new Border(strikeOut));
textFragment.getPage().getAnnotations().add(strikeOut);
}
}
//Output file names according to their input files
String outputFileRiskAnnotation = pdf.substring(0, pdf.lastIndexOf(".pdf")) + "_annotation.pdf";
System.out.println(outputFileRiskAnnotation);
//save updated document
document.save(outputFileRiskAnnotation);