PDF Watermark Rotation issue

We are trying to move from spire pdf manipulation library to your Aspose library and we do have a redundant data according to which we have to do some operation on the pdf and should get the same end result as when we were using the spire library

Problem we are facing : we are trying to rotate a water mark with the give angle but we are not able to get the same result as spire
Code :
Spire:

static async Task Main(string[] args)
        {
            var Document = new PdfDocument(@"D:\repos\Tools\watermark\spire\spire\spire\graph.pdf");
            string Text = ".__________________________";
            int Angle = 20;
            string FontColor = "#880c0c";
            float FontSize = 25;
            float Opacity = 0.4f;
            float CoordinateX = 10;
            float CoordinateY = 10;
            PdfFont fontFamily = new PdfFont(PdfFontFamily.TimesRoman, FontSize, PdfFontStyle.Bold);
            Color watermarkFontColor = ColorTranslator.FromHtml(FontColor);
            
            int index = 0;
            PdfPageBase page= Document.Pages[0];
                
                    PdfTilingBrush brush = await Task.Run(() =>
                    {
                        PdfTilingBrush brush = new PdfTilingBrush(
                           new SizeF(page.Size.Width, page.Size.Height));
                        brush.Graphics.SetTransparency(Opacity);
                        brush.Graphics.Save();
                           brush.Graphics.TranslateTransform(
                                CoordinateX,
                                CoordinateY);
                        brush.Graphics.RotateTransform(Angle);
                        brush.Graphics.DrawString(
                            Text,
                            fontFamily,
                            new PdfSolidBrush(
                                Color.FromArgb(
                                    watermarkFontColor.A,
                                    watermarkFontColor.R,
                                    watermarkFontColor.G,
                                    watermarkFontColor.B)),
                            0,
                            0);
                        return brush;
                    })
            .ConfigureAwait(false);
                    page.Canvas.DrawRectangle(
                        brush,
                        new RectangleF(
                            new PointF(0, 0),
                            page.Canvas.ClientSize));

            Document.SaveToFile(@"D:\repos\Tools\watermark\spire\spire\spire\" + new Random().Next(10, 1000) + ".pdf");
            System.Console.WriteLine("done");
}

Aspose implementation:
static void Main(string[] args)
{

            var Document = new Document(@"D:\repos\Tools\watermark\PdfWatermark\PdfWatermark\graph.pdf");
            PdfFileInfo info = new PdfFileInfo(Document);
            string Text = ".__________________________";
            int Angle = 20;
            string FontColor = "#880c0c";
            float FontSize = 25;
            float Opacity = 0.4f;
            float CoordinateX = 10;
            float CoordinateY = 10;
            System.Drawing.Color watermarkFontColor = ColorTranslator.FromHtml(FontColor);
            Aspose.Pdf.Text.Font font = Aspose.Pdf.Text.FontRepository.FindFont("TimesRoman");
            int index = 1;
            
            TextStamp textStamp = new TextStamp(Text);
            textStamp.TextState.Font = font;
            textStamp.TextState.FontSize = FontSize;
            textStamp.TextState.ForegroundColor = Aspose.Pdf.Color.Parse((FontColor.ToString()));
            textStamp.Opacity = Opacity;
            float tempCordX = (float)CoordinateX;
            float tempCordY = (float)CoordinateY;
            textStamp.XIndent = tempCordX;
            textStamp.YIndent = tempCordY;
            textStamp.RotateAngle = Angle;
            textStamp.TextState.FontStyle = Aspose.Pdf.Text.FontStyles.Bold;
            Document.Pages[index].AddStamp(textStamp);
            Document.Save(@"D:\repos\Tools\watermark\PdfWatermark\PdfWatermark\" + new Random().Next(10, 1000) + ".pdf");
            System.Console.WriteLine("done");

        }        

Spire Output at 20 degree angle same coordinate
image.jpg (227.4 KB)

Aspose at 20 degree angle same coordinate

image.jpg (137.3 KB)

Here is the sample project link for download: [Watermark rotation issue sample project](https://cpaperless-my.sharepoint.com/:f:/g/personal/bhuvan_safesend_com/EmpcdAQnjL9HtWNGYugXdC8BfIGWBX-MWaHhvLrO5CPRLA?e=01nVdA)

Any help much appreciated.

@cpaperless

Please note that Aspose.PDF implements a coordinating system where (0,0) means lower-left unlike common understandings where it means top-left. Therefore, the watermark is being rendered at the bottom of the page. Therefore, please try to adjust the XIndent and YIndent properties according to the appropriate values to show watermark at the top e.g. {page height} - 10 and feel free to let us know if you are still unable to achieve the correct output.

Hi Asad,
Thank you for your quick response.
We have tried as you suggested. We have subtracted the page height with the y index, but we have a small differentiation in the coordinate and the rotation seems to way off form the spire out put .

We have attached the new code and the out put below

Aspose implementation:

static void Main(string[] args) 
        { 
            var Document = new Document(@"D:\repos\Tools\watermark\PdfWatermark\PdfWatermark\graph.pdf"); 

            PdfFileInfo info = new PdfFileInfo(Document); 

            string Text = ".__________________________"; 

            int Angle = 20; 

            string FontColor = "#880c0c"; 

            float FontSize = 25; 

            float Opacity = 0.4f; 

            float CoordinateX = 10; 

            float CoordinateY = 10; 

            System.Drawing.Color watermarkFontColor = ColorTranslator.FromHtml(FontColor); 

            Aspose.Pdf.Text.Font font = Aspose.Pdf.Text.FontRepository.FindFont("TimesRoman"); 

            int index = 1; 

            TextStamp textStamp = new TextStamp(Text); 

            textStamp.TextState.Font = font; 

            textStamp.TextState.FontSize = FontSize; 

            textStamp.TextState.ForegroundColor = Aspose.Pdf.Color.Parse((FontColor.ToString())); 

            textStamp.Opacity = Opacity; 

            float tempCordX = (float)CoordinateX; 

            float tempCordY = (float)CoordinateY; 

            textStamp.XIndent = tempCordX; 

textStamp.YIndent = info.GetPageHeight(index)-tempCordY;                           textStamp.RotateAngle = Angle; 

            textStamp.TextState.FontStyle = Aspose.Pdf.Text.FontStyles.Bold; 

            Document.Pages[index].AddStamp(textStamp); 

            Document.Save(@"D:\repos\Tools\watermark\PdfWatermark\PdfWatermark\" + new Random().Next(10, 1000) + ".pdf"); 

            System.Console.WriteLine("done"); 

 

        }        } 

Out put of Aspose with 20 degree and same coordinate :
image.jpg (196.6 KB)

As you can see in the above image after rotation the text is visible partially on the top left corner.

@cpaperless

We are checking it and will get back to you shortly.

@cpaperless

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFNET-54794

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.