Skip to content

960253: Add a view for the custom stamp in SfPdfViewer #3313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Jun 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions MAUI/PDF-Viewer/Stamps.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,46 @@ void AddCustomStampAnnotation()
{% endhighlight %}
{% endtabs %}

### Add a view as custom stamps without using the toolbar

You can create a custom stamp from any view, such as Button, Entry, Label, Image, or any other view, and add it to a PDF document. The following example explains how to create a custom stamp from a button view in the application and add it to a PDF document using the [AddAnnotation](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.PdfViewer.SfPdfViewer.html#Syncfusion_Maui_PdfViewer_SfPdfViewer_AddAnnotation_Syncfusion_Maui_PdfViewer_Annotation_) method of the [SfPdfViewer](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.PdfViewer.SfPdfViewer.html).

{% tabs %}
{% highlight C# %}
StampAnnotation CreateCustomStamp()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you confirm that this code directly copy pasted from a workable sample in Visual Studio or VS Code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copy paste from a workable sample in visual studio

{
int pageNumber = 1;

// Define the bounds for the stamp to be placed in the PDF page.
RectF bounds = new RectF(100, 100, 200, 100);

// Create a button to be used as the visual content of the stamp.
var button = new Button
{
Text = "Click Me",
BackgroundColor = Colors.Blue,
};

// Create a custom stamp annotation using the button view.
StampAnnotation customStamp = new StampAnnotation(button,pageNumber,bounds);

// Return the stamp annotation.
return customStamp;
}

void AddCustomStampAnnotation()
{
StampAnnotation stampAnnotation = CreateCustomStamp();

// Add the stamp to the PDF document using `SfPdfViewer` instance.
PdfViewer.AddAnnotation(stampAnnotation);
}
{% endhighlight %}
{% endtabs %}

N> * The view will be converted as an image in the saved PDF document. The view becomes read only once saved, and its contents cannot be edited after saving the document.
N> * Interactions within the view such as button clicks or text entry will not function inside the PDF Viewer.

## Edit the selected stamp

You can edit the properties of the selected stamp annotation programmatically by accessing the selected annotation instance. The selected annotation instance may be obtained from the [AnnotationSelected](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.PdfViewer.SfPdfViewer.html#Syncfusion_Maui_PdfViewer_SfPdfViewer_AnnotationSelected) event.
Expand Down