We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How to align the Pdf Rubber stamp to the page as well as set its margins?

I'm trying to add graphic stamps to my pdf file and I want to position them in a certain way. Reading the documentation for this class, there was any mention of an alignment or margin property, however, there is property called page that gives me direct access to the current settings that the page has though I'm not certain I should be  modifying that when all I want to do is modify the margin and alignment property of my stamp.

Ideally I would like to do this(Pseudocode).

          var imageStamp = new PdfRubberStampAnnotation();
          imageStamp.TopMargin = 10;
          imageStamp.HorizontalAlignment = HorizontalAlignment.Center;
          imageStamp.VerticalAlignment = VerticalAlignment.Top;

How would I roughly be able to achieve this?



1 Reply

PV Prakash Viswanathan Syncfusion Team February 19, 2019 11:23 AM UTC

Hi Luis, 
 
Thanks for contacting Syncfusion support.  
 
The PdfRubberStampAnnotation does not have properties to set the horizontal and vertical alignment. However, we can achieve your requirement by calculating the X and Y position of the annotation based on page size and size of the annotation. Kindly refer below code snippet to add the annotation with particular postion.  
 
//Creates a new PDF document. 
PdfDocument document = new PdfDocument(); 
 
//Creates a new page 
PdfPage page = document.Pages.Add(); 
 
//Getting page size 
SizeF pageSize = page.GetClientSize(); 
 
//Setting annotation size 
SizeF annotSize = new SizeF(100, 20); 
 
//Setting the X position to align in center of page 
float xPos = (pageSize.Width / 2) - (annotSize.Width / 2); 
 
//Set margin as Y value 
float yPos = 10; 
RectangleF bounds = new RectangleF(new PointF(xPos, yPos), annotSize); 
 
//Creates a new pdf rubber stamp annotation. 
PdfRubberStampAnnotation rubberStampAnnotation = new PdfRubberStampAnnotation(bounds, " Text Rubber Stamp Annotation"); 
rubberStampAnnotation.Icon = PdfRubberStampAnnotationIcon.Experimental; 
rubberStampAnnotation.Text = "Text Properties Rubber Stamp Annotation"; 
 
//Adds annotation to the page 
page.Annotations.Add(rubberStampAnnotation); 
 
//Saves the document to disk. 
document.Save(DataPathOutput + "RubberStamp.pdf"); 
 
document.Close(true); 
 
A simple sample for achieving the same can be found in the below link: 
 
Please let us know if you need any further assistance on this.  
 
Regards, 
Prakash V 


Loader.
Live Chat Icon For mobile
Up arrow icon