I'm currently working with HTML text that is highlighted using RGB and RGBA values, however the text using the RGBA value is showing incorrectly after converting to PDF. I have attached code below that includes the sample text used in addition to the implementation of it. It appears that the Blue value of the RGBA text is using the Green value which is causing this discoloration.
Please see the below code & attached output.
Thanks,
Marcus.
- Code: Select all
class Program
{
public static void Main(string[] args)
{
var test = new Program();
string incorrect_text = "<p><span style=\"background-color: rgba(0, 102, 204, 1);\">Blue</span></p>" +
"<p><span style=\"background-color: rgba(0, 138, 0, 1);\">Green</span></p>" +
"<p><span style=\"background-color: rgba(230, 0, 0, 1);\">Red</span></p>" +
"<p><span style=\"background-color: rgba(255, 153, 0, 1);\">Orange</span></p>" +
"<p><span style=\"background-color: rgba(255, 255, 0, 1);\">Yellow</span></p>" +
"<p><span style=\"background-color: rgba(153, 51, 255, 1);\">Purple</span></p>";
string correct_text = "<p><span style=\"background-color: rgb(0, 102, 204);\">Blue</span></p>" +
"<p><span style=\"background-color: rgb(0, 138, 0);\">Green</span></p>" +
"<p><span style=\"background-color: rgb(230, 0, 0);\">Red</span></p>" +
"<p><span style=\"background-color: rgb(255, 153, 0);\">Orange</span></p>" +
"<p><span style=\"background-color: rgb(255, 255, 0);\">Yellow</span></p>" +
"<p><span style=\"background-color: rgb(153, 51, 255);\">Purple</span></p>";
using (var correctDoc = new Document())
{
var docSection = correctDoc.Sections.Count > 0 ? correctDoc.Sections[0] : correctDoc.AddSection();
test.DrawLabelValueElement(docSection, correct_text);
correctDoc.SaveToFile("C:\\test-app\\correct_text.pdf");
}
using (var incorrectDoc = new Document())
{
var docSection = incorrectDoc.Sections.Count > 0 ? incorrectDoc.Sections[0] : incorrectDoc.AddSection();
test.DrawLabelValueElement(docSection, incorrect_text);
incorrectDoc.SaveToFile("C:\\test-app\\incorrect_text.pdf");
}
}
public void DrawLabelValueElement(Section documentSection, string text)
{
Paragraph paragraph = documentSection.AddParagraph();
DrawElement(paragraph, text);
}
public void DrawElement(Paragraph paragraph, string text)
{
var htmlParagraph = paragraph.ParentSection.AddParagraph();
htmlParagraph.AppendHTML(text);
int lastParagraphIndex = paragraph.ParentSection.Paragraphs.Count - 1;
paragraph.ParentSection.Paragraphs[lastParagraphIndex].AppendBreak(BreakType.LineBreak);
}
}