I am using Aspose.pdf java in my Talend job, here is a basic breakdown of the job:
- accept PDF file - ok
- search PDF file for certain string - my current problem
- rename PDF file based on certain string - should be ok after problem is solved
I am using Aspose.pdf java in my Talend job, here is a basic breakdown of the job:
Hi Junmil,
Thanks for your inquiry. You can easily search and replace text using Aspose.Pdf. Please check the following documentation links and sample code snippet for the purpose. They will help you accomplish the task.
// Open document
com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document("Sample.pdf");
// Create TextAbsorber object to find all instances of the input search phrase
com.aspose.pdf.TextFragmentAbsorber textFragmentAbsorber = new com.aspose.pdf.TextFragmentAbsorber("12345678 AB");
// Accept the absorber for all the pages
pdfDocument.getPages().accept(textFragmentAbsorber);
// Get the extracted text fragments into collection
com.aspose.pdf.TextFragmentCollection textFragmentCollection = textFragmentAbsorber.getTextFragments();
// Loop through the fragments
for(com.aspose.pdf.TextFragment textFragment : (Iterable)textFragmentCollection) {
System.out.println("Text :- " + textFragment.getText());
System.out.println("Position :- " + textFragment.getPosition());
System.out.println("XIndent :- " + textFragment.getPosition().getXIndent());
System.out.println("YIndent :- " + textFragment.getPosition().getYIndent());
System.out.println("Font - Name :- " + textFragment.getTextState().getFont().getFontName());
System.out.println("Font - IsAccessible :- " + textFragment.getTextState().getFont().isAccessible());
System.out.println("Font - IsEmbedded - " + textFragment.getTextState().getFont().isEmbedded());
System.out.println("Font - IsSubset :- " + textFragment.getTextState().getFont().isSubset());
System.out.println("Font Size :- " + textFragment.getTextState().getFontSize());
System.out.println("Foreground Color :- " + textFragment.getTextState().getForegroundColor());
}
Please feel free to contact us for any further assistance.
Best Regards.
Thanks for the reply, could you shorten the code to search a 50-character string starting from the first instance of “Invoice” searched? Im having a hard time trying to understand all the code, been using Aspose since only yesterday.
Hi Junmil,