Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Fri Feb 10, 2023 12:33 am

Hi there,

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);
        }
    }

marcus.m
 
Posts: 2
Joined: Thu Feb 09, 2023 11:26 pm

Fri Feb 10, 2023 7:52 am

Hello,

Thanks for your inquiry.
According to your code, I reproduced your issue and logged it into our bug tracking system with the ticket number SPIREDOC-9041. Our development team will investigate and fix it. Once it is resolved, I will inform you in time. Sorry for the inconvenience caused.
However, before fixing this bug, you can use the Spire.Pdf’s function of converting Html to Pdf, I put the code below for your reference. And I attached link of the help document about how to using QT plugin to convert html to pdf.

help document: https://www.e-iceblue.com/Tutorials/Spi ... lugin.html

Code: Select all
  string input = @"<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 outputFile = @"../../output/ToPDF.pdf";

            Spire.Pdf.HtmlConverter.Qt.HtmlConverter.PluginPath = @"E:\\QtPlugin\\5.14.2\\qt-5.14.2-plugins-windows-x64\\plugins";
            Spire.Pdf.HtmlConverter.Qt.HtmlConverter.Convert(input,

            outputFile,
            //enable javascript
            true,
            //load timeout
            10 * 1000,
            //page size
            new SizeF(612, 792),
            //page margins
            new Spire.Pdf.Graphics.PdfMargins(0),
            //load from content type
            LoadHtmlType.SourceCode
            );


Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 860
Joined: Tue Mar 08, 2022 2:02 am

Sun Feb 12, 2023 10:18 pm

Hi there,

Thanks for the quick response, the plugin is not something that I'd like to use going forward.

Would you have an ETA on the bug fix for the Spire.Doc implementation?

Thanks,
Marcus.

marcus.m
 
Posts: 2
Joined: Thu Feb 09, 2023 11:26 pm

Mon Feb 13, 2023 10:17 am

Hello,

Thanks for your feedback.
Sorry I can’t share any ETA at this moment, our Dev team is working on your issue now. I have requested them to share any available estimate at their earliest, if there is any good news, we will notify you immediately. Thanks for your understanding.

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1261
Joined: Wed Apr 25, 2018 3:20 am

Wed Feb 22, 2023 5:45 am

Hello,

Thanks for your patience!
Glad to inform you that we just released Spire.Office 8.2.2 which fixes the issue with SPIREDOC-9041.

Please download the new version from the following links to test.
Website download link: https://www.e-iceblue.com/Download/down ... t-now.html
Nuget download link: https://www.nuget.org/packages/Spire.Office/8.2.2

Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 860
Joined: Tue Mar 08, 2022 2:02 am

Return to Spire.Doc