I want to remove content between two text lines. Please see attached file. I want to search “this is heading of level 1” and “this is bullet style 1”. Then I want to remove whatever content in between these two text, i.e. text, image etc.
Please let me know workaround using Java aspose.pdf or Java aspose.pdf.kit as soon as possible.
String path = “c:\pdftest\”;<o:p></o:p>
com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document(path+"testHeading (2).pdf");
//create TextAbsorber object to find all instances of the input search phrase
String from="this is heading of level 1";
String till="this is bullet style 1";
com.aspose.pdf.TextFragmentAbsorber textFragmentAbsorber = new com.aspose.pdf.TextFragmentAbsorber(from+".*"+till,new com.aspose.pdf.TextSearchOptions(true));
//accept the absorber for first page of document
//get the extracted text fragments into collection
com.aspose.pdf.TextFragmentCollection textFragmentCollection = textFragmentAbsorber.getTextFragments();
//loop through the Text fragments
for(com.aspose.pdf.TextFragment textFragment : (Iterable)textFragmentCollection)
// It is enough to remove all segments between the first and the last if they are separate segments.
int size = textFragment.getSegments().size();
//after each deleting size is decremented by 1
textFragment.getSegments().delete(2);//removes the second fragment and recalculates the remaining fragments
The issues you have found earlier (filed as PDFNEWJAVA-33689) have been fixed in Aspose.Pdf for Java 4.2.1.
This message was posted using Notification2Forum from Downloads module by Aspose Notifier.
Thanks a lot.
Hello, I reached this post from searching for a way to search a PDF for a certain string of text. May I know which part of the code above that is? Could you give me a sample code if I were to search for the string “OR Number” in a PDF?