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.

Sun Jul 04, 2021 6:25 am

Hi ,

I have added a watermark in my document but It got cut in some places of the text. I have added the image for reference.

shivaa1234
 
Posts: 5
Joined: Mon Aug 26, 2019 6:41 am

Mon Jul 05, 2021 9:06 am

Hello,

Thanks for your inquiry.
According to the picture you provided, I speculate that some cells of your table have the white color background, which will cover the watermark. You can remove the background color from table cell in Microsoft Word, then add watermark. On the other hand, you could do the same thing using our Spire.Doc, sample code is give as below. If the problem still exists, please provide your Word file for further investigation. You could attach it here or send to us via email ([email protected]). Thanks in advance.
Code: Select all
            //Get the table from Word document.
            Table table = doc.Sections[0].Tables[0] as Table;

            //Loop through table cell
           foreach (TableRow row in table.Rows)
            {
                foreach (TableCell cell in row.Cells)
                {
                   Color color = cell.CellFormat.BackColor;
                    if (color != null)
                    {
                        //Remove background
                        cell.CellFormat.ClearBackground();
                    }
                }
            }

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Fri Jul 16, 2021 6:23 am

Hello,

Hope you're doing well!
How is your issue going? Has it been resolved? Can you give us some feedback at your convenience? Thank you in advance.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Thu Jul 22, 2021 8:50 am

Still it exists, clear backgroud is not available .Can you tell which version of the spire it fixed

shivaa1234
 
Posts: 5
Joined: Mon Aug 26, 2019 6:41 am

Thu Jul 22, 2021 10:10 am

Hi,

Thank you for your feedback.
I tested the code with the latest version of Spire.Doc (Spire.Doc Pack(hot fix) Version:9.7.3), and the method ClearBackground is effective. Please download and test again. If the problem still exists, please provide your sample Word file for further investigation. You could attach it here or send to us via email ([email protected]). Thanks in advance.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Thu Jul 22, 2021 11:15 am

Hi,

After updating the latest spire version also issue exists. I have attached the word file.

Regards,
Shivaa

shivaa1234
 
Posts: 5
Joined: Mon Aug 26, 2019 6:41 am

Fri Jul 23, 2021 9:39 am

Hi,

Thank you for your feedback.
Sorry I did not find your Word file in this post or email. Please resend it to us? Thanks in advance.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Mon Jul 26, 2021 5:06 am

Hi,

Sent mail again, please check and let me know

Regards.
Shivaa

shivaa1234
 
Posts: 5
Joined: Mon Aug 26, 2019 6:41 am

Mon Jul 26, 2021 7:04 am

Hi,

Thank you for sharing file via email.
I tested your Word file and found that the watermark is indeed obscured. After investigation, I found that the table contains nested table, which also has white background color, that’s the reason why the watermark is covered. Please refer to the following code to clear the cell background color of the nested table. Any question, please feel free to write back.
Code: Select all
        static void Main(string[] args)
        {
            Document doc = new Document();
            doc.LoadFromFile("Sample.docx");
            foreach (Section section in doc.Sections)
            {
                //Get the table from Word document.                     
                foreach (Table table in section.Tables)
                {
                    //Iterate through all the rows
                    foreach (TableRow row in table.Rows)
                    {
                        //Iterate over the cells in each row
                        foreach (TableCell cell in row.Cells)
                        {
                            //Whether there are nested tables
                            foreach (DocumentObject collection in cell.ChildObjects)
                            {
                                //A nested tables
                                if (collection is Table)
                                {
                                    Table tables = (Table)collection;
                                    foreach (TableRow rows in tables.Rows)
                                    {
                                        foreach (TableCell cells in rows.Cells)
                                        {
                                            ClearBackgroundColor(cells);
                                        }
                                    }
                                }

                                ClearBackgroundColor(cell);
                            }
                        }
                    }
                }

                InsertTextWatermark(section);
            }                           
            string filePath = "output.docx";
            doc.SaveToFile(filePath,FileFormat.Docx2013);

        }
        private static void InsertTextWatermark(Section section)
        {
            TextWatermark txtWatermark = new TextWatermark();
            txtWatermark.Text = "E-iceblue";
            txtWatermark.FontSize = 95;
            txtWatermark.Color = Color.Blue;
            txtWatermark.Layout = WatermarkLayout.Diagonal;
            txtWatermark.Semitransparent = true;
            section.Document.Watermark = txtWatermark;

        }
        private static void ClearBackgroundColor(TableCell cell)
        {
            //Gets the cell background color
            Color colors = cell.CellFormat.BackColor;
            if (colors != null)
            {
                //Clear background color
                cell.CellFormat.ClearBackground();
            }
        }

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Fri Jul 30, 2021 9:35 am

Hello,

Hope you're doing well.
How is your issue going? Can you give us some feedback at your convenience? Thanks in advance.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.Doc

cron