da-qr-watermark
v1.0.1
Published
An example of using the DocumentAlchemy API to generate a QR code and then stamp it on each page of a PDF as a watermark image.
Downloads
1
Maintainers
Readme
Watermarking a PDF document with a QR code
In this example we will follow a two-step process to first create (and store) an image of a QR code and then use that image to watermark a PDF document.
This example demonstrates several features of the Document Alchemy API:
How to create a QR code image.
How to create a document directly within the Document Alchemy file-store.
How to use a stored document within another API call.
How to watermark a PDF document (using a stored image and an uploaded PDF file).
How to delete a file from the Document Alchemy file-store.
Installing
(These instructions assume you've already installed a modern version of Node.js/IO.js. If you haven't yet, see https://nodejs.org/ for details.)
To simplify the task, this example uses the popular request module (on GitHub at request/request).
To install the module, simply run:
npm install
from within this directory (the one containing package.json
and this README
file). This will download and install all of the necessary third-party
libraries.
Running
To run this example, you will need:
A DocumentAlchemy API key. If you don't have one yet, you can obtain one immediately by signing up for DocumentAlchemy.
A PDF document to watermark.
The general format for running this program is this:
node qr-watermark.js <API-KEY> <TEXT-TO-ENCODE> <PDF-TO-WATERMARK> [<OUTPUT-FILE-NAME>]
For example, if your API key value is HbblCNv7gLN2pasWFK44
, the command:
node qr-watermark.js HbblCNv7gLN2pasWFK44 "http://www.example.com/" myDocument.pdf watermarkedDocument.pdf
will create (or overwrite) the file watermarkedDocument.pdf
, containing a copy
of myDocument.pdf
with a QR code (pointing to www.example.com) stamped on
every page.
The output of the program may look something like this:
Creating the QR code...
...Success! Created and stored QR code as document ID "8cxwka1gbjoflxrqi2ux2z2".
Watermarking the PDF document using that stored image...
...Success! Watermarked PDF document saved at "watermarkedDocument.pdf".
Deleting the QR code...
...Success! Stored document deleted from the server.
(Note that qr-watermark.js
is also directly executable via:
qr-watermark.js <API-KEY> <TEXT-TO-ENCODE> <PDF-TO-WATERMARK> [<OUTPUT-FILE-NAME>]
if your shell recognizes the #!/usr/bin/env node
hash-bang identifier.)
How it works
Please review the code and comments found in qr-watermark.js
for a detailed
explanation of the process.