Free Support Forum - aspose.com

Water mark test is stretching unnecessarily in pdf file

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 https://docs.aspose.com/display/wordsnet/Add+Watermark 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 https://docs.aspose.com/display/wordsnet/Add+Watermark 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));
    }   
}

@mehtabcompunnel,

Thanks for your inquiry. We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-16816. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

Hi @tahir.manzoor,

Owing to the constricted deadline from our customer, We are eagerly waiting for the coverings of this issue to be resolved as soon as possible. Can you please provide any time frame so that we can cascade same to the customer.

Another important thing that we came across while testing water mark text on mac OS, it is displaying black boxes only which made us completely disappointed.

Attached snapshot for your review from mac.
watermarktextonmac.jpg (251.3 KB)

This is also related bug which i reported:Copyright symbol © not visible issue in watermark

Please Help!!!

@mehtabcompunnel,

Thanks for your inquiry. We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-16823. You will be notified via this forum thread once this issue is resolved. We apologize for your inconvenience.

We try our best to deal with every customer request in a timely fashion, we unfortunately cannot guarantee a delivery date to every customer issue. We work on issues on a first come, first served basis. We feel this is the fairest and most appropriate way to satisfy the needs of the majority of our customers.

Currently, your issue is pending for analysis and is in the queue. Once we complete the analysis of your issue, we will then be able to provide you an estimate.

You reported this issue in free support forum and it will be treated with normal priority. To speed up the progress of issue’s resolution, we suggest you please check our paid support policies from following link.
Paid Support Policies

A post was split to a new topic: Incorrect watermark in generated PDF

@mehtabcompunnel,

Thanks for your patience. It is to inform you that the issue which you are facing is actually not a bug in Aspose.Words. So, we have closed this issue (WORDSNET-16823) as ‘Not a Bug’.

Please note that Word for Mac has some difficulties with VML shapes, so in order to create correct output for Mac Word, please change ShapeType.TextPlainText to ShapeType.TextBox in your code. Please check the following code example.

Document doc = new Document();
double top = 760D;
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);
OoxmlSaveOptions saveOptions = new OoxmlSaveOptions(SaveFormat.Docx);
saveOptions.Compliance = OoxmlCompliance.Iso29500_2008_Strict;
doc.Save(MyDir + "18.5.docx", saveOptions);

public static void ApplyWaterMark(Document doc, string watermarkText, double top)
{
    Run text = new Run(doc, watermarkText);
    text.Font.Size = 7;
    text.Font.Name = "Calibri";
    text.Font.NoProofing = true;

    Paragraph watermarkTextPara = new Paragraph(doc);
    watermarkTextPara.AppendChild(text);

    Shape watermark = new Shape(doc, ShapeType.TextBox);
    watermark.RelativeVerticalPosition = RelativeVerticalPosition.Page;
    watermark.Width = 500;
    watermark.Height = 10;
    watermark.Top = top;
    watermark.TextBox.InternalMarginBottom = 0;
    watermark.TextBox.InternalMarginTop = 0;
    watermark.TextBox.InternalMarginLeft = 0;
    watermark.Stroked = false;
    watermark.WrapType = WrapType.None;
    watermark.AppendChild(watermarkTextPara);

    Paragraph watermarkPara = new Paragraph(doc);
    watermarkPara.AppendChild(watermark);

    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));
}

Thanks @tahir.manzoor, ShapeType.TextBox approach instead of ShapeType.TextPlainText resolved the stretching as well as copyright symbol © not visible issue in watermark issue.
Thanks a ton!!!

@mehtabcompunnel,

Thanks for your feedback. We have closed this issue (WORDSNET-16823) as “Not a Bug”.

@mehtabcompunnel,

By using ShapeType.TextBox in the code also resolves WORDSNET-16816 (Watermark text is stretched in output PDF). Please confirm. We will then close this issue.

@tahir.manzoor, Yes, It has been resolved. I am highly obliged for your cooperation. :+1:t3:

@mehtabcompunnel,

Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.