Alfresco PDF Generation from Word Document

As we had discussed in one of my previous article regarding alfresco media-previewer that alfresco use third party tool for content manipulation in backend. We can generate pdf files from word document.

Now there are requirements when user wants to keep pdf copy of any word content For instance invoices normally we create invoice in word document and then send pdf copy of final version of invoice to client for payment.

Way to achieve it?

We can create pdf document from word using available rule which invoke that transformation action based on content update or content create event. Now here we may be updating word version of invoice multiple times before finalizing it so that mean we have to create rule on content update.

Problem with content update rule.

Issue with that approach is that it first time create content successfully but later on whenever you update content it will fail because pdf file with same name already exist on destination.

How to solve?

To deal with this problem we need to create simple script which invoke content transformation action and before generating pdf it search for existing pdf file if exist it delete it and create new one.

Here is that script.

var parentnode=document.parent;
var name=parentnode.name;
var newpdfname=name+".pdf";

var existingpdf= parentnode.childByNamePath(newpdfname);
if(existingpdf!=null)
{
parentnode.removeNode(existingpdf) ;
parentnode.save();
}
var trans1 = document.transformDocument("application/pdf");
trans1.save();

Summary: As I always mention script is very powerful tool within alfresco which can help you to deal with many such issues. Happy coding!

Looking for quality Alfresco Web Hosting? Look no further than Arvixe Web Hosting!

Tags: , , , , , , , , , , , , , , | Posted under Alfresco | RSS 2.0

Author Spotlight

mitpatoliya

mitpatoliya

I love opensource technologies working with those technologies from the time I have stepped in to the Software Industry. Alfresco CMS is my area of expertise. I have worked on various complex implementations which involved integration of Alfresco with other technologies, extensively worked with JBPM workflows and Webscripts.

Leave a Reply

Your email address will not be published. Required fields are marked *


7 − 4 =

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>