I am trying to test out pdfjs.express for the needs of our project and
following the documentation I am a little bit lost, would like to get your
support in this case.
I am trying to implement the fill and sign feature and with this I need
to clarify the below questions:
If I have a custom image already predefined as signature, how can I add it
After placing a signature how to get the X and Y coordinates
How to get the Width and Height of the signature image
How to retrieve the page number that the signature was places
As well as I am finding difficulties to implement the Sign Here feature
I am using Angular@10 for implementing pdfjs.express
Would appreciate your support in this case
Thank you
Gentian
Code snippet
loadViewer(file) {
WebViewer({
path: '../../../../assets/static/lib',
}, this.viewer.nativeElement)
.then(instance => {
instance.UI.loadDocument(file, { filename: file.name });
this.wvInstance = instance;
this.viewer.nativeElement.addEventListener('pageChanged', (e) => {
const [ pageNumber ] = e.detail;
console.log(`Current page is ${pageNumber}`);
});
// or from the docViewer instance
instance.docViewer.on('annotationsLoaded', (e) => {
console.log('annotations loaded', e);
});
});
}
getCoordinates(){
const { Annotations } = this.wvInstance;
let field = new Annotations.Forms.Field('Signature', { type: "Sig" });
let sig = new Annotations.SignatureWidgetAnnotation(field);
console.log(sig.getX())
console.log(sig)
}
To add an image as a signature, you can use the importSignatures api. It accepts a base 64 string, so you need to load your predefined image as a base64 string and pass it in.
2 & 3 & 4) There are many many ways to do this, but the easiest is to listen to the annotationChanged event and get the coordinates of the new signature like this: