Hi Aspose,
I am confronting a weird issue after generating a pdf document with the help of Aspose.Words API. My requirement is, I need to insert three lines watermark text in footer for which i have created three water marks with text, fixed there positions from top of the document and inserted them into footer. By following this approach .docx document is generating without any issue but when i try to produce .pdf document, third line which has less text compared to other two lines stretches to fill the complete width of the other water mark texts which is an issue. Please help
I am attaching complete code which i have followed from Add Watermark in C#|Aspose.Words for .NET article.
Produced Sample.docx snapshot document which seems perfect
Sample.zip (11.5 KB)
image.png (46.5 KB)
Produced Sample.pdf snapshot document (notice third line)
Sample.pdf (296.5 KB)
image.png (114.5 KB)
Below is the complete code based on Add Watermark in C#|Aspose.Words for .NET article.
class Program
{
static void Main(string[] args)
{
var path = @“D:\Sample.docx”;
var pathToGenerateDoc = @“D:\Watermark\Sample.docx”;
var pathToGeneratepdf = @“D:\Watermark\Sample.pdf”;
Document doc = new Document(path);
double top = 765D;
string copyRightText = "Copyright © 2018 by the Aspose.Words company of Word and pdfs. Warning: This particular document is protected by U.S. with Copyright Law and International Treaties.";
string secondline = "It was created by \"Firm-MAli\" for \"Header Regression Test\". I must test Aspose.word feasiblity of generating documents before purchasing any license Please Do.";
string thirdline = "project.";
ApplyWaterMark(doc, copyRightText, top); top = top + 8D;
ApplyWaterMark(doc, secondline, top); top = top + 8D;
ApplyWaterMark(doc, thirdline, top);
doc.Save(pathToGenerateDoc);
doc.Save(pathToGeneratepdf);
}
public static void ApplyWaterMark(Document doc, string watermarkText, double top)
{
// Create a watermark shape. This will be a WordArt shape.
Shape watermark = new Shape(doc, ShapeType.TextPlainText);
// Set up the text of the watermark.
watermark.TextPath.Text = watermarkText;
watermark.TextPath.FontFamily = "Calibri";
watermark.TextPath.Size = 7D;
watermark.Width = 467.75D;
watermark.Height = 8.65D;
watermark.TextPath.FitShape = false;
watermark.Fill.Color = Color.Black; // Try LightGray to get more Word-style watermark
watermark.TextPath.TextPathAlignment = TextPathAlignment.Left;
watermark.Top = top;
watermark.Stroked = false;
watermark.RelativeVerticalPosition = RelativeVerticalPosition.Page;
watermark.WrapType = WrapType.None;
// Create a new paragraph and append the watermark to this paragraph.
Paragraph watermarkPara = new Paragraph(doc);
watermarkPara.ParagraphBreakFont.Size = 0;
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.FooterPrimary);
insertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.FooterFirst);
insertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.FooterEven);
}
}
public static void insertWatermarkIntoHeader(Paragraph watermarkPara, Section sect, HeaderFooterType headerType)
{
HeaderFooter header = sect.HeadersFooters[headerType];
if (header == null)
{
header = new HeaderFooter(sect.Document, headerType);
sect.HeadersFooters.Add(header);
}
header.AppendChild(watermarkPara.Clone(true));
}
}