Watch videos with subtitles in your language, upload your videos, create your own subtitles! Click here to learn more on "how to Dotsub"

Add a Signature Field to a PDF Using the Java API

0 (0 Likes / 0 Dislikes)
[ADOBE DEVELOPER CONNECTION] [Duane Nickull, Platform Evangelist] Hi, I'm Duane Nickull, Twitter handle duanechaos. I'm one of the Adobe Evangelists, and this is a series on LiveCycle ES for Java developers. [Adding Digital Signatures to PDFs with Java and LiveCycle ES2] How to work with the LiveCycle ES client-side SDKs. In the previous ones, we set up the development environment, we made an EJB call to LiveCycle ES server, and then we made a SOAP call to the LiveCycle ES2 server. This one, we're going to do something a little bit different. We're going to take our skeleton code that we've written from the previous examples, and we're going to work with the signature client service. We're going to add a digital signature programmatically-- a signature field programmatically--to a PDF document and invoke this over SOAP. We're going to send in a PDF and get our PDF returned with the signature field on it. This is very easy to do, luckily. All the code samples from Scott McDonald and Tyler Rushden have made this very, very simple for Java developers. [For a LiveCycle ES2 Developer DVD contact [email protected]] If you haven't done so yet, contact us here at the show. You'll get a LiveCycle DVD sent out to you with a special developer license, and we'll point you at this quick start library and you can get going and coding with this right away. Let's get started, shall we? [Download the project and extras from: http://technoracle.blogspot.om/2010/05/livecycle-for-java-developers-video.html] I've got the same client code that I've had in the previous examples. We're basically using the SOAP endpoint. We've got a couple to-dos here, so we're creating a signature service client. This is being created by passing in the connection properties from the service client factory as a parameter. We're taking the input file--that's that "C:\\munich\\test.pdf"-- and we're going to add a signature field to it. Now if we look at the signature API--the signature API for this particular call takes a number of different parameters. The method signature takes--an in document, the name of the field, the page number that we're going to put it on, and a couple of other parameters. We can see these when we start to work with the code at the bottom. So before we do this, we're going to have to set up a signature field name. This can just be a simple string, so we'll call it signature field 1, so it's fieldName --and we'll just pass it a string here-- = "signaturefield1"; --all lowercase. Maybe we'll even spell it correctly, just for the show. Now, when you lay out a signature, the signature field has to have 4 position coordinates on it, and these are the lower left-hand x and y, rather than the top x and y, and there's a reason for that that I'll explain. Most signature fields are in fact added to the lower side of the document, so in order to position it, the minimum number of integers we're going to have to pass it is the x, y from the lower left, and then the height and the width. And with that information, LiveCycle ES is SDK can then draw the box, or the LiveCycle ES can draw the box for the signature. So we're going to add our PositionRectangle-- and we're going to create a new one, so we'll call ours post and this is going to be the 4 coordinates we just talked about-- = PositionRectangle and we'll feed it the values of (10, 10, 133, 25) --133 for the width and 25 for the height, and that should be adequate. The next thing we're going to have to do is specify the page number for the signature field to go on. Now, our position is that this test document is only 1 page long anyhow, but imagine you had a document that was several pages long. You do have to pass it this value, so we'll just use a java.lang.Integer for this and we'll call this one pageNum and construct your method for that-- = new java.lang.Integer and we'll set the value for that at (1); and now we finally get to the meat of this. This is where we add the method call to place the signature field on the doc, so if you remember when we set up our code up above, we have our in document (inDoc) This is the one we're going to do. We're going to create the sigField doc to PDF document and this will equal our signature client, which is up at the top-- signClient. This is taken from this particular line of code, and we're going to invoke the add visible signature field though, there's an invisible one as well--this is used for certifying documents. And we can see here that the add signature field first takes the document as argument 0, the string that corresponds to the field name is argument 1-- because you have to have a way of referencing these later if there's more than one signature field on a document, and in the positionRectangle. So let's start with this--our document itself will be the inDoc, and the second argument will be fieldName. The third argument will be our pageNum. This is the positionRectangle here (post) and we could optionally set some other of the MDP options, so in this case, we're just going to put null on this one, and we'll overwrite this one as null, too. And that is pretty much all we have to do make the call. Now we've gotten no red x's on this. At this point, we'll shrink it down and run it and wait until the red x tells us it's terminated running and we should go and see our adc3 and we'll open this up. And if we scroll down to the lower left hand side, we see in fact that we have a signature field that's placed on our document. I'm Duane Nickull. I'm one of the Adobe Evangelists. Try this out yourself; this is very, very easy to do, and it's a great series of tutorials from the guys from the ES2 team. Peace, love, may your code compile on the first try. [ADOBE DEVELOPER CONNECTION]

Video Details

Duration: 7 minutes and 8 seconds
Country:
Language: English
License: All rights reserved
Genre: None
Views: 406
Posted by: adobetv on Oct 21, 2010

In this additional video highlighting LiveCycle ES2 for Java developers, Duane Nickull programmatically adds a digital signature field to a PDF document using the Java API.

Caption and Translate

    Sign In/Register for Dotsub to translate this video.