Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (143).NET Core  (23)Angular  (38)ASP.NET  (47)ASP.NET Core  (53)ASP.NET MVC  (83)Azure  (26)Blazor  (44)DocIO  (18)Essential JS 2  (64)Essential Studio  (159)Flutter  (46)JavaScript  (133)Microsoft  (96)PDF  (47)React  (29)Succinctly series  (118)Syncfusion  (383)TypeScript  (30)Uno Platform  (2)UWP  (4)Vue  (25)Webinar  (13)Windows Forms  (52)WPF  (86)Xamarin  (104)XlsIO  (20)Other CategoriesBarcode  (4)BI  (29)Bold BI  (3)Build conference  (6)Business intelligence  (53)Button  (4)C#  (97)Chart  (38)Cloud  (8)Company  (445)Dashboard  (4)Data Science  (3)Data Validation  (2)DataGrid  (27)Development  (232)Doc  (7)eBook  (89)Enterprise  (22)Entity Framework  (4)Essential Tools  (14)Excel  (11)Extensions  (6)File Manager  (3)Gantt  (6)Gauge  (4)Git  (3)Grid  (24)HTML  (8)Installer  (1)Knockout  (2)LINQPad  (1)Linux  (1)M-Commerce  (1)Metro Studio  (11)Mobile  (133)Mobile MVC  (9)OLAP server  (1)Orubase  (12)Partners  (20)PDF viewer  (15)Performance  (1)PHP  (1)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (5)Road Map  (9)Scheduler  (13)SfDataGrid  (7)Silverlight  (21)Sneak Peek  (12)Solution Services  (2)Spreadsheet  (2)SQL  (4)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (8)Tips and Tricks  (12)UI  (56)Uncategorized  (68)Unix  (2)User interface  (42)Visual State Manager  (1)Visual Studio  (12)Visual Studio Code  (6)Web  (85)What's new  (53)Windows 8  (19)Windows App  (1)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
Share on twitter
Share on facebook
Share on linkedin
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:

Share on twitter
Share on facebook
Share on linkedin

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

Leave a comment

Popular Now

Be the first to get updates

Subscribe RSS feed
Scroll To Top