Sign PDF REST API

Hello, I am evaluating your REST API for use in our application. Our workflow is pretty simple: upload a document, sign the document, download the signed document and delete the document. So far, things are looking promising.

I am having some trouble, however, when I attempt to sign. I have uploaded a test document named “Sample.pdf” into a folder named “test”. My routine then builds the signed URL for the sign document request:

http://api.aspose.com/v1.1/pdf/test/Sample.pdf/sign?appSID=****&signature=****

The request body is:

{

“SignaturePath”: “test.pfx”,

“SignatureType”: 1,

“Password”: "****",****

“Appearance”: “joe-client.png”,

“Reason”: “Success”,

“Contact”: "joe@test.com",

“Location”: “Texas”,

“Visible”: true,

“Rectangle”: {

“X”: 100,

“Y”: 100,

“Width”: 400,

“Height”: 100

},

“FormFieldName”: “Signature1”,

“Authority”: “Joe Client”,

“Date”: {

“Links”: null

}

}

When I test this in Java, I receive the following stack trace:

java.io.FileNotFoundException: http://api.aspose.com/v1.1/pdf/test/Sample.pdf/sign?appSID=&signature=

at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)

at com..****.aspose.DocumentController.sign(DocumentController.java:53)****

at com..****.aspose.Program.main(Program.java:10)

When I test it through a browser, I receive the following message:

404 - File or directory not found.

The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.

From what I can tell of the documentation, I have formed the URL correctly based on the location of the PDF file but perhaps it has something to do with the values for the “SignaturePath” or “Appearance” properties. There is no documentation showing that these files are sent as part of the request so I have uploaded them to Aspose in the root of my storage. Do you have any ideas on what I am doing incorrectly?

One final and unrelated question: is there a REST API to delete a document? I didn’t find any documentation.

Thanks much,

Erich Heard

Hi Erich,

We are working on a Java example for sign API and will share with you once ready. As far as deleting a document is concerned, you can use Delete File example for this purpose.

Best Regards,

Thanks for the quick response, Muhammad. The delete file worked like a charm. When do you think you will be posting your example?

As for signing and downloading, I have done some more testing and found that if I attempt to work on a file in the root of my storage (“Sample.pdf”) I receive an HTTP 400 rather than the 404 I received when the file was in the “test” folder (“test/Sample.pdf”). When I test it through a browser, I receive the following response:

Invalid Amazon S3 file path 7675/25bef367-c398-4088-9674-c197d7538059/

I am using default Aspose storage, so I do not know where this is coming from unless you are working with Amazon behind the scenes. Here is the code I am using to sign the document. My download code is basically the same just with a different url and no json.

String json = “{” +

““SignaturePath”: “test.pfx”,” +

““SignatureType”: 1,” +

““Password”: “****”,” +

““Appearance”: “joe-client.png”,” +

““Reason”: “Success”,” +

““Contact”: "joe@test.com”," +

““Location”: “Texas”,” +

““Visible”: true,” +

““Rectangle”: {” +

““X”: 100,” +

““Y”: 100,” +

““Width”: 400,” +

““Height”: 100” +

“},” +

““FormFieldName”: “Signature1”,” +

““Authority”: “Joe Client”,” +

““Date”: {” +

““Links”: null” +

“}” +

“}”;

String url = “http://api.aspose.com/v1.1/pdf/” + filename + “/sign”;

url = this.signURL( url, Program.APP_SID, Program.APP_KEY );

HttpURLConnection conn = this.initializeRequest( url, “POST” );

conn.setRequestProperty( “Content-Type”, “application/json” );

conn.setRequestProperty( “Content-Length”, “” + json.length( ) );

conn.connect( );

java.io.OutputStream out = conn.getOutputStream( );

out.write( json.getBytes( ) );

out.flush( );

InputStream response = conn.getInputStream( );

String text = this.streamToText( response );

return text;

Hi Erich,


Thanks for your feedback. It is good to know that you have managed to accomplish the file deletion task.

Moreover thanks for your investigation about the file signing. We are working over the code and will update you asap.

Thanks for your patience and cooperation.

Best Regards,

Sorry to be a pain, but do you know when this might be done? We are evaluating your API for use in an application that is starting development and we need to make a choice of providers ASAP.


Thanks for your help,
Erich

Hi Erich,

Sorry for the inconvenience.

There seems to be some issue with sign PDFs API and we are working on this issue. We will update you as soon as it is resolved.

Best Regards,

Hey guys,


It has been almost a month since I reported these issues. I just retested with the same results. Is there any news on when they will be fixed? If it is not very soon, we will have to move on to another vendor.

Thanks,
Erich

Hi Erich,

First of all there is an issue with your URI http://api.aspose.com/v1.1/pdf/test/Sample.pdf/sign?appSID=****&signature=****. Folder path should not be passed as part of the file name.

You should pass folder parameter to specify location of the file e.g. http://api.aspose.com/v1.1/pdf/Sample.pdf/sign?folder=test&appSID=****&signature=****

A working Java example has been added at http://www.aspose.com/docs/display/pdfcloud/Sign+PDF+Documents . This is a XML example and you can try passing XML if you see any issue passing JSON. Please note that folder path will be part of the PFX and Image file names in the XML/JSON if your PFX and Image files are not on the root folder.

Please test it and let us know if you still see any issue.

Muhammad,

Thanks for the quick response and explanation. The folder path makes sense as I was getting a 404 when trying to specify a folder and a 400 when I was not. Unfortunately the XML example does not work for my values (see below). I still get a 400 when I set my PFX, password, appearance, etc. I did find that if I alter the PFX name to something non-existent I go back to getting a 404 which is correct. I do NOT get a 404 if I change the name of the appearance file which leads me to believe that your API is perhaps having a problem with the certificate. Is there any chance we can get better error messaging so I can debug the actual problem?

Thanks,

Erich

xml = "<?xml version='1.0' encoding='utf-8'?> " +

" " +

" onboard.pfx " +

" PKCS7 " +

" **** " +

" joe-client.png " +

" Success " +

" [erichheard@kpmg.com](mailto:erichheard@kpmg.com) " +

" United States " +

" true " +

" " +

" 100 " +

" 100 " +

" 400 " +

" 100 " +

" " +

" Signature1 " +

" Erich Heard " +

" 08/01/2012 12:15:00.000 PM " +

“”;

Hi Erich,

Can you please share your input PDF, PFX and Image files? We will test at our end and check why it is not working.

Aspose for Cloud service checks the request and returns HTTP error without processing the file if request is not properly formatted. Only valid requests are entertained by our Cloud service and you should get proper error message from Aspose in this case.

Best Regards,

Muhammad,


Here are the files in question. The password is “smarti” without quotes.

Thanks,
Erich

Hi Erich,

Thanks for the samples. We will update you soon.

Best Regards,