Using Aspose.pdf version 4.0.0.6 from C# 3.0
Hi Giorgio,
Thanks for your inquiry. Please check following code snippet for your requirement. Moreover, you are using a quite older version of Aspose.Pdf for .Net. Please download and try latest version of Aspose.Pdf for .NET 8.2. Hopefully it will serve the purpose.
string newPath = (myDir + “WatermarkExample.pdf”);
FileStream ioStream = new FileStream(newPath, FileMode.Open, FileAccess.ReadWrite);
//open document
Document pdfDocument = new Document(ioStream);
//create text stamp
TextStamp textStamp = new TextStamp(“Sample Stamp”);
//set whether stamp is background
// textStamp.Background = true;
//set origin
textStamp.XIndent = 100;
textStamp.YIndent = 100;
//rotate stamp
//textStamp.Rotate = Rotation.on90;
textStamp.RotateAngle = 45.0F;
//set text properties
textStamp.TextState.Font = FontRepository.FindFont(“Arial”);
textStamp.TextState.FontSize = 14.0F;
textStamp.TextState.FontStyle = FontStyles.Bold;
textStamp.TextState.FontStyle = FontStyles.Italic;
textStamp.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Aqua);
//add stamp to particular page
pdfDocument.Pages[1].AddStamp(textStamp);
//save output document
pdfDocument.Save();
Please feel free to contact us for any further assistance.
Best Regards,
Would this method support multi line texts?
Hi there,
Thanks for your inquiry. You can use FormattedText object to add multiline text stamp. Please check following code snippet for the purpose. Moreover, can you please share the text with special characters that you are using as text stamp? So we look into it and provide you more information.
string newPath = (myDir + “WatermarkExample.pdf”);
FileStream ioStream = new FileStream(newPath, FileMode.Open, FileAccess.ReadWrite);
//open document
Document pdfDocument = new Document(ioStream);
FormattedText formatText = new FormattedText(“Sample stamp”, System.Drawing.Color.FromArgb(180, 0, 0), Aspose.Pdf.Facades.FontStyle.TimesItalic, EncodingType.Winansi, false, 20);
formatText.AddNewLineText("" + DateTime.Now.Date.ToShortDateString());
//create text stamp
TextStamp textStamp = new TextStamp(formatText);
//set whether stamp is background
// textStamp.Background = true;
//set origin
textStamp.XIndent = 100;
textStamp.YIndent = 100;
//rotate stamp
//textStamp.Rotate = Rotation.on90;
textStamp.RotateAngle = 45.0F;
//set text properties
textStamp.TextState.Font = FontRepository.FindFont(“Arial”);
textStamp.TextState.FontSize = 14.0F;
textStamp.TextState.FontStyle = FontStyles.Bold;
textStamp.TextState.FontStyle = FontStyles.Italic;
textStamp.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Aqua);
//add stamp to particular page
pdfDocument.Pages[1].AddStamp(textStamp);
//save output document
pdfDocument.Save();
Please feel free to contact us for any further assistance.
Best Regards,