Document.Doc2PdfSaveWithWaterMarkOut636608796292274550.pdf (43.4 KB)
When I tried to add multi-line/multiple watermark on top left in header portion, I was unable to do that. It’s repeating one over another. Below is my code and I have attached the output file too.
static void AddWaterMarktoHeader()
{
Document doc = new Document(@“I:\Document\PDFConversion\testFile.docx”);
DocumentBuilder builder = new DocumentBuilder(doc);
Section currentSection = builder.CurrentSection;
PageSetup pageSetup = currentSection.PageSetup;
Shape watermark = new Shape(doc, ShapeType.TextPlainText);
Shape watermark1 = new Shape(doc, ShapeType.TextPlainText);
Shape watermark2 = new Shape(doc, ShapeType.TextPlainText);
Shape watermark3 = new Shape(doc, ShapeType.TextPlainText);
// Set up the text of the watermark.
String waterText = "Approved";
watermark.TextPath.Text = waterText;
watermark.TextPath.FontFamily = "Arial";
watermark.Width = 50;
watermark.Height = 20;
watermark.Fill.Color = System.Drawing.Color.Red; // Try LightGray to get more Word-style watermark
watermark.StrokeColor = System.Drawing.Color.Red; // Try LightGray to get more Word-style watermark
watermark.RelativeHorizontalPosition = RelativeHorizontalPosition.LeftMargin;
watermark.DistanceLeft = 200.0;
watermark.DistanceTop = 200.0;
watermark.RelativeVerticalPosition = RelativeVerticalPosition.TopMargin;
watermark.WrapType = WrapType.None;
watermark.VerticalAlignment = VerticalAlignment.Top;
watermark.HorizontalAlignment = HorizontalAlignment.Left;
watermark1.TextPath.Text = "Approved1";
watermark1.TextPath.FontFamily = "Arial";
watermark1.Width = 50;
watermark1.Height = 20;
watermark1.Fill.Color = System.Drawing.Color.Green; // Try LightGray to get more Word-style watermark
watermark1.StrokeColor = System.Drawing.Color.Green; // Try LightGray to get more Word-style watermark
watermark1.RelativeHorizontalPosition = RelativeHorizontalPosition.LeftMargin;
watermark1.RelativeVerticalPosition = RelativeVerticalPosition.TopMargin;
watermark1.WrapType = WrapType.None;
watermark1.VerticalAlignment = VerticalAlignment.Top;
watermark1.HorizontalAlignment = HorizontalAlignment.Left;
watermark2.TextPath.Text = "Approved2";
watermark2.TextPath.FontFamily = "Arial";
watermark2.Width = 50;
watermark2.Height = 20;
watermark2.Fill.Color = System.Drawing.Color.Green; // Try LightGray to get more Word-style watermark
watermark2.StrokeColor = System.Drawing.Color.Green; // Try LightGray to get more Word-style watermark
watermark2.RelativeHorizontalPosition = RelativeHorizontalPosition.LeftMargin;
watermark2.RelativeVerticalPosition = RelativeVerticalPosition.TopMargin;
watermark2.WrapType = WrapType.None;
watermark2.VerticalAlignment = VerticalAlignment.Top;
watermark2.HorizontalAlignment = HorizontalAlignment.Left;
//watermark3.TextPath.Text = waterText;
//watermark3.TextPath.FontFamily = "Arial";
//watermark3.Width = 50;
//watermark3.Height = 20;
//watermark3.Fill.Color = System.Drawing.Color.Green; // Try LightGray to get more Word-style watermark
//watermark3.StrokeColor = System.Drawing.Color.Green; // Try LightGray to get more Word-style watermark
//watermark3.RelativeHorizontalPosition = RelativeHorizontalPosition.LeftMargin;
//watermark3.RelativeVerticalPosition = RelativeVerticalPosition.TopMargin;
//watermark3.WrapType = WrapType.None;
//watermark3.VerticalAlignment = VerticalAlignment.Top;
//watermark3.HorizontalAlignment = HorizontalAlignment.Left;
// Insert the watermark into all headers of each document section.
Paragraph watermarkPara = new Paragraph(doc);
watermarkPara.AppendChild(watermark);
watermarkPara.AppendChild(watermark1);
watermarkPara.AppendChild(watermark2);
//watermarkPara.AppendChild(watermark3);
foreach (Section sect in doc.Sections)
{
insertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HeaderPrimary);
insertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HeaderFirst);
insertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HeaderFirst);
}
doc.Save(@"I:\Document\PDFConversion\" + "Document.Doc2PdfSaveWithWaterMarkOut" + DateTime.Now.Ticks + ".pdf", SaveFormat.Pdf);
}
Thanks
Satyendra Kumar