How to StrikOut Words in PDF

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);

Hi Rohit,


Thanks for contacting support.

I am afraid currently Aspose.Pdf for Java does not support the feature to StrikeOut (StrikeOut) text in existing PDF files. However for the sake of implementation, I have logged this requirement as PDFNEWJAVA-34476 in our issue tracking system. We will further look into the details of this requirement and will keep you posted on the status of correction. Please be patient and spare us little time.

We are sorry for this inconvenience.
This is working

StrikeOutAnnotation strikeOut = new StrikeOutAnnotation(textFragment.getPage(), rect);
//Create a new section in the Pdf object
strikeOut.setOpacity(.80);
strikeOut.setBorder(new Border(strikeOut));
strikeOut.setColor(com.aspose.pdf.Color.getRed());
textFragment.getPage().getAnnotations().add(strikeOut);

Hi Rohit,


Thanks for sharing the feedback. During my testing, I have observed that StrikeOut annotation is properly being added to PDF document. It appears that setting of color for annotation is mandatory. Besides this, during my earlier attempt, I tried using createMarkup(…) method of PdfContentEditor class which provides the feature to make the text as strikeout but with current release of Aspose.Pdf for Java, the feature seems to have some issue. The problem has already been logged in our issue tracking system. The development team will further investigate the issue and will keep you posted on the status of correction.

However we are pleased to hear that your requirement is accomplished while using StrikeOutAnnotation instance. Please continue using our API and in the event of any further query, please feel free to contact.

Hi Rohit,


Adding more to my previous comments, please note that the fragments may contain one or more segments, so the appropriate approach will be to work with the internal segments as well.

[Java]

for (TextSegment ts : (Iterable<TextSegment>)textFragment.getSegments())<o:p></o:p>

{

StrikeOutAnnotation strikeOut = new StrikeOutAnnotation(textFragment.getPage(), ts.getRectangle());

//Create a new section in the Pdf object

strikeOut.setOpacity(.80);

strikeOut.setBorder(new Border(strikeOut));

strikeOut.setColor(com.aspose.pdf.Color.getRed());

textFragment.getPage().getAnnotations().add(strikeOut);

}