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.