Trying to add a background colour when using PdfHTMLTextElement

Please could someone help.  I have the following code to show HTML on my pdf.  I want the text to appear on a coloured background, so I am first drawing a rectangle with the colour box i need and then the html text over the top.  However when i write out the HTML to background colour remains white. 


RectangleF layoutRectangle = new RectangleF((float)rectXStartPos, intY + (borderSize / 2), intWidth - borderSize, height - borderSize);

 PdfBrush backgroundBrush = new PdfSolidBrush(new PdfColor(255, 0, 0));

page.Graphics.DrawRectangle(backgroundBrush, layoutRectangle);

 //HTML TEXT

 string htmlText = objTableSetting.Text;

PdfFont font = CreatePdfFont(FONT_NAME, fontSize, FontStyle.Regular);

PdfHTMLTextElement richTextElement = new PdfHTMLTextElement(htmlText, font, CreateSolidBrush(fontColour));

richTextElement.TextAlign = TextAlign.Left;

 PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();

 format.Layout = PdfLayoutType.Paginate;

format.Break = PdfLayoutBreakType.FitPage;


richTextElement.Draw(page, layoutRectangle, format);

If i replace
richTextElement.Draw(page, layoutRectangle, format);'

with

page.Graphics.DrawString(objTableSetting.Text, CreatePdfFont(FONT_NAME, fontSize, FontStyle.Regular), CreateSolidBrush(fontColour), new RectangleF(intX + 5, intY, intWidth - 6, height), objStringFormat);' 

it works fine and i get my text on a red background, but obviously the html tages are written out.

Can someone help?  Many thanks


3 Replies

CG Caroline Gooding March 12, 2025 07:24 AM UTC

Does anyone know the answer please?  



IJ Irfana Jaffer Sadhik Syncfusion Team March 13, 2025 11:52 AM UTC

Hi Caroline,


Currently we are validating on the reported behavior with the provided details on our end and we will share the further validation on March 17th, 2025.



Regards,

Irfana J.



IJ Irfana Jaffer Sadhik Syncfusion Team March 18, 2025 01:41 PM UTC

Hi Caroline,


We have confirmed the issue “Transparency is not applied while drawing the richtextbox” as a defect in our product and we will include the fix on 8th April 2025 
Please use the below feedback link to track the status of the reported bug.
Note: If you require a patch for the reported issue in any of our Essential Studio Main or SP release version, then kindly let us know the version, so that we can provide a patch in that version based on our SLA policy.
Disclaimer: “Inclusion of this solution in the weekly release may change due to other factors including but not limited to QA checks and works reprioritization.”


Regards,

Irfana J.


Loader.
Up arrow icon