We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Pdf edit - search text and remove content in between

Hi,

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.

Thanks.
-Sonali

Hi Sonali,


Thanks for your inquiry. I’m afraid the requested feature is not supported at the moment. However, I’ve logged your request as PDFNEWJAVA-33689 in our issue tracking system for further investigation and implementation. We will update you via this forum thread as soon as its resolved.

We are sorry for the inconvenience faced.

Best Regards,

Hi Sonali,


Thanks for your patience.

We are pleased to share that the feature requested earlier to search text strings and remove the contents between them. The feature will become available in upcoming hotfix of Aspose.Pdf for Java 4.2.1. Please try using the following code snippet to accomplish your requirement.

[Java]

String path = “c:\pdftest\”;<o:p></o:p>

//open document

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

pdfDocument.getPages().accept(textFragmentAbsorber);

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

size++;

//after each deleting size is decremented by 1

while(textFragment.getSegments().size()>2)

{

textFragment.getSegments().delete(2);//removes the second fragment and recalculates the remaining fragments

}

}

pdfDocument.save(path+“testHeading_out.pdf”);

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.

Hi ,

Thanks a lot.

-Sonali

Hi Sonali,


We are glad to hear that you problem is resolved. Please continue using our products and in the event of any further query, please feel free to contact.

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?

Hi Junmil,


Thanks for your inquiry. You can easily search and replace/edit string or number using Aspose.Pdf for Java. I have shared the details in your original query, please check it for the solution.

Best Regards,