Introducing the Adobe PDF Watermark API | by Raymond Camden | Jul, 2024


Watermarks provide an important feature for PDFs by allowing you to ‘mark’ a document. This can be used to signify who the document was created for, specify the status of content, add important information about the document, and so forth. Today we’re happy to announce that Acrobat Services has released the PDF Watermark API, currently available via our REST API and soon supported via our various SDKs. Let’s demonstrate this in action.

At a high level, adding watermarks is a three-step process.

  • First, you upload the PDF you wish to be watermarked.
  • Second, you upload the PDF to be used as a watermark. (Currently, you can only add a PDF as a watermark. In the future, we may support text or image-based watermarks.)
  • Create the Watermark job, optionally specifying a range of pages for it to be applied to as well as your desired opacity. Watermarks may also be placed on the foreground or background, with foreground being the default. In general, it is safer to use the foreground as a background watermark can be covered by opaque elements of the PDF-like images.

Note that like other Acrobat Services, you can use cloud-based storage instead of uploading assets.

We’ve covered the basics of our REST API before, but if you’ve missed that, you can read the introduction here: Announcing the New Adobe Document Services REST APIs. As the basics of authentication and asset uploading haven’t changed in two years, we’ll skip over that code and instead focus on how easy it is to kick off the watermark job. Given that you’ve uploaded a source PDF:

Screenshot of a PDF document

And given an uploaded PDF to use for watermarking:

Screenshot of PDF that says, Propery of Fictional Made Up Company

You can make a request to kick off a watermarking job like so:

Note that this example only uses the required arguments specifying our input (the first PDF shown above) and our watermark (the second PDF shown above).

Again, as with our other APIs, this returns a “job” URL that you can make a request to and check the status. When the job successfully completes, you can then download the result. (Note that as with our other APIs, specifying a webhook URL is also supported.)

Sample PDF with watermark applied.

You can find the complete source for this below:

As mentioned above, currently the PDF Watermark API only supports static PDF sources for the actual watermark, however, we already support a way to create dynamic PDFs with the Document Generation API. If you’ve never encountered it before, this API lets you use a Microsoft Word document as a template. In the Word doc, you can insert tokens that when passed to the API along with your data, will be replaced with real values in the generated PDF. The API supports simple variable substitutions along with more complex use cases involving looping, conditionals, dynamic tables and so forth. For our need here though we can keep it simple. Here’s a Word document we’ll use as a watermark:

Word document with a token, {{ email }} in the content.

In the Word document above, the section, {{ email }} will be replaced with a real value when the Document Generation API is called. We can then take the result of that call and use it to watermark another PDF.

How is that done? First, we upload our source Word document and then we can call the Document Generation API:

This snippet skips over a bit of stuff we’ve already covered, but you can see the call to the REST API passing the asset ID of the uploaded Word document along with our data, which in this case is just an email address.

Now, here comes the fun part. We don’t have to actually download the generated PDF. The result, docgenResult, contains an asset object and we can simply use that in our Watermark call:

For this demo, we modified the opacity in our Watermark API call to specify a lower opacity:

Once run and the result stored, here’s the result:

Watermarked document showing a unique email address.

You can find the complete source code for this example here: https://github.com/cfjedimaster/document-services-demos/blob/main/watermark/dynamic.js

If you want to give this API, and the many other features of Acrobat Services, sign up for your credentials and start using the free tier today. If you need help, reach out on our forums.



Source link