Adding a Custom Stamp to a PDF Using Xamarin PDF Viewer
Tags: android, ios, dotnet, csharp
Published: 2019-12-19 05:17:31

---
title: Adding a Custom Stamp to a PDF Using Xamarin PDF Viewer
published: true
date: 2019-12-12 12:00:51 UTC
tags: android, ios, dotnet, csharp
canonical_url: https://www.syncfusion.com/blogs/post/adding-a-custom-stamp-to-a-pdf-using-xamarin-pdf-viewer.aspx
cover_image: https://www.syncfusion.com/blogs/wp-content/uploads/2019/12/Adding-a-Custom-Stamp-to-a-PDF-Using-Xamarin-PDF-Viewer-1.png
---

## What is a custom stamp?

A custom stamp is a user-defined virtual rubber stamp that allows users to add their own customized, personal signatures or seals to a PDF document. For example, this can be used for marking up an invoice in the received, approved, or expired stages of a process. It also can be used to add an approval (or other) stage with name, date, and time information.

## Overview

The custom stamp annotation feature in [PDF Viewer](https://www.syncfusion.com/xamarin-ui-controls/xamarin-pdf-viewer) allows users to include any form of Xamarin.Forms widget, such as Button, Entry, Label, or Image, anywhere in a PDF document. You can perform operations such as add, move, resize, and delete on custom stamp annotations. Also, you can save and load the existing custom stamp annotations associated with a PDF document in the PDF Viewer control.

In this blog, we are going to see two typical examples of custom stamps used in the real world:

- An image as a custom stamp
- A custom dynamic stamp

## Adding an image as a custom stamp

PDF Viewer provides an option to add any user-defined or customized image as a custom stamp to the PDF document. The **AddStamp** method in PDF Viewer is used to achieve this. The following code example demonstrates how to add an image as a custom stamp.

```csharp
//Initialize PdfViewer
PdfViewer pdfViewer = new PdfViewer();
  
//Load document
pdfViewer.LoadDocument(typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("PDFViewerSample.Assets.Invoice.pdf"));
  
//Set image source 
Image customImage = new Image();
customImage.Source = "Expired.png";
  
//Add image as custom stamp
pdfViewer.AddStamp(customImage, 1, new Point(250, 400));
```

This code example will add the image as a custom stamp in the location 250X400 in the first page of the PDF document.

## Adding a custom dynamic stamp

Dynamic stamps obtain information from your computer and allow you to indicate name, date, and time information on the stamp. Please find the following a reference image for a dynamic stamp.

![Adding a custom dynamic stamp.](https://www.syncfusion.com/blogs/wp-content/uploads/2019/11/Add-a-custom-dynamic-stamp.png)

PDF Viewer lets you add a custom dynamic stamp to a PDF document. The **AddStamp** method in PDF Viewer is used to add this stamp. The following code example demonstrates how to create and add a custom dynamic stamp to a PDF page.

```xml
<Grid> 
  <Image  x:Name="approved" Source="Approved.png" Aspect="Fill" />
  <Label  x:Name="dateAndTime" VerticalOptions="End" />
</Grid>
```
```csharp
//Add the Date and Time value to the custom stamp/image
Device.StartTimer(TimeSpan.FromSeconds(1), () =>
{
    Device.BeginInvokeOnMainThread(() => dateAndTime.Text = DateTime.Now.ToString());
        return true;
    });
});
```
```csharp
//Convert the Grid with dynamic date/time text as image
DependencyService.Get<CustomImage>().ConvertToImage(tappedstamp as Grid);
Stream stream= DependencyService.Get<CustomImage>().GetStream();
stream.Position = 0;
  
//Set image source
Image customImage = new Image();
customImage.Source = ImageSource.FromStream(() => stream);
customImage.HeightRequest = 90;
customImage.WidthRequest = 300;                   
  
//Add image as custom stamp
pdfViewer.AddStamp(customImage, pdfViewer.PageNumber, new Point(250, 400));
```

## Sample project

You can find a sample project that explains the previous scenarios on [GitHub](https://github.com/SyncfusionExamples/Adding-custom-stamps-using-xamarin-pdf-viewer). The following screenshot illustrates the execution of a sample project.

![Sample project.](https://www.syncfusion.com/blogs/wp-content/uploads/2019/11/Sample-project.png)

In this sample, we have two custom stamp sections: **Standard** and **Dynamic**. The Standard section contains the image of the stamps, whereas the Dynamic section contains the image of the stamp along with the text field displaying the current date and time.

![Standard stamps and Dynamic stamps.](https://www.syncfusion.com/blogs/wp-content/uploads/2019/11/Standard-stamps-and-Dynamic-stamps.png)

To learn more about adding custom stamps and using their features, refer to our documentation page, [Working with Custom Stamp annotations](https://help.syncfusion.com/xamarin/pdf-viewer/working-with-custom-stamp-annotations).

## Conclusion

We hope you now have a better understanding of adding custom stamps to a PDF using the Xamarin PDF Viewer control. By using these custom stamp APIs and events, you can add your own style of custom stamps to your application.

If you are already a Syncfusion user, please download the latest version of Essential Studio from the [License & Downloads](https://www.syncfusion.com/account/downloads) page and try these new features. Our NuGet packages are available on [NuGet.org](https://www.nuget.org/). If you aren’t a customer yet, you can try our 30-day [free trial](https://www.syncfusion.com/downloads) to check out these features. Also, try our other samples from this [GitHub location](https://github.com/syncfusion/xamarin-demos/tree/master/Forms/PdfViewer).

If you wish to send us feedback or submit any questions, please feel free to post them in the comments section below, or contact us through our [support forum](https://www.syncfusion.com/forums), [Direct-Trac](https://www.syncfusion.com/support/directtrac/), or [feedback portal](https://www.syncfusion.com/feedback/). We are happy to assist you!

_If you liked this post, we hope you will also enjoy the following:_

- [Ebook] [_PDF Succinctly_](https://www.syncfusion.com/ebooks/pdf)
- [Ebook] [_Forms Succinctly_](https://www.syncfusion.com/ebooks/xamarin-forms-succinctly)
- [Ebook] [_Visual Studio for Mac Succinctly_](https://www.syncfusion.com/ebooks/visual-studio-for-mac-succinctly)
- [Ebook] [_Forms for macOS Succinctly_](https://www.syncfusion.com/ebooks/xamarin_forms_for_mac_os_succinctly)

The post [Adding a Custom Stamp to a PDF Using Xamarin PDF Viewer](https://www.syncfusion.com/blogs/post/adding-a-custom-stamp-to-a-pdf-using-xamarin-pdf-viewer.aspx) appeared first on [Syncfusion Blogs](https://www.syncfusion.com/blogs).