Introduction
New development challenges continuously call for
yet another things to be done to circumvent the tricky limitations
all big name platform providers impose on us for whatever reasons.
Nevertheless we, at Apitron, believe that it just makes our software
better and if one could use a rewording – cuts
it like a diamond for it to become an even
better all-around tool for our customers.
We already went a long way to
make our tools cross-platform with .NET,
MONO and Xamarin, so now they cover many
usage scenarios and provide a solid toolset
for creating full-cycle PDF processing apps. But we have even
more to offer, a web API for PDF processing with the focus on signing
and watermarking of documents. It’s designed to be hosted in-house
but we have a demo installation publicly available as well.
Demo
Like
it has been said before, the API can be hosted anywhere including
your own server if you need. It supports signing and watermarking of
PDF documents and we have set up a test installation for you to try
it out. The slides below demonstrate the user interface of a test
client web app that makes use of the aforementioned
web api and is available for download from our github
repo. As the
first step after
downloading, you’d have to configure the app to use the right web
api installation URL
by editing the “ServiceUrl” in its web.config. We
used our demo url here.
Pic.
1 Configuring client app
|
After that we can run the app in
browser and proceed by selecting the file and desired action, see
below:
Pic.
2 Selecting source
file
and desired
action
|
Source
document used here
is a dummy letter crafted for illustrative
purposes, it’s
shown below:
Pic. 3 Source PDF document
|
After setting up the desired signature properties
as shown on the next slide, we will get our doc sent to the server,
signed there and downloaded back. The demo installation uses https,
so there won’t a be a plaintext data exchange happening and we
won’t store and use any data sent to our web api except for
providing you with signing and watermarking services.
Pic.
4 Applying signature settings
|
So
here we can choose
among the existing server keys for signing but
the demo installation has only one such key listed
(with a word
“password” used as its actual
password). You
can also upload your own key and sign with it if you wish. The
purpose of having
a set of pre-loaded keys is to provide an organization with a way to
share certain functions among employees without actually giving them
access to the signing certificates and having common keys in one
place for easy management and better protection.
It might be the case
that you’d want to employ a HSM or other means for
storing the keys. All these things become
possible with a custom setup and
implementation of storage modules. Contact us if you are interested
to know more. Our
web API is based
on Apitron PDF Kit product and requires a
license for this product to become
fully functional. Otherwise it will work in evaluation mode, but
the important note is that web API package
itself is provided
free of charge.
The results of the signing operation are shown
below, signature image (if set) takes priority over signature text
hence the name and surname represented by the supplied image at the
bottom of the page.
Pic. 5 Signed PDF document
|
Watermarking
requires less parameters for now, it can be either a text string or
an image as shown below:
Pic.
6 Applying watermark settings
|
The image (if set) gets centered on the page and
the text gets aligned diagonally along the line coming from the left
bottom corner to the top right corner.
Sample
watermarked document is shown below:
Pic.
7
Watermarked
PDF document
|
The Code
JS code sample showing how to perform the request to the API is
provided below, it is the excerpt from the client app referenced in
this post, so you can examine its code and find more info there.
[Javascript]
...
var formData = new FormData();
formData.append("signatureText", “your text here”);
formData.append("signatureImage", [image data here]);
formData.append("signingKeyName", “key name here”);
formData.append("signingCertificate", [cert data here]);
formData.append("signingPassword", “cert password here”);
formData.append("signatureBoundary", “115,150,185,190”);
formData.append("signaturePageIndexStart", 0);
formData.append("signaturePageIndexEnd", 0);
$.each(filesToSend,
function (index, value) {
formData.append("sourceFiles" + index, value);
});
// call signing api
$.ajax({ url: “signing api url here”,
data: formData,
contentType: false,
processData: false,
type: 'POST',
success: function (data) {
getResults(“signing api url here”, data);
},
error: function (xhr, textStatus, errorThrown) {
reportError("Error occured while contacting the server: " + textStatus);
}
});
We’re performing the REST call here, namely POST the form with parameters describing our signing request, get back the signing task Id and later query the same service using the acquired task Id to get the result. We recommend looking at the sources of the sample app for the detailed explanation on how to make these calls.
Summary
We hope that new web API will facilitate the
development of your PDF processing apps. It’s never been so easy to
handle PDFs just with a few lines of code and get the serious job
done so quickly. An option to have your own installation of the web
api free of charge is a great benefit and our professional customer
support can always help you with any questions you might have.