Draw area for digital signature...

PDF-XChange Editor SDK for Developers

Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
Post Reply
lidds
User
Posts: 510
Joined: Sat May 16, 2009 1:55 pm

Draw area for digital signature...

Post by lidds »

I am using the following code to automatically add a digital signature to a file, this all works fine. However what I want to do is allow the user to define an area region on the document as to where they want to place the signature. I was wondering how I would do this?

Code: Select all

   Private Sub OneClickDigitalSignature(ByVal Inst As IPXV_Inst, ByVal Doc As IPXV_Document)
        Try
            Dim docOID As Guid = getActiveDocOID()

            Dim nID As Integer = Inst.Str2ID("op.document.addDigitalSignature", False)
            Dim Op As IOperation = Inst.CreateOp(nID)
            Dim input As ICabNode = Op.Params.Root("Input")
            input.Add().v = Doc
            Dim options As ICabNode = Op.Params.Root("Options")
            options("PageNumber").v = 0
            options("Certificate").v = "3F26DA34FB7566A7147897F44BB63A43BDBE9F68"
            'options("UseFileCertificate").v = True
            ' 0 = Unknown
            ' 1 = Approval Signature
            ' 2 = Certification signature
            ' 3 = Timestamp signature
            options("DigiSigType").v = 1
            'options("FileCertificate").v = "D:\vb.net\PDFTracker\AddDigitalSignature\AddDigitalSignature\AddDigitalSignature\111111.pfx"
            'options("CertificatePassword").v = "Dragnetadmin1"
            options("AskDestinationFileName").v = False
            options("DestinationFileName").v = MISData.Instance.TempDirectory & "\" & docOID.ToString.ToUpper & ".pdf"
            ' 1 = No changes to the document shall be permitted; any change to the document shall invalidate the signature
            ' 2 = Permitted changes shall be filling in forms, instantiating page templates, and signing; other changes shall invalidate the signature
            ' 3 = Permitted changes shall be the same as for 2, as well as annotation creation, deletion, and modification; other changes shall invalidate the signature
            options("DocMDP").v = 2
            Dim appear As ICabNode = options("SignatureAppearance")
            appear("HasTemplate").v = True
            ' I am the author of this document
            ' I agree to the specified portions of this document
            ' I have reviewed this document
            ' I am approving this document
            ' I attest to the accuracy and integrity of this document
            ' I agree to the terms defined by the placement of my signature on this document
            appear("Reason").v = "I am professional engineer"
            Dim tmplt As ICabNode = appear("Template")
            tmplt("GraphicType").v = 2
            tmplt("GraphicName").v = "D:\vb.net\PDFTracker\AddDigitalSignature\AddDigitalSignature\AddDigitalSignature\rosette.png"
            tmplt("ShowName").v = False
            tmplt("ShowDate").v = False
            tmplt("ShowLocation").v = False
            tmplt("ShowReason").v = False
            tmplt("ShowDistinguishedName").v = False
            tmplt("ShowLabels").v = False
            tmplt("ShowSubjectName").v = False
            tmplt("ShowEditorVersion").v = False
            Dim timeStamp As ICabNode = options("TimeStamping")
            timeStamp("Enabled").v = True
            Dim timeStampData As ICabNode = timeStamp("Data")
            timeStampData("URL").v = "https://ca.signfiles.com/TSAServer.aspx"

            Op.Do()
        Catch ex As Exception
            MsgBox(convertErr(ex))
        End Try
    End Sub


Thanks

Simon
lidds
User
Posts: 510
Joined: Sat May 16, 2009 1:55 pm

Re: Draw area for digital signature...

Post by lidds »

Anyone have any ideas on how to do this?
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Draw area for digital signature...

Post by Sasha - Tracker Dev Team »

Hello Simon,

Have you tried using the End-User Editor to find an analogy of what you need?

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
lidds
User
Posts: 510
Joined: Sat May 16, 2009 1:55 pm

Re: Draw area for digital signature...

Post by lidds »

Alex,

Basically what my client wants is a one click digital signature, which I have coded with help from the forum (see code in earlier post) but what I am struggling with is allowing the user to define an area on the PDF that they want the signature. Once they have done that I can get the bounds of the defined area and pass that into my code to place the digital signature in that area.

I was thinking of allowing the user to define an annotation rectangle get the coordinates of it and delete after. However this is one messy, and also I think would invalidate any earlier digital signatures that were placed as the document would have been modified?

So to recap all I want to do is allow the user to define an area that I can get the coordinates of without modifying the PDF.

Hope that makes sense

Thanks

Simon
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Draw area for digital signature...

Post by Sasha - Tracker Dev Team »

Hello Simon,

Will the user draw that area somehow?
I think the Signature Field will work for you. Go to edit form tool - you can add it from there.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
lidds
User
Posts: 510
Joined: Sat May 16, 2009 1:55 pm

Re: Draw area for digital signature...

Post by lidds »

Alex,

Not in front of the computer at the moment but I think the signature form field launches your form, where I want to insert the signature in my custom code in that area and I could not find a operation to intercept??

Thanks

Simon
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Draw area for digital signature...

Post by Sasha - Tracker Dev Team »

Hello Simon,

Then again, how the user will define an area of the signature - will he just use your form and several edits to input the coordinates? Or will he draw in the Editor control?

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
lidds
User
Posts: 510
Joined: Sat May 16, 2009 1:55 pm

Re: Draw area for digital signature...

Post by lidds »

I would like the user to draw in the editor control a region / area

Thanks

Simon
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Draw area for digital signature...

Post by Sasha - Tracker Dev Team »

Hello Simon,

Well then the Snapshot Tool can work for this matter - it defines a IPXV_PageRectSelection type basically allowing you to get it as a signature placement rectangle. And also, the benefit of the snapshot is that the PDF document itself is not being modified.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
lidds
User
Posts: 510
Joined: Sat May 16, 2009 1:55 pm

Re: Draw area for digital signature...

Post by lidds »

Thanks Alex, I'll give this a go later today.
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Draw area for digital signature...

Post by Sasha - Tracker Dev Team »

Additionally you can customize the snapshot's command icon and text so that it would match your criteria. Even better - create your own command that would use the snapshots handler in the overloaded methods so that you could see when your command executes.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
lidds
User
Posts: 510
Joined: Sat May 16, 2009 1:55 pm

Re: Draw area for digital signature...

Post by lidds »

Hi Alex,

Stuggling with getting the IPXV_PageRectSelection of the snapshot tool, obviously doing something wrong as I get the following error:

Error [System]: Invalid pointer

I am using the following code:

Code: Select all

        ElseIf e.nEventID = nIDS(CInt(IDS.e_docSelection_changed)) Then
            Try
                Dim Doc As PDFXEdit.IPXV_Document = CType(e.pFrom, PDFXEdit.IPXV_Document)
                Dim docSel As IPXV_DocSelection = Doc.GetSel(1)
                Dim prs As IPXV_PageRectSelection = CType(docSel, IPXV_PageRectSelection)
                Console.WriteLine(prs.PageRect.bottom.ToString & " " & prs.PageRect.top.ToString)

                e.pEvent.Result = 1
                e.pEvent.Handled = True
            Catch ex As Exception
                Console.WriteLine(convertErr(ex))

                e.pEvent.Result = 1
                e.pEvent.Handled = True
            End Try
Any help would be appreshiated.

Thanks

Simon
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Draw area for digital signature...

Post by Sasha - Tracker Dev Team »

Hello Simon,

And what is Doc.GetSel(1)?
The correct code is:

Code: Select all

int nSel = pdfCtl.Inst.Str2ID("selection.pageRect");
PDFXEdit.IPXV_DocSelection docSel = pdfCtl.Doc.GetSel(nSel);
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
lidds
User
Posts: 510
Joined: Sat May 16, 2009 1:55 pm

Re: Draw area for digital signature...

Post by lidds »

Alex,

Thanks this worked perfectly.

Just one last question. When I execute the cmd.tool.snapshot it changes the cursor icon to a camera, is there anyway that I can change this to match the cursor icon that is displayed when placing a digital signature (the one with a rectangle and pencil)?

Thanks

Simon
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Draw area for digital signature...

Post by Sasha - Tracker Dev Team »

Hello Simon,

I believe I've already answered this one:
https://www.pdf-xchange.com/forum3 ... or#p114625

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
lidds
User
Posts: 510
Joined: Sat May 16, 2009 1:55 pm

Re: Draw area for digital signature...

Post by lidds »

Sorry Alex, my mistake, forgot I asked this
lidds
User
Posts: 510
Joined: Sat May 16, 2009 1:55 pm

Re: Draw area for digital signature...

Post by lidds »

Alex,

I have tried the following code, but it does not change the icon?? I have also tried it in:

e_operBeforeExecute
e_operExecuted

but nothing happens

Code: Select all

    Public Sub RunOneClickDigitalSignature()
        Dim cmd As PDFXEdit.IUIX_Cmd = uiInst.CmdManager.Cmds.Find("cmd.tool.snapshot")
        Me.docPreview.Inst.ExecUICmd2(cmd.ID)
        uiInst.SetCursor(uiInst.GetCursorID("pen"))
    End Sub
Thanks

Simon
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Draw area for digital signature...

Post by Sasha - Tracker Dev Team »

Hello Simon,

For this you will have to implement and use the Custom Event Handler and use it carefully:

Code: Select all

		//Event listener that listens for all of the needed events
		public void OnEvent(PDFXEdit.IUIX_Obj pSender, PDFXEdit.IUIX_Event pEvent)
		{
			//If the event is not handled then it will be 
			pEvent.Handled = false;
			//
			if (pEvent.Code == (int)0x200) //WM_MOUSEMOVE
			{
				Parent.uiInst.SetCursor(Parent.uiInst.GetCursorID("pen"));
				pEvent.Handled = true;
			}

Code: Select all

		//Target that will contain the custom event handler implementation for the given object
		public CustomEventTarget myEventTarget = null; //PS: Do not forget to dispose of it

		private void initilaizeCustomEventListenerToolStripMenuItem_Click(object sender, EventArgs e)
		{
			//Creating the drop target and filling it's supported formats
			myEventTarget = new CustomEventTarget(pdfCtl.Doc.ActiveView.PagesView.Obj, this);
		}
Basically you will have to create the custom event target when you activate the snapshot tool and dispose of it when you finish using it.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Post Reply