Transparent text fails in transparent text boxes on DocIO to PDF conversion

Hi,
I've encountered a bug where transparent text sometimes doesn't carry over to a converted pdf. I'm finding fully replicating this bug difficult, but this generally seems to be the issue:
Using version: 18.3.0.38
When text.Color is set to Color.Transparent AND the textbox fill colour is set to Color.Transparent, the result is text that renders black. However, if any other fill colour is selected, the text renders invisible. I don't know how sophisticated this is: is the text colour simply matching the fill colour? So if a text box fill = Color.Red and text.Color = Color.Transparent is the library simply saying "set text.Color = textbox.FillColor"?
I also get odd behaviour in my application, for example sometimes text that is set to transparent in a textbox that has a fill colour of blue will render in black, and other times will render invisible. I cannot manage to control this, the same codebase can produce different results.
In any case, there is certainly some bug (or lack of feature?) causing this problem. I submit the below method that should illustrate it. The method will create a word document and then convert that to a pdf. If the textBox.TextBoxFormat.FillColor = Color.Red and text.CharacterFormat.TextColor = Color.Transparent then in the word document it will render white and in the pdf it will render invisible. If textBox.TextBoxFormat.FillColor = Color..Transparent and  text.CharacterFormat.TextColor = Color.Transparent then in the word document it will render white and in the pdf it will render black.

I've also attached 2 pdf documents. One with text rendered invisible and one with text rendered as black. The text in question is on the second page, marked P4. The character pair "Ey" should be invisible but on one pdf has rendered visible. These pdf files were created with the same code. It simply does:
ProcessText(bool hidden, string textToAppend, IWParagraph paragraph)
{
var text = paragraph.AppendText(textToAppend);
text.CharacterFormat.TextColor = hidden ? Color.Transparent: Color.Black;
}

Please also note, I require that the text boxes are fill colour transparent, they are blue for testing purposes. Also, pdfs were rendered using version 18.3.0.38.


public static void Convert()
        {
            PdfUnitConverter converter = new PdfUnitConverter();
            WordDocument wordDoc = new WordDocument();
            var section = wordDoc.AddSection();
            section.PageSetup.PageSize =
                new SizeF(converter.ConvertUnits(132PdfGraphicsUnit.Millimeter, PdfGraphicsUnit.Point),
                    converter.ConvertUnits(150PdfGraphicsUnit.Millimeter, PdfGraphicsUnit.Point));
            var paragraph = section.AddParagraph();
 
            IWTextBox textBox = paragraph.AppendTextBox(converter.ConvertUnits(50PdfGraphicsUnit.Millimeter, PdfGraphicsUnit.Point),
                    converter.ConvertUnits(50PdfGraphicsUnit.Millimeter, PdfGraphicsUnit.Point));
 
            //Sets up some generic formatting such as making the box transparent and without a border
            textBox.TextBoxFormat.NoLine = true;
            textBox.TextBoxFormat.FillColor = Color.Red;
            textBox.TextBoxFormat.AutoFit = false;
            textBox.TextBoxFormat.InternalMargin.Bottom = 0;
            textBox.TextBoxFormat.InternalMargin.Top = 0;
            textBox.TextBoxFormat.InternalMargin.Left = 0;
            textBox.TextBoxFormat.InternalMargin.Right = 0;
 
            //add a paragraph
            var textBoxParagraph = textBox.TextBoxBody.AddParagraph();
            textBoxParagraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Right;
 
            textBoxParagraph.ParagraphFormat.AfterSpacing = 0;
 
            var text = textBoxParagraph.AppendText("test\ntest2\ntest3");
            text.CharacterFormat.TextColor = Color.Transparent;
            var wordDocConverter = new DocIORenderer { Settings = { EmbedFonts = true, EmbedCompleteFonts = true } };
 
            PdfDocument pdfDocument = null;
 
            pdfDocument = wordDocConverter.ConvertToPDF(wordDoc);
 
 
            using (MemoryStream stream = new MemoryStream())
            {
                //Saves the document to stream
                wordDoc.Save(stream, Syncfusion.DocIO.FormatType.Docx);
                stream.Seek(0SeekOrigin.Begin);
                using (FileStream fs = new FileStream("D:\\" + Guid.NewGuid().ToString() + "outputWordDoc.docx"FileMode.OpenOrCreate))
                {
                    stream.CopyTo(fs);
                    fs.Flush();
                }
            }
 
            wordDocConverter.Dispose();
            wordDoc.Dispose();
 
            using (MemoryStream stream = new MemoryStream())
            {
                //Saves the document to stream
                pdfDocument.Save(stream);
                stream.Seek(0SeekOrigin.Begin);
                using (FileStream fs = new FileStream("D:\\" + Guid.NewGuid().ToString() + "outputpdfConverted.pdf"FileMode.OpenOrCreate))
                {
                    stream.CopyTo(fs);
                    fs.Flush();
                }
                pdfDocument.Close();
                pdfDocument.Dispose();
            }
 
        }

Attachment: invisibletext_1818f13d.zip

5 Replies 1 reply marked as answer

HC Hemalatha Chiranjeevulu Syncfusion Team November 4, 2020 07:59 PM UTC

Hi Will,

Thank you for contacting Syncfusion support.

Currently we are checking on your reported issue and we will share the details for the same on 6th November 2020.

Please let us know if you have any other questions.

Regards,
Hemalatha C


MJ Mohanaselvam Jothi Syncfusion Team November 6, 2020 06:39 PM UTC

Hi Will,

Sorry for the inconvenience.

We are facing some difficulties while validating on this fill color behavior in PDF rendering. Currently we are validation on this with high priority and we will update you more details on 10th November, 2020.

Please let us know if you have any other questions.

Regards,
Mohanaselvam  



HC Hemalatha Chiranjeevulu Syncfusion Team November 10, 2020 05:48 PM UTC

Hi Will,

Thank you for your patience.

On further validating the reported issues, we have found that the text colour will be preserved as white in the generated PDF of the Microsoft Word application when applying the transparent colour for text in the Word document.

In order to achieve the same in DocIO, we suggest you to set the White for TextColor in the Word document. Please refer the below highlighted code snippets to achieve your requirement.
 
 
Issue 
Solution 
In PDF, text will render invisible. 
textBox.TextBoxFormat.FillColor = Color.Red; 
text.CharacterFormat.TextColor = Color.White; 
In PDF, text will render black. 
textBox.TextBoxFormat.FillColor = Color.Transparent; 
text.CharacterFormat.TextColor = Color.White; 

If we misunderstood any of your requirements, then kindly share us the details of your end requirement, which will be helpful for us to provide the exact solution at the earliest.

Please let us know if you have any other questions.

Regards,
Hemalatha C



WC Will Chambers November 17, 2020 09:07 AM UTC

Hi, thank you for your reply. So my question was whether or not it was possible to have "transparent" text with a "transparent" text box. Should I have an image placed behind a text box then white or black text will show over the image. Given your response, it looks like it isn't possible and selecting "transparent" as my text colour in the case that the text box fill colour is "transparent" will always lead to text with some colour (white or black). Is that correct?


HC Hemalatha Chiranjeevulu Syncfusion Team November 18, 2020 08:08 PM UTC

Hi Will,

Thank you for your update.

As mentioned earlier, text color is not preserved as per your end requirement when applying transparent color for text in the transparent textbox. From the given details, we suspect that your requirement is image behind the textbox preserved along with the text. To achieve this requirement, we suggest you to set the image behind the textbox and set fill color of the textbox as empty. Thus, it preserves the image behind the text box along with text.

To meet your requirement, we suggest you to use the below code snippet in your Sample Application

 
//Appends new textbox to the paragraph
            IWTextBox textbox = paragraph.AppendTextBox(150, 75);

           
//Sets fill color for textbox
            textbox.TextBoxFormat.FillColor = Color.Empty;

           
//Sets a value indicates whether the textbox has no line around its shape.
            textbox.TextBoxFormat.NoLine = true;

           
//Adds new text to the textbox body
            IWParagraph textboxParagraph = textbox.TextBoxBody.AddParagraph();
            textboxParagraph.AppendText(
"Text inside text box");
            textboxParagraph = textbox.TextBoxBody.AddParagraph();

           
//Adds new picture to textbox body
            IWPicture picture = textboxParagraph.AppendPicture(Image.FromFile(@"Syncfusion.png"));
            picture.Height = 40;
            picture.Width = 150;

           
//Sets text wrapping style as behind for picture
            picture.TextWrappingStyle = TextWrappingStyle.Behind; 

If we misunderstood any of your requirements, then kindly share us the input document and expected output PDF document, which will be helpful for us to provide the exact solution at the earliest.

Please let us know if you have any other questions.

Regards,
Hemalatha C
 


Marked as answer
Loader.
Up arrow icon