Hey there! Recently I got a chance to implement CAD format (DXF, DWG) support within Alfresco Share 5.0 so users could preview engineering documents. What’s an Alfresco previewer? The main concept lying behind it is to convert all variety of complex formats (doc, excel, txt, etc.) to a single one – PDF which is then can be rendered by Alfresco previewer. To handle word/excel/other conversion OpenOffice is used, to support DXF and DWG we need to find an appropriate CAD to PDF converter. To do this I will take a look at existing converters, evaluate them and show how to inject one of them to Alfresco to provide the preview of engineering drawings. This solution will work on Alfresco 5 (4th should also be fine) on Windows and Linux.
First of all I’d like to show Alfresco content preview lifecycle:
- Some content is uploaded, let’s say *.doc
- A user opens the file for the first time
- Alfresco reads its mime-type
- Using content mime-type Alfresco finds the appropriate converter config
- In this config there is a path to external software that performs doc to pdf conversion (LibreOffice path)
- Doc to pdf conversion takes place using LibreOffice
- Store generated pdf to content store and link it to document entity. After the generated pdf is stored, the conversion will not occur for the second time (when the user opens the file one more time).
- Alfresco previewer (that is a javascript component) is started that simply loads pdf rendition
A key moment we need to solve is to provide a CAD to PDF converter (step 6). Such converter is not shipped within Alfresco, only 3d party software exists which is proprietary in turn. There are 3 CAD to PDF market leaders were considered:
- Formtek software. If you type “DWG” under Alfresco add-ons page, you’ll find references to Formtek add-ons mostly. All found modules presented as free of charge, but eventually they all require Formtek EDM Module which in contrast is obligatory to pay. The price of this module is unknown, I’ve tried to communicate to the team of this project, but still waiting for reply.
- AcmeCADConverter tool (price 99 euro), Windows version only (its team suggests to use wine on Linux to run it). Current converter showed good results, but unfortunately not all dwg files could be converted: some huge files (more than 5Mb) gave blank pdf as a transformation result.
- It turned out that the best solution to solve CAD to PDF conversion is a QCAD library, during tests it could convert dwg files of any complexity (> 10Mb), it can be run on Windows and Linux and its price is just 39 euro.
To enable dwg to pdf conversion within Alfresco we need to add a Transformer to newly created bean context located on Alfresco application class path classpath:alfresco/extension/some-context.xml:
<beanid="transformer.dwg2pdf"
class="org.alfresco.repo.content.transform.ProxyContentTransformer"
parent="baseContentTransformer"><propertyname="worker"><refbean="transformer.worker.dwg2pdf" /></property></bean>
And a Worker to the same context file:
<beanid="transformer.worker.dwg2pdf" class="org.alfresco.repo.content.transform.RuntimeExecutableContentTransformerWorker"><propertyname="mimetypeService"><refbean="mimetypeService" /></property><propertyname="checkCommand"><beanname="transformer.dwg2pdf.checkCommand"class="org.alfresco.util.exec.RuntimeExec"><propertyname="commandsAndArguments"><map><entrykey="Linux.*"><list><value>sh</value><value>-c</value><value>${dwg2pdf.root}/dwg2pdf -h</value></list></entry><entrykey="Windows.*"><list><value>cmd</value><value>/C</value><value>cd ${dwg2pdf.root} && dwg2pdf -h</value></list></entry></map></property></bean></property><propertyname="transformCommand"><beanname="transformer.dwg2pdf.Command"class="org.alfresco.util.exec.RuntimeExec"><propertyname="commandsAndArguments"><map><entrykey="Linux.*"><list><value>sh</value><value>-c</value><value>${dwg2pdf.root}/dwg2pdf -f -a -o ${target} ${source}</value></list></entry><entrykey=".*"><list><value>cmd</value><value>/C</value><value>cd ${dwg2pdf.root} && dwg2pdf -f -a -o ${target} ${source}</value></list></entry></map></property><propertyname="waitForCompletion"><value>true</value></property></bean></property></bean>
A couple notes regarding Worker config:
- ${dwg2pdf.root} is taken from alfresco-global.properties, a snippet of this file is shown below
- ${target} ${source} values are injected automatically by Alfresco, when a file is opened and a conversion is triggered
- checkCommand is a command run on system start. If succeed then current Worker is enabled at a time of Alfresco usage
- transformerCommand is actually a command that triggered when a content conversion is requested. You can type here any parameters suitable for QCAD (or any other converter you use). For QCAD case: –f is force file overwrite, –a is to adjust page layout, –o is the output filename
DXF Worker and Transformer configuration looks similar to DWG config, the only should be changed is the bean ids transformer.dwg2pdf to transformer.dxf2pdf andtransformer.worker.dwg2pdf to transformer.worker.dxf2pdf.
The final thing we should do is to add developed transformers to alfresco-global.properties:
dwg2pdf.root=/opt/qcad content.transformer.dwg2pdf.priority=50 content.transformer.dwg2pdf.extensions.dwg.pdf.supported=true content.transformer.dwg2pdf.extensions.dwg.pdf.priority=50 content.transformer.dxf2pdf.priority=50 content.transformer.dxf2pdf.extensions.dxf.pdf.supported=true content.transformer.dxf2pdf.extensions.dxf.pdf.priority=50
A few notes regarding this:
- dwg2pdf.root is the path to QCAD (Linux version) that injected to developed spring context
- transformer.dwg2pdf is our transformer bean ids prefixed with a content keyword to refer to converters. Extensions keyword means that when a content with dwg or dxf mime-type is found, Alfresco will try to convert it to pdf.
That’s it, after Alfresco restart CAD preview should work. And here is a complete source code that incudes Ant script to build a jar which can be deployed on top of your Alfresco.
Kaynak: http://soft29.info/blog/entry/linux-postgresql-automated-backups-alfresco
Alfresco CAD (dxf, dwg) önizleme desteği