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

Free Support Forum - aspose.com

Highlight characters within a word ends up on separate line

I have html text that I added to the pdf. When the entire word is highlighted, it display correctly, but when any number of characters highlighted within the word, the word is broken up into separate line.

Hi Tan,


Thanks for your inquiry. We will appreciate it if you please share your source code and sample PDF document, so we will test the scenario at our end and will guide you accordingly…

We are sorry for the inconvenience caused.

Best Regards,

Aspose.Pdf.Generator.Row MyRow = MyTable.Rows.Add();



Text htmlTxt;

htmlTxt = new Text(Server.HtmlDecode(MyRisk.WGAssessment));

htmlTxt.IsHtmlTagSupported = true;

MyRow.Cells.Add().Paragraphs.Add(htmlTxt);



The text string is: Testing of opportunity description. adding new description



The current Aspose.pdf version is 9.7.0.0

Hi Tan,


Thanks for sharing your source document. I am afraid I am unable to replicate the issue while using following code snippet to highlight the complete words or characters with Aspose.Pdf for .NET 9.8.0. Please share your source code you are using to highlight the words/characters, so we will test the scenario at our end and will update you accordingly.

Document document = new Document(myDir

  • “RiskDetailedReport.pdf”);<o:p></o:p>

TextFragmentAbsorber textFragmentAbsorber1 = new TextFragmentAbsorber("or");

document.Pages.Accept(textFragmentAbsorber1);

TextFragmentCollection textFragmentCollection1 = textFragmentAbsorber1.TextFragments;

foreach (TextFragment textFragment in textFragmentCollection1)

{

Aspose.Pdf.InteractiveFeatures.Annotations.HighlightAnnotation freeText = new Aspose.Pdf.InteractiveFeatures.Annotations.HighlightAnnotation(textFragment.Page, new Aspose.Pdf.Rectangle((float)textFragment.Position.XIndent,

(float)textFragment.Position.YIndent, (float)textFragment.Position.XIndent + (float)textFragment.Rectangle.Width,

(float)textFragment.Position.YIndent + (float)textFragment.Rectangle.Height));

freeText.Opacity = 0.5;

freeText.Color = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Blue);

textFragment.Page.Annotations.Add(freeText);

}

document.Save(myDir + "texthighlight_output.pdf");


Best Regards,

I’m sorry, but what you provided is not what I used in my PDF. I’m populating the pdf using a table and adding the html tag within the cell. If you look at my example, I had added a row and then insert the html into the cell. I’m not attempting to highlight or annotate the text. I want to be able to insert html into a cell within a row and have it formatted correctly.



Again the actual html tag that’s being added to the cell is < span style=“background-color: rgb(255, 0, 255);”>Testing < /span >of opportunity < em >description< /em >. adding new < span style=“color: rgb(255, 153, 0);” >description< /span >



I had to separate the html tag in order for it to display it without it begin render.

Hi Tan,


My apologies for the misunderstanding. Please use new DOM approach for scenario, it will help you to accomplish the task. Please check following code sample and documentation links for creating table and adding HTML text.


// Load source PDF document<o:p></o:p>

Aspose.Pdf.Document doc = new Aspose.Pdf.Document();

Page page = doc.Pages.Add();

// Initializes a new instance of the Table

Aspose.Pdf.Table table = new Aspose.Pdf.Table();

table.ColumnAdjustment = ColumnAdjustment.AutoFitToContent;

// Set the table border color as LightGray

table.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray));

// set the border for table cells

table.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray));

// create a loop to add 10 rows

// add row to table

Aspose.Pdf.Row row = table.Rows.Add();

// add table cells

row.Cells.Add("Column 1");

row.Cells.Add("Column 2");

row.Cells.Add("Column 3");

Aspose.Pdf.Row row1 = table.Rows.Add();

row1.Cells.Add("Row2 cell1");

row1.Cells.Add("Row2 cell2");

Aspose.Pdf.Cell cell1 = row1.Cells.Add();

HtmlFragment htmlFragment = new HtmlFragment("Testing of opportunity description. adding new description ");

htmlFragment.Margin.Bottom = 10;

cell1.Paragraphs.Add(htmlFragment);

// Add table object to first page of input document

page.Paragraphs.Add(table);

// Save updated document containing table object

doc.Save(myDir+"document_with_table.pdf");

Please feel free to contact us for any further assistance.


Best Regards,

Thanks for the information. I’ve been using the Aspose.PDF.Generator to create the PDF. Now you’re telling me I need to convert everything over to use Aspose.PDF to make this work?

Hi Tan,


Thanks for the feedback. I am afraid old generator(Aspose.Pdf.Generator) will be obsolete in near future. So please use new generator(Aspose.Pdf.Document) for creating PDF from scratch or manipulating existing PDF. It is more efficient and improved. It is suggested to convert your code to new generator and we will be glad to extend our support in this regards.

Best Regards,