Hi
I am trying to place a watermark in the margin of a PDF document/or the far most right on the right during the conversation from word to PDF - is this possible and if so can anyone provide an example. My code is below and I have attached a copy of the output file. From the attachment you can see that the watermark could shift to the right an inch or so.
Also I am trying to rotate my watermark using the following code but I cannot get this to work. Watermark.Rotation = -45 does not work.
Any help would be greatly appreciated
Regards
Des
byte[] bytes = System.Text.Encoding.ASCII.GetBytes(report);
MemoryStream stream = new MemoryStream(bytes);
// Create new doc
Document doc = new Document(stream);
// Insert Watermark
InsertWatermarkText(doc, "Copy as of " + DateTime.Now.ToShortDateString());
// Save the doc in a xml fille that can be handled by Aspose.Pdf.
doc.Save("test.xml", SaveFormat.AsposePdf);
// New a pdf object.
Aspose.Pdf.Pdf pdf = new Aspose.Pdf.Pdf();
// Bind content from the named xml file.
pdf.BindXML("test.xml", null);
// Save the result
pdf.Save("c:\\test.pdf");
public void InsertWatermarkText(Document doc, String watermarkText)
{
// Create a watermark shape. This will be a WordArt shape.
// You are free to try other shape types as watermarks.
Shape watermark = new Shape(doc, ShapeType.TextPlainText);
// Set up the text of the watermark.
watermark.TextPath.Text = watermarkText;
watermark.TextPath.FontFamily = "Arial";
watermark.TextPath.Size = 13;
watermark.Width = 150;
watermark.Height = 50;
// Text will be directed from the bottom-left to the top-right corner.
watermark.Rotation = -90;
// watermark.Rotation = 180;
// Remove the following two lines if you need a solid black text.
watermark.Fill.Color = Color.White;//.Silver;//.Gray; // Try LightGray to get more Word-style watermark
watermark.StrokeColor = Color.Silver; // Try LightGray to get more Word-style watermark
// Place the watermark in the page center.
watermark.RelativeHorizontalPosition = RelativeHorizontalPosition.Page;
watermark.RelativeVerticalPosition = RelativeVerticalPosition.Page;
watermark.WrapType = WrapType.None;
watermark.VerticalAlignment = VerticalAlignment.Top;
watermark.HorizontalAlignment = HorizontalAlignment.Right;
// 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);
}
}
public 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));
}
}