Adding a Custom Stamp to a PDF Using Xamarin PDF Viewer | Syncfusion Blogs
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (174).NET Core  (29).NET MAUI  (207)Angular  (109)ASP.NET  (51)ASP.NET Core  (82)ASP.NET MVC  (89)Azure  (41)Black Friday Deal  (1)Blazor  (219)BoldSign  (14)DocIO  (24)Essential JS 2  (107)Essential Studio  (200)File Formats  (66)Flutter  (133)JavaScript  (221)Microsoft  (119)PDF  (81)Python  (1)React  (100)Streamlit  (1)Succinctly series  (131)Syncfusion  (917)TypeScript  (33)Uno Platform  (3)UWP  (4)Vue  (45)Webinar  (51)Windows Forms  (61)WinUI  (68)WPF  (159)Xamarin  (161)XlsIO  (36)Other CategoriesBarcode  (5)BI  (29)Bold BI  (8)Bold Reports  (2)Build conference  (8)Business intelligence  (55)Button  (4)C#  (149)Chart  (131)Cloud  (15)Company  (443)Dashboard  (8)Data Science  (3)Data Validation  (8)DataGrid  (63)Development  (631)Doc  (8)DockingManager  (1)eBook  (99)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (40)Extensions  (22)File Manager  (7)Gantt  (18)Gauge  (12)Git  (5)Grid  (31)HTML  (13)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (507)Mobile MVC  (9)OLAP server  (1)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (43)Performance  (12)PHP  (2)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (12)Road Map  (12)Scheduler  (52)Security  (3)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (31)Solution Services  (4)Spreadsheet  (11)SQL  (11)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (12)Tips and Tricks  (112)UI  (387)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (31)Visual Studio Code  (19)Web  (595)What's new  (332)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
Adding a Custom Stamp to a PDF Using Xamarin PDF Viewer

Adding a Custom Stamp to a PDF Using Xamarin PDF Viewer

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 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:

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.

//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.

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.

<Grid> 
  <Image  x:Name="approved" Source="Approved.png" Aspect="Fill" />
  <Label  x:Name="dateAndTime" VerticalOptions="End" />
</Grid>
//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;
    });
});
//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. The following screenshot illustrates the execution of a sample project.

Sample project.

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.

To learn more about adding custom stamps and using their features, refer to our documentation page, 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 page and try these new features. Our NuGet packages are available on NuGet.org. If you aren’t a customer yet, you can try our 30-day free trial to check out these features. Also, try our other samples from this GitHub location.

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 forumDirect-Trac, or feedback portal. We are happy to assist you!

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

Tags:

Share this post:

Comments (2)

Hello,
When I try your sample and add a custom stamp, on the saved PDF, I have no custom stamp printed.

Do you have an idea why ?

Hi Xavier,

Sorry for the inconvenience. Upon checking, we found issue with the sample uploaded and now it has been resolved. We need to use the “SaveDocumentAsync()” method instead to save the stamps. Kindly check the updated sample from the same GitHub location.

For any further queries, please create a new incident (under your account) from our support website to provide solution quickly and find the support website link from below.

https://www.syncfusion.com/support/directtrac/incidents/newincident

Regards,
Ramkumar

Comments are closed.

Popular Now

Be the first to get updates

Subscribe RSS feed

Be the first to get updates

Subscribe RSS feed