Blogroll

The New Domino Admin

A great source of information for Lotus Domino administrators

ecmarchitect.com

Jeff Potts' excellent ECM/Portal blog

Jared Ottley

Lots of very useful Alfresco articles

Looking for web hosting?  I have been using DreamHost for years and have found them to be reliable, inexpensive and very good at what they do!  Click below to sign up, use promo code 'unorganized' to get a free domain registration and 10 bucks off your first year of hosting!

 

dreamhostBadge

Home Software and Tech Software Development Watermarking PDF Documents with Alfresco
Watermarking PDF Documents with Alfresco PDF Print E-mail
Written by Nathan McMinn   
Monday, 06 September 2010 15:31

Like a lot of Alfresco users, I spend a lot of time dealing with PDF documents.  Invoices, purchase orders, product specifications, documentation and signed authorizations all flow through our Alfresco system as PDFs.  Recently I had a need to watermark a subset of these documents, marking them as "official" or "draft" releases.  A bit of poking around revealed that there wasn't an open-source, free way to apply simple watermarks to PDF documents in Alfresco.  Generis has a solution, but it is a commercial package and provides a lot more functionality than I really need.  So, what to do?  Extend Alfresco, of course!

 

Alfresco allows developers to create custom actions that can manipulate nodes in the repository.  These actions can then be triggered via a content rule, perfect for my needs.  It's pretty simple:  a document is added to a space, the content rule is triggered and calls an action that can modify the new document.  While I was looking around for PDF tools for Alfresco, I came across Jared Ottley's blog, and specifically his Alfresco PDF Toolkit project.  I love to learn by example, and Jared's code was a nice, concise introduction to how custom actions work.  With a few days of coding, I was able to add a PDF watermarking action to his existing project.  The code has been added to the alfresco-pdf-toolkit project on Google Code.  It supports the following features:

 

  • Selection of a watermark image and marked PDF destination
  • Choice of watermark location:  top left, top right, bottom left, bottom right or centered
  • Choice of watermark pages:  first, last, even, odd or all
  • Choice of watermark depth:  above or below the PDF content.

 

You can either build the package from source or download the AMP file here.  For those that don't know, AMPs are one of the ways that extensions to Alfresco can be packaged.  AMPs are deployed using the Alfresco Module Management Tool.  Once you have installed the AMP and restarted Alfresco, you will find a few new actions available.  To try out the watermarking action, start by creating a space for inbound PDF documents and create a new content rule for the space.  Since this action will only work with PDF documents, set the condition to "Content of mimetype", as shown below: 

 

create_rule_step_1

 

Select "Adobe PDF Document" from the mimetype list to ensure that this rule is only triggered when a PDF is added.

 

create_rule_step_2

 

After you have set the mimetype and clicked "Next", select the "Watermark PDF" action from the list.  Click "Set Values and Add" to configure the PDF watermarking action:

 

create_rule_step_3

 

The PDF Watermark action requries 5 parameters.  The first, the watermark image, is the image that you wish to have applied to your PDF.  Most common image formats are supported.  The second parameter is the destination.  This is the space into which the watermarked PDF will be placed.  The watermarked PDF will have the same name as the original, so it probably isn't a good idea to put it back into the same space.  Finally, you can select the pages to watermark, the position of the watermark, and whether the mark will be applied above or below the existing PDF content (similar to a CSS z-index).

 

create_rule_step_4

 

Once the parameters are set, click OK to save.  Finish up the "Add Content Rule" wizard and you are all set.  Any PDF documents put into the space will now be watermarked and copied to the destination space you specified.

 

Additional feature requests are welcome, enjoy!

Last Updated on Tuesday, 07 September 2010 13:37
 

Comments  

 
#9 2011-10-02 05:55
Quoting Joters:
Hi i install amp:

...

No error log.

No "Watermark PDF" action

Alfresco 3.4d
Thank you for your help.

joters


Hi,

I experienced the same problem, but I can get rid of this problem by using another method.

Here is the solution:
1) Copy the source code from alfresco-pdf-toolkit link above.
2) Copy iText-5.0.4.jar into 'alf-home\tomcat\web apps\alfresco\W EB-INF\lib'
3) Copy files in 'web\jsp\actions ' into 'alf-home\tomcat\web apps\alfresco\j sp\actions'
4) Compile java source code inside folder src into a jar file then copy it 'into alf-home\tomcat\web apps\alfresco\W EB-INF\lib'
5) Copy files and folders in 'config\alfresco \module' into 'alf-home\tomcat\web apps\alfresco\W EB-INF\classes\alf resco\module'
 
 
#8 2011-08-28 09:33
I have successfully installed the module as per instructions, however i get this error:

org.apache.jasper.JasperException : Unable to compile class for JSP:

An error occurred at line: 6 in the generated java file
Only a type can be imported. javax.faces.context.FacesContext resolves to a package

An error occurred at line: 7 in the generated java file
Only a type can be imported. javax.transaction.UserTransaction resolves to a package
...
 
 
#7 2011-08-17 23:07
Quote:
Hi Gigi,

If you don't see a "Watermark PDF" action, then the PDF toolkit is probably not installed. Did you get any errors when you applied the AMP? Can you check your patched Alfresco instance and see if any of the classes from the PDF Toolkit (such as PDFWatermarkAct ionExecuter) are present?


Hi i install amp:

Module 'org.alfresco.extension.pdftoolkit' installed in 'c:\Alfresco\tom
pps\alfresco.war'
- Title: Alfresco PDF Toolkit
- Version: 0.96
- Install Date: Wed Aug 17 23:40:53 CLT 2011
- Desription: This module adds functionality to manipulate PDFs

No error log.

No "Watermark PDF" action

Alfresco 3.4d
Thank you for your help.

joters
 
 
#6 2010-12-03 02:29
Hi Nathan,

thank you for your reply!
No I could not find the class deployed. I checked the alfresco.log and I found following error message:

ERROR [org.springframework .web.context.ContextLoader] Context initialization failed
org.alfresco.error.AlfrescoRuntime Exception: 10300000 Workflow deployment failed

Could that have something to do with it?
Thanks a lot!

Gigi
 
 
#5 2010-12-02 12:30
Hi Gigi,

If you don't see a "Watermark PDF" action, then the PDF toolkit is probably not installed. Did you get any errors when you applied the AMP? Can you check your patched Alfresco instance and see if any of the classes from the PDF Toolkit (such as PDFWatermarkAct ionExecuter) are present?
 
 
#4 2010-11-30 07:03
Hi Nathan,

thank you for your solution. I wanted to try it out and installed your AMP withe the Module Management Tool and when I use the list function I can se it has been installed successfully. But when I am creating a new rule - there is no "Watermark PDF" Action available.

What might be the problem here?

Thank you for your help.
Gigi
 
 
#3 2010-10-01 07:19
Thanks for the mention of us, your solution looks pretty good!
 
 
#2 2010-09-30 01:21
Hey Bob, glad you found it useful!

I have a raft of new feature requests coming in, and yours will definitely be on the list. The font features are coming soon.

For the rest, I plan on making the PDF text field Freemarker-friendly (or just allow the selection of a template in the repository). That should allow the inclusion of all the document metadata and provide a few other nice features.
 
 
#1 2010-09-29 12:12
Great job on the PDF watermarking. Thanks!

A few feature requests for all your free time (yeah, right... :)
1) Allow other metadata information like version, path (both full and relative to a site document library), decsription, etc.
2) Allow custom metadata.
3) Allow different date formats (including time).
4) Allow smaller fonts (down to 6 pt).
5) Allow bold or italic.
6) Allow regexp strings/replacement.
7) Develop some mechanism to left justify part of a text watermark and right justify the other part.

Thanks again for some nice software.

Bob
 
RSS Feed Icon

About Me

 

My profile picture

 

My name is Nathan McMinn.  I'm a software engineer, beer geek, wannabe adventurer and genuinely curious guy.  Find me on Facebook, Linkedin or Twitter

Latest Comments