Search code examples
c#word-interop

Symbol in added Watermark isn't correctly shown in C# Word Interop


My program has a function to add a watermark to word files, but a symbol 'Ⓒ' is not shown correctly, just a square like the attached file.(it's rotated).

enter image description here

I guess I have to write a line of code to use these symbols, but I cannot find it. Can anybody help me?

if (file.Watermark == true)
                    {
                        Microsoft.Office.Interop.Word.Shape wordShape = null;
                        foreach (Microsoft.Office.Interop.Word.Section section in wordDoc.Sections)
                        {
                            wordShape = section.Headers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Shapes.AddTextEffect(
                                             Microsoft.Office.Core.MsoPresetTextEffect.msoTextEffect1,
                                             "Ⓒ gg", "Arial", (float)30,
                                             Microsoft.Office.Core.MsoTriState.msoTrue,
                                             Microsoft.Office.Core.MsoTriState.msoFalse,
                                             150, 150, ref o);
                            wordShape.Fill.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
                            wordShape.Fill.Solid();
                            wordShape.Fill.ForeColor.RGB = (Int32)Microsoft.Office.Interop.Word.WdColor.wdColorGray15;
                            wordShape.Line.Visible = Microsoft.Office.Core.MsoTriState.msoFalse;
                            wordShape.RelativeHorizontalPosition = Microsoft.Office.Interop.Word.WdRelativeHorizontalPosition.wdRelativeHorizontalPositionMargin;
                            wordShape.RelativeVerticalPosition = Microsoft.Office.Interop.Word.WdRelativeVerticalPosition.wdRelativeVerticalPositionMargin;
                            wordShape.Left = 20;
                            wordShape.Top = 250;
                            wordShape.Rotation = -45;
                        }
                    }

Solution

  • Do something like this :

    if (file.Watermark == true)
                    {
                        Microsoft.Office.Interop.Word.Shape wordShape = null;
                        foreach (Microsoft.Office.Interop.Word.Section section in wordDoc.Sections)
                        {
                            wordShape = section.Headers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Shapes.AddTextEffect(
                                             Microsoft.Office.Core.MsoPresetTextEffect.msoTextEffect1,
                                             "\u00a9 gg", "Arial", (float)30,
                                             Microsoft.Office.Core.MsoTriState.msoTrue,
                                             Microsoft.Office.Core.MsoTriState.msoFalse,
                                             150, 150, ref o);
                            wordShape.Fill.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
                            wordShape.Fill.Solid();
                            wordShape.Fill.ForeColor.RGB = (Int32)Microsoft.Office.Interop.Word.WdColor.wdColorGray15;
                            wordShape.Line.Visible = Microsoft.Office.Core.MsoTriState.msoFalse;
                            wordShape.RelativeHorizontalPosition = Microsoft.Office.Interop.Word.WdRelativeHorizontalPosition.wdRelativeHorizontalPositionMargin;
                            wordShape.RelativeVerticalPosition = Microsoft.Office.Interop.Word.WdRelativeVerticalPosition.wdRelativeVerticalPositionMargin;
                            wordShape.Left = 20;
                            wordShape.Top = 250;
                            wordShape.Rotation = -45;
                        }
                    }
    

    you can replace your symbol by this expression : \u00a9

    i thing i will help you

    for more informations have a look at this :

    How to use caracter encoding

    A similar question has been aked