Having trouble getting help?
Contact Support
Contact Support
Working with custom stamp annotations in UWP PDF Viewer (SfPdfViewer)
8 Jan 20252 minutes to read
The PDF Viewer allows you to include any form of UIElement (Button, Entry, Label, Image, and more) anywhere in the pages of the PDF Viewer as a custom stamp annotation. You can add, move, resize, and delete the custom stamp annotations. Also, you can save and load the existing custom stamp annotation associated with a PDF document.
NOTE
Stamp annotations can be saved only by using the SaveAsync method.
Add a custom stamp
The custom stamps can be added using the AddStamp
method.
Method | Action |
---|---|
AddStamp(view, pageNumber) | Add custom stamp to the specified page. |
AddStamp(view, pageNumber, position) | Add custom stamp to the specified page and position as Point object. |
AddStamp(view, pageNumber, bounds) | Add custom stamp to the specified page and position as Rectangle object. |
A typical example of a custom stamp in the real world includes adding an image as a custom stamp. The PDF Viewer provides an option to add any user-defined signature or seal image as a custom stamp to a PDF document. The following code sample explains the same.
private async void Button_Clicked(object sender, RoutedEventArgs e)
{
//Set the image source.
Image image = new Image();
Stream imageStream = typeof(MainPage).GetTypeInfo().Assembly.GetManifestResourceStream("PdfViewerCustomToolbar.Assets.Image.png");
StackPanel grid = new StackPanel();
grid.Height = 100;
grid.Width = 100;
BitmapImage bitmap = new BitmapImage();
bitmap.DecodePixelHeight = 500;
bitmap.DecodePixelWidth = 500;
await bitmap.SetSourceAsync(imageStream.AsRandomAccessStream());
image.Source = bitmap;
if (image.Source != null)
grid.Children.Add(image);
//Add the image as a custom stamp to the first page using the AddStamp method.
pdfViewer.AddStamp(grid, 1, new Point(100,100));
}