I am working on a project to integrate PDF Viewer (React) with Topaz Signature Pad.
According to topaz web demo, there are two events that require integration. One is the "Sign" button event that will start Topaz service, the other one is "Done" button event that will generate signature data and stop Topaz service.
I read the Syncfusion PDF Viewer documents and it seems there is no available API to use for the integration. So I tried to use customized toolbar to create my own button in PDF Viewer to start Topaz service. Below is my idea:
Now I am stuck at step 3, can you please help me on this?
Below is the PDF Viewer built-in UI to add signature, upon click Create button, I am able to place the signature into PDF, so how to do it in my customized button event?
|
<button id="openSignatureDialog">openSignatureDialog</button>
document.getElementById('openSignatureDialog').addEventListener('click', () => {
viewer.annotationModule.setAnnotationMode('HandWrittenSignature');
});
|
|
viewer.addSignature = (args) => {
console.log('Signature base64 string is ' + args.data);
};
|
Hi Vasugi,
Thank you for the code snippet. I managed to launch PDF Viewer signature dialog and display signature from Topaz Signature Pad. However, the create button is grey out (refer to below screenshot). I guess it is because I use document.getElementById('pdfcontainer_signatureCanvas_') to access the canvas in the dialog to allow Topaz draw on the screen, but PDF Viewer internally does not detect the change.
Do you have any idea on how to solve it?
|
var createbtn = document.getElementsByClassName('e-pv-createbtn')[0];
createbtn.disabled = false;
|
Hi Vasugi,
Thank you for the advise. I have tried to enable the Create button by modifying html directly in chrome DevTools, but Syncfusion return me an empty signature to place in PDF.
Below is the code snippet, I have also attached the full source code of Topaz library in the attachment for your reference.
const SyncfusionTest: React.FC = () => { const viewer = useRef<PdfViewerComponent>(); const clickHandler = (args: ClickEventArgs) => { switch (args.item.id) { case 'sign_action': viewer.current?.annotationModule.setAnnotationMode('HandWrittenSignature'); // ... Code to preapare Topaz Siganture Pad ctx = document.getElementById('pdfcontainer_signatureCanvas_').getContext('2d'); // This is the code to allow topaz draw on syncfusion signature panel // .. Other Topaz setup break; } }; return ( <div> <div className="e-pdf-toolbar"> <ToolbarComponent clicked={clickHandler}> <ItemsDirective> <ItemDirective prefixIcon="e-pv-open-document-icon" id="sign_action" tooltipText="Open" ></ItemDirective> </ItemsDirective> </ToolbarComponent> </div> <PdfViewerComponent ref={viewer} id="pdfcontainer" documentPath="PDF_Succinctly.pdf" serviceUrl="https://ej2services.syncfusion.com/production/web-services/api/pdfviewer" style={{ height: '640px' }} enableToolbar={false} enableNavigationToolbar={false} > <Inject services={[ Toolbar, Magnification, Navigation, Annotation, LinkAnnotation, BookmarkView, ThumbnailView, Print, TextSelection, TextSearch, FormFields, ]} /> </PdfViewerComponent> </div> ); }; export default SyncfusionTest; |
|
Draw:
var formField = viewer.retrieveFormFields();
formField[8]. signatureType = [SignatureType.Draw];
formField[8].value = ""; // Provide the path value.
viewer.updateFormFieldsValue(formField[8]);
Type:
var formField = viewer.retrieveFormFields();
formField[8].signatureType =[SignatureType.Type];
formField[8].value = "name"; // Provide the name
formField[8].fontName = "Symbol";
viewer.updateFormFieldsValue(formField[8]);
Image:
var formField = viewer.retrieveFormFields();
formField[8].signatureType=[SignatureType.Image];
formField[8].value = ""; // Provide the base64 string
viewer.updateFormFieldsValue(formField[8]);
|
Hi Vasugi,
I managed to integrate Topaz Signature Pad with Syncfusion PDF Viewer by using the code you provided, thank you very much.