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

Free Support Forum - aspose.com

Aspose PDF Java - Search and replace text in pdf output based on column position

I have a requirement where I have to replace a text with another text using aspose pdf for java.

I have two grids containing some data on different pages. Each grid has some columns.

The search text remains the same but the substituted value changes based on the position of the column.

Please have a look at the attached pdf. I have highlighted what is the requirement on the various pages (at the bottom).

As an update, I have already tried the regular approaches that are there where we iterate over a textfragmentcollection - over the youtube aspose tutorial video.

but, is there something that is there that will help me know that it is part of a column so that I can exploit it to set the replace accordingly.

like apart from getting .getTextFragment().getPosition() and trying to find x,y co-ordinates and interating over the y part to understand which column header it is - whether "Max Inventory Cost" or "Max inventory sale" (from pdf document attached) - is there any other easy to iterate over and find out the particular fragment and replace it.

NOTE: the source file from where its generated has no way to distinguish the columns (apart from the headers) - no difference in color,size,formatting. the only way to know is if that is 999999.






Hi Chetan,


Thanks for your inquiry. I am afraid currently Aspose.Pdf does not support to read/manipulate tables in existing PDF document. So It is not possible to get column/column title information. Currently you can use TextFragment coordinates(esp. x-axis values) and page properties to device some logic for text replacement.

We are sorry for the inconvenience caused.

Best Regards,

Hi Chetan,


Adding more to Tilal’s comments, you may accomplish your requirement by converting PDF files to Excel format using Aspose.Pdf for Java and then use Aspose.Cells for Java to find values in a particular range. The range can be a complete column, some selective cells etc. However when using this approach, the formatting of XLS might not be identical to source PDF file. My fellow worker from Aspose.Cells team will further look into this matter and will share the details regarding searching and replacing text in columns.

PDF -> Excel
[Java]

//
load PDF file
<o:p></o:p>

Document document = new Document("c:/pdftest/Aspose_PDF_issue_mock.pdf");

// save output as Excel file

document.save(<span style=“font-size:9.5pt;
line-height:115%;font-family:Consolas;mso-fareast-font-family:“Malgun Gothic”;
mso-fareast-theme-font:minor-fareast;color:#A31515;background:white;mso-highlight:
white;mso-ansi-language:EN-US;mso-fareast-language:KO;mso-bidi-language:AR-SA”>“c:/pdftest/Aspose_PDF_issue_mock.xls”, com.aspose.pdf.SaveFormat.Excel);

Hi,


Please see the document on how to find and replace your desired text/value in the cells in the specific area of the worksheet using Aspose.Cells APIs, kindly refer to it and try to accomplish your task accordingly:
http://www.aspose.com/docs/display/cellsjava/Search+and+Replace+Cell+Data+inside+a+Range

Hope, this helps a bit.

Thank you.