Hi
Thanks for your request. The file with .doc extension is actually a PDF document. I suppose this is the reason why you get incorrect format exception.
I think, in your case, you should use a text box as a watermark instead of WordArt shape. I created a simple code example for you:
[Test]
public void Test001()
{
Document doc = new Document("C:\\Temp\\in.doc");
InsertWatermarkText(doc, "For Your Information Only.\nNot to be Shown to Other customers.\nNot to be Distributed or Used in Sales/Promotional Detailing.");
doc.Save("C:\\Temp\\out.doc");
doc.Save("C:\\Temp\\out.pdf");
}
///
/// Inserts a watermark into a document.
///
/// The input document.
/// Text of the watermark.
private static void InsertWatermarkText(Document doc, string watermarkText)
{
// Create a watermark shape. This will be a TextBox shape.
// You are free to try other shape types as watermarks.
Shape watermark = new Shape(doc, ShapeType.TextBox);
Paragraph par = new Paragraph(doc);
watermark.AppendChild(par);
// We will use DocumentBuilkder to insert the text.
DocumentBuilder builder = new DocumentBuilder(doc);
// Move builder into watermark.
builder.MoveTo(par);
// Setup text properties.
builder.Font.Size = 12;
builder.Font.Color = Color.Red;
builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
builder.ParagraphFormat.SpaceAfterAuto = false;
builder.ParagraphFormat.SpaceBeforeAuto = false;
builder.ParagraphFormat.SpaceAfter = 0;
builder.ParagraphFormat.SpaceBefore = 0;
// Insert text.
builder.Write(watermarkText);
// Set up the text box.
watermark.Width = 500;
watermark.Height = 60;
watermark.Stroked = false;
// Place the watermark in the page center.
watermark.RelativeHorizontalPosition = RelativeHorizontalPosition.Page;
watermark.RelativeVerticalPosition = RelativeVerticalPosition.Page;
watermark.WrapType = WrapType.None;
watermark.VerticalAlignment = VerticalAlignment.Bottom;
watermark.HorizontalAlignment = HorizontalAlignment.Center;
// Create a new paragraph and append the watermark to this paragraph.
Paragraph watermarkPara = new Paragraph(doc);
watermarkPara.AppendChild(watermark);
// Insert the watermark into all headers of each document section.
foreach(Section sect in doc.Sections)
{
// There could be up to three different headers in each section, since we want
// the watermark to appear on all pages, insert into all headers.
InsertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HeaderPrimary);
InsertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HeaderFirst);
InsertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HeaderEven);
}
}
private static void InsertWatermarkIntoHeader(Paragraph watermarkPara, Section sect, HeaderFooterType headerType)
{
HeaderFooter header = sect.HeadersFooters[headerType];
if (header == null)
{
// There is no header of the specified type in the current section, create it.
header = new HeaderFooter(sect.Document, headerType);
sect.HeadersFooters.Add(header);
}
// Insert a clone of the watermark into the header.
header.AppendChild(watermarkPara.Clone(true));
}
Hope this helps.
Best regards,