Add text in the center of PDF document using Aspose.PDF for .NET

Hi,


I have a small project where I just need to add multiple pieces of centered text to an existing PDF. It’s a certificate that is generated automatically, and I need to add the user’s name, the course name and the date. This is pretty much all I’m very going to do with ASPOSE.PDF, so I don’t have the time to learn the whole API. Is there just a sample somewhere that will help me do this? I’ve looked and looked and can’t find anything.

Any help is greatly appreciated.

Thank you.

Hi,


Thanks for your interest in Aspose. You can add text as Text Stamp in existing PDF and set different properties of stamp object. To add a centered text, you need to set all alignment properties values to center. Please find a sample code for the purpose and check documentation link for the details.

//open document

Document pdfDocument1 = new Document(myDir + "Test.pdf");

var textStamp = new Aspose.Pdf.TextStamp("Aspose.Pdf for .NET stamping test")

{

Background = false,

Opacity = 0.5,

//RotateAngle = 50,

HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center,

VerticalAlignment = Aspose.Pdf.VerticalAlignment.Center,

TextAlignment = Aspose.Pdf.HorizontalAlignment.Center

};

textStamp.TextState.Font = FontRepository.FindFont("Arial");

textStamp.TextState.FontSize = 16.0f;

textStamp.TextState.FontStyle = FontStyles.Bold;

textStamp.TextState.FontStyle = FontStyles.Italic;

textStamp.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.FromArgb(121, 177, 0));

for( int pageno=1;pageno<=pdfDocument1.Pages.Count;pageno++)

pdfDocument1.Pages[pageno].AddStamp(textStamp);

pdfDocument1.Save(myDir + "testout_stamp.pdf");

Please feel free to contact us for any further assistance.


Best Regards,