RavishaHesh / PDFJsAnnotations

Wrapper for PDF JS to add annotations
MIT License
322 stars 98 forks source link

Question about workflow #45

Closed str closed 2 years ago

str commented 2 years ago

So, I got to this project because we need an inhouse "DocuSign" alternative. Let me see if I understood the workflow right:

Signing the document is a 2 steps process, a user will be defining where the signature will be shown, and a 2nd user will be loading their signature in the document. For this, the process would be:

Step 1, define the signature placeholder:

Step 2, request the signature:

Am I understanding this right?

Thank you for your great work.

RavishaHesh commented 2 years ago

You're correct. that's the abstract functionality of the DocuSign without the "Secure" part. Security comes with the digital signature verification between two parties. However since it's a specific use case, this library doesn't support some of the features you need to implement that. For an example, rather than drawing a rectangle we can define a new element named "placeholder" which doesn't show up on the exported document(by setting opacity to 0). Also we can lock that object option when initializing for the second time to prevent resizing and movements. These are all possible but you have do little-bit of tinkering with the package.

str commented 2 years ago

Hi @RavishaHesh

After your reply, I had to change priorities, but I now have time to continue with this integration. I'm having issues with the pdf.enableRectangle() part. It does nothing on my end.

How do I add a new rectangle? Or should I use pdf.loadFromJSON()?

RavishaHesh commented 2 years ago

@str in this commit I have changed enableRectangle little bit. Instead of inserting a rectangle when clicked on the tool I've changed it to insert into the clicked position of the canvas

str commented 2 years ago

@RavishaHesh I see it now. BUT now, the functionality stays ON. So, if I click the PDF again, another black rectangle pops up. If I try to move or resize the rectangle, because I click the PDF again, it adds another rectangle.

RavishaHesh commented 2 years ago

Yes. I tried to generalize the function since the text box also uses that model. You have to click the selector tool again if you don't want to draw another rectangle.

str commented 2 years ago

@RavishaHesh but how do you know that the rectangle has already been placed? I have a button that says "addd signature placeholder".

$('#sign').click(function(event) {
    $('.message').html('Click on the PDF to draw a rectangle where you want the signature to be placed.');
    pdf.enableRectangle(event);
});

The user tries to draw a rectangle, to place the placeholder but instead, nothing happnes on click, but a black square is placed on mouse-release.

The user can try to resize the square, but when releasing the mouse to finish resizing the square, another square is added.

How can I define a callback to trigger after placing the first square?

RavishaHesh commented 2 years ago

in your use case, since you don't have to keep the rectangle tool after drawing the first one, change https://github.com/RavishaHesh/PDFJsAnnotations/blob/master/pdfannotate.js a little bit and call inst.enableSelector() after this line

str commented 2 years ago

@RavishaHesh I ended calling the enableSelector() onPageUpdated, as it's the call back that triggers after the rectangle is set, like this:

pdf = new PDFAnnotate('pdf-container', pdfUrl, {
    onPageUpdated(page, oldData, newData) {
        pdf.enableSelector(page);
    }
});

Thank you for your work and your patience.