Stamp text on PDF document with adjustable left margin

Hi, I am trying to add a text stamp on my PDF document, but I am unable to set the left margin value.

I would like the stamp text to be at the header of the document, that is when I use VerticalAlignment.Top but I want the left margin to be adjustable so that I could set any value and it will align horizontally according to the LeftMargin value set. For the code snippet provided below, I am able to get the text stamped at the top part of the document, but the left alignment will always stick to the most left side even after I set the LeftMargin property. How can it be done as what I explained above. Please advice, thanks.

Document doc = new Document(@“C:\Input.pdf”);
FormattedText text = new FormattedText(“Test Stamp Text”);

//create TextStamp object using FormattedText
TextStamp txtstamp = new TextStamp(text);

//set text properties
txtstamp.TextState.Font = FontRepository.FindFont(“Arial”);
txtstamp.TextState.FontSize = 20;
txtstamp.TextState.FontStyle = FontStyles.Bold;
txtstamp.VerticalAlignment = VerticalAlignment.Top;
txtstamp.LeftMargin = Convert.ToDouble(“230.5”);

//for every page of attachments
for (int i = 1; i <= doc.Pages.Count; i++)
{
doc.Pages[i].AddStamp(txtstamp);
}

// save the udpated document
doc.Save(@“C:\Output.pdf”);

Hi ShiJien,


Thanks for your inquiry. Please use HorizontalAlignment property for using LeftMargin as following. Please check following code snippet, It will help you to accomplish the task.

....

txtstamp.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Left;

txtstamp.LeftMargin = Convert.ToDouble("400");

....

....


Please feel free to contact us for any further assistance.


Best Regards,