Import seals/signatures from Endpoint

Product: PDFTro

Product Version:

Please give a brief summary of your issue:
(Think of this as an email subject)

Please describe your issue and provide steps to reproduce it:
(The more descriptive your answer, the faster we are able to help you)

Hi everyone.

I trying import seals/signatures from endpoint and I have error

This is my code.

getSignatures()
			.then((response) => {
				webViewer.UI.enableElements(['signatureToolGroupButton']);
				const signatureTool = instanceDocumentViewer.getTool('AnnotationCreateSignature');
				const { data } = response;

				webViewer.UI.setMaxSignaturesCount(data.length);
				let signatures = data.map((element) => {
					return element.imgData;
				});

				signatureTool.importSignatures(signatures);
			})
			.catch((err) => console.log(err));

And this is a base64 data from the endpoint
[ { "signatureId": 0, "signatureDescription": "TEST IMAGE 1/0", "imageData": "data:image/png;base64,iVBO..." }, { "signatureId": 1, "signatureDescription": "TEST IMAGE 1/1", "imageData": "data:image/png;base64,iVBO..." }, { "signatureId": 2, "signatureDescription": "TEST IMAGE 1/2", "imageData": "data:image/png;base64,iVBOR..." }, ]

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAMAAADXqc3KAAAB+FBMVEUAAAA/mUPidDHiLi5Cn0XkNTPmeUrkdUg/m0Q0pEfcpSbwaVdKskg+lUP4zA/iLi3msSHkOjVAmETdJSjtYFE/lkPnRj3sWUs8kkLeqCVIq0fxvhXqUkbVmSjwa1n1yBLepyX1xxP0xRXqUkboST9KukpHpUbuvRrzrhF/ljbwaljuZFM4jELaoSdLtElJrUj1xxP6zwzfqSU4i0HYnydMtUlIqUfywxb60AxZqEXaoifgMCXptR9MtklHpEY2iUHWnSjvvRr70QujkC+pUC/90glMuEnlOjVMt0j70QriLS1LtEnnRj3qUUXfIidOjsxAhcZFo0bjNDH0xxNLr0dIrUdmntVTkMoyfL8jcLBRuErhJyrgKyb4zA/5zg3tYFBBmUTmQTnhMinruBzvvhnxwxZ/st+Ktt5zp9hqota2vtK6y9FemNBblc9HiMiTtMbFtsM6gcPV2r6dwroseLrMrbQrdLGdyKoobKbo3Zh+ynrgVllZulTsXE3rV0pIqUf42UVUo0JyjEHoS0HmsiHRGR/lmRz/1hjqnxjvpRWfwtOhusaz0LRGf7FEfbDVmqHXlJeW0pbXq5bec3fX0nTnzmuJuWvhoFFhm0FtrziBsjaAaDCYWC+uSi6jQS3FsSfLJiTirCOkuCG1KiG+wSC+GBvgyhTszQ64Z77KAAAARXRSTlMAIQRDLyUgCwsE6ebm5ubg2dLR0byXl4FDQzU1NDEuLSUgC+vr6urq6ubb29vb2tra2tG8vLu7u7uXl5eXgYGBgYGBLiUALabIAAABsElEQVQoz12S9VPjQBxHt8VaOA6HE+AOzv1wd7pJk5I2adpCC7RUcHd3d3fXf5PvLkxheD++z+yb7GSRlwD/+Hj/APQCZWxM5M+goF+RMbHK594v+tPoiN1uHxkt+xzt9+R9wnRTZZQpXQ0T5uP1IQxToyOAZiQu5HEpjeA4SWIoksRxNiGC1tRZJ4LNxgHgnU5nJZBDvuDdl8lzQRBsQ+s9PZt7s7Pz8wsL39/DkIfZ4xlB2Gqsq62ta9oxVlVrNZpihFRpGO9fzQw1ms0NDWZz07iGkJmIFH8xxkc3a/WWlubmFkv9AB2SEpDvKxbjidN2faseaNV3zoHXvv7wMODJdkOHAegweAfFPx4G67KluxzottCU9n8CUqXzcIQdXOytAHqXxomvykhEKN9EFutG22p//0rbNvHVxiJywa8yS2KDfV1dfbu31H8jF1RHiTKtWYeHxUvq3bn0pyjCRaiRU6aDO+gb3aEfEeVNsDgm8zzLy9egPa7Qt8TSJdwhjplk06HH43ZNJ3s91KKCHQ5x4sw1fRGYDZ0n1L4FKb9/BP5JLYxToheoFCVxz57PPS8UhhEpLBVeAAAAAElFTkSuQmCC

In the console, I have the next error
getSignatureDataToStore.js:20 Uncaught (in promise) TypeError: Cannot read properties of null (reading ‘StrokeThickness’)

Please provide a link to a minimal sample where the issue is reproducible:

Hello,

Thank you for contacting us about WebViewer and for the sample code. Can I confirm what the response.data you are using look like? For the endpoint you mention it has an imageData property. However in your code you had

let signatures = data.map((element) => {
  return element.imgData;
});

I just want to confirm if the above should be using imageData instead. Besides that, make sure to check the strings in “signatures” are valid base64 images string (that nothing got truncated, or if it has misformatted data). Please let me know if either of those works, if not would it be possible to send a small sample file of you using setMaxSignaturesCount with the data you using? Thank you

Best Regards,

Andrew Yip
Software Developer
PDFTron Systems, Inc.
www.pdftron.com

Hi, thanks for answering.

And its correct, was my bad. From the backend change de property because this reason wasn’t possible fill the dropdowns (seals and signatures).

Thanks so much.

Hi,

Thank you for the update and I’m glad the solution worked for you. I’ll also add a note in our backlog that the “signatureTool.importSignatures” API should provide better error messages. Feel free to let us know if you have any other questions

Best Regards,

Andrew Yip
Software Developer
PDFTron Systems, Inc.
www.pdftron.com

1 Like