Add Custom Stamp Items to the Stamp Dropdown
22 Jul 202612 minutes to read
Overview
This guide shows how to add custom images to the custom stamp dropdown in the React PDF Viewer so users can apply personalized stamps to documents.
Steps to show custom items in the custom stamp dropdown
Step 1: Create a basic React PDF Viewer sample using the getting started guide.
Step 2: Configure custom stamp settings
Use customStampSettings to define stamps that appear in the dropdown. The customStampImageSource value accepts a Base64 data URI or an absolute URL pointing to an image.
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import {
PdfViewerComponent,
Toolbar,
Magnification,
Navigation,
Annotation,
TextSelection,
TextSearch,
FormFields,
FormDesigner,
PageOrganizer,
Inject
} from '@syncfusion/ej2-react-pdfviewer';
class App extends React.Component {
constructor(props) {
super(props);
this.viewerRef = React.createRef();
}
render() {
const customStampSettings = {
isAddToMenu: true,
customStamps: [
{
customStampName: 'Image1',
customStampImageSource: 'data:image/png;base64,...' // Provide a valid base64 or URL for the image
},
{
customStampName: 'Image2',
customStampImageSource: 'data:image/png;base64,...' // Provide a valid base64 or URL for the image
}
],
enableCustomStamp: true,
opacity: 1
};
return (
<div>
<div className='control-section' style={{ marginTop: '50px' }}>
<PdfViewerComponent
ref={this.viewerRef}
id="PdfViewer"
documentPath="https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf"
resourceUrl="https://cdn.syncfusion.com/ej2/31.2.2/dist/ej2-pdfviewer-lib"
customStampSettings={customStampSettings}
style={{ height: '640px' }}
>
<Inject services={[
Toolbar,
Magnification,
Navigation,
Annotation,
TextSelection,
TextSearch,
FormFields,
FormDesigner,
PageOrganizer
]} />
</PdfViewerComponent>
</div>
</div>
);
}
}
const root = ReactDOM.createRoot(document.getElementById('sample'));
root.render(<App />);import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import {
PdfViewerComponent,
Toolbar,
Magnification,
Navigation,
Annotation,
TextSelection,
TextSearch,
FormFields,
FormDesigner,
PageOrganizer,
Inject
} from '@syncfusion/ej2-react-pdfviewer';
class App extends React.Component {
constructor(props) {
super(props);
this.viewerRef = React.createRef();
}
render() {
const customStampSettings = {
isAddToMenu: true,
customStamps: [
{
customStampName: 'Image1',
customStampImageSource: 'data:image/png;base64,...' // Provide a valid base64 or URL for the image
},
{
customStampName: 'Image2',
customStampImageSource: 'data:image/png;base64,...' // Provide a valid base64 or URL for the image
}
],
enableCustomStamp: true,
opacity: 1
};
return (
<div>
<div className='control-section' style={{ marginTop: '50px' }}>
<PdfViewerComponent
ref={this.viewerRef}
id="PdfViewer"
documentPath="https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf"
serviceUrl= "https://document.syncfusion.com/web-services/pdf-viewer/api/pdfviewer"
customStampSettings={customStampSettings}
style={{ height: '640px' }}
>
<Inject services={[
Toolbar,
Magnification,
Navigation,
Annotation,
TextSelection,
TextSearch,
FormFields,
FormDesigner,
PageOrganizer
]} />
</PdfViewerComponent>
</div>
</div>
);
}
}
const root = ReactDOM.createRoot(document.getElementById('sample'));
root.render(<App />);Use customStampSettings to specify the custom stamps that should appear in the dropdown menu.
Troubleshooting
-
Stamps do not appear in the dropdown: Ensure
isAddToMenuandenableCustomStampare both set totrue, and that thecustomStampsarray is not empty. - Image not loading (CORS errors): When using an absolute URL, the image host must send the appropriate CORS headers. Host images on the same origin or a CORS-enabled CDN.
-
Broken image icon in the dropdown: Verify that the
customStampImageSourcecontains a valid Base64 data URI or a reachable absolute URL. Open the URL directly in a browser to confirm. -
Stamps appear faded: Check the
opacityvalue; it must be between0and1.