Hi Team,
We have a requirement where we need to print Excel in PDF format, we’re using Aspose.Cells to perform this action.
But we’re facing one issue. Whenever we’re converting Excel to PDF, there are some cells which have background color, which is working fine but we have a new requirement where we need to add background color to some part of the text within a cell which is not supported by Microsoft Excel.
We’re trying to edit the converted PDF, but we’re not able to figure the way to determine the coordinates in PDF. For Example, Cell A5 has text ASDFGHJKL and we want to add background color to FGH in the output PDF. Can you suggest a way to achieve this?
Thanks
@shivanandchikkalli
Can you please share the converted PDF file with us? We will test the scenario in our environment and address it accordingly.
@shivanandchikkalli
You can use search and highlight functionality of Aspose.PDF for .NET in order to achieve your requirements. For example, the below code snippet:
Document doc = new Document(file);
TextFragmentAbsorber tfa = new TextFragmentAbsorber(searchkeyword, new TextSearchOptions(true));
doc.Pages.Accept(tfa);
TextFragmentCollection tfc = tfa.TextFragments;
if (tfc.Count > 0)
{
foreach (TextFragment frag in tfc)
{
frag.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Black);
frag.TextState.BackgroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Yellow);
}
}
You can specify a regular expression for searchkeyword
in order to find the string and then change its background color. In case you face any issues, please let us know.
we’re looking for more precise approach i.e., we have the row number and column number info from Excel, but once converted to PDF, is there any way to determine the exact coordinates as in PDF?
@shivanandchikkalli
We are afraid that this cannot be possible as tables behave differently in PDF format as compared to Excel. In order to find table cell data in PDF, you can search the specific text and once it is found, you can determine its coordinates.