DWG Transformations

Document created by resplin Employee on Jun 6, 2015Last modified by alfresco-archivist on Aug 31, 2016
Version 2Show Document
  • View in full screen mode

Obsolete Pages{{Obsolete}}

The official documentation is at: http://docs.alfresco.com



{{Partner Info
| companyName=DENC Netherlands B.V.
| companyWebsite=http://www.denc.nl
| companyLogo=DENC.jpg
| companyDescription=Design, Engineering & Contracting
| contactEmail=info [at] denc.nl
}}


Introduction


Document management is important for architectural and logistical companies. These companies often have drawings in AutoCAD's DWG file format. This page will give instructions on setting up transformations from DWG to filetypes that can be used in Alfresco.


Requirements


This information is based on an Alfresco Community Edition 3.2r2 installation deployed on Tomcat 6 on Ubuntu 9.04 (Jaunty Jackalope). However, most of this should be applicable to other distributions, all Alfresco editions with version number 3.2 (and probably higher) and other means of deployment.

The transformations are based on some of the default transformers in Alfresco, the ImageMagick and pdf2swf transformers and the ability to convert DWG to PDF using an arbitrary command.


Setup


Below are the steps required to set up parts of the transformation. If setup of the component is already done you can safely skip to the next subsection.


Create configuration for ImageMagick and pdf2swf


Assuming you installed ImageMagick and pdf2swf using distribution tools both will exist in /usr/bin. There are 2 values that need to be changed for Alfresco to pick these up:
classpath:alfresco-global.properties



img.root=/usr
swf.exe=/usr/bin/pdf2swf

If ImageMagick can be found as /somepath/bin/convert then you only need to specify /somepath as img.root. For pdf2swf you have to specify the full path. Please note that there's a bug in pdf2swf versions from before SWFTools 0.9.0, so make sure you install at least version 0.9.0.


Install dwg2pdf transformer (Option 1)


At my company we have developed our own DWG to PDF transformer. We simply named it dwg2pdf and linked it statically, so we don't have to worry about library placement. A good place to put this executable would be /usr/local/bin because your distribution should leave this location alone, even during upgrades etc.. Thus the path to the transformer will be /usr/local/bin/dwg2pdf for the converter.

Of course you can use any converter that provides the same transformation and you can also use any location for that converter (especially on Windows I expect you've chosen another place), keep in mind that you will also need to change this in the bean configuration.


Install cad2svg and Apache Batik rasterizer (Option 2)


Cad2svg is a free tool to convert AutoCAD DWG drawings to SVG files. It doesn't support the latest AutoCAD versions nor does it do perfect transformations, but often it will be good enough for your basic flat drawings. Combined with a conversion to PDF this allows one to use the same transformations as otherwise could be used with a direct DWG to PDF transformation.

Apache's Batik Rasterizer will provide this SVG to PDF transformation resulting in vectorized PDF files, allowing unlimited (of course depending upon the viewer) zoom without quality loss. To use the Batik rasterizer I suggest downloading the zip and extracting the contents in /opt, resulting in a /opt/batik-1.7 folder for the current version of Batik.


Setup transformations


I put all my DWG transformation definitions in one file, because they all concern the same source mimetype. You might want to split it over multiple files, however for performance it's wise to avoid a huge library of files.
classpath:extension/dwg-transform-context.xml


<beans>

        <bean id='transformer.worker.dwg2pdf' class='org.alfresco.repo.content.transform.RuntimeExecutableContentTransformerWorker'>
                <property name='mimetypeService'>
                        <ref bean='mimetypeService' />
                </property>
                <property name='checkCommand'>
                        <bean class='org.alfresco.util.exec.RuntimeExec'>
                                <property name='commandsAndArguments'>
                                        <map>
                                                <entry key='.*'>
                                                        <list>
                                                                <value>ls</value>
                                                                <value>/usr/local/bin/dwg2pdf</value>
                                                        </list>
                                                </entry>
                                        </map>
                                </property>
                                <property name='errorCodes'>
                                        <value>2</value>
                                </property>
                        </bean>
                </property>

                <property name='transformCommand'>
                        <bean class='org.alfresco.util.exec.RuntimeExec'>
                                <property name='commandsAndArguments'>
                                        <map>
                                                <entry key='.*'>
                                                        <list>
                                                                <value>/usr/local/bin/dwg2pdf</value>
                                                                <value>${source}</value>
                                                                <value>${target}</value>
                                                        </list>
                                                </entry>
                                        </map>
                                </property>
                                <property name='errorCodes'>
                                        <value>1,2</value>
                                </property>
                        </bean>
                </property>

                <property name='explicitTransformations'>
                        <list>
                                <bean class='org.alfresco.repo.content.transform.ExplictTransformationDetails'>
                                        <property name='sourceMimetype'><value>image/x-dwg</value></property>
                                        <property name='targetMimetype'><value>application/pdf</value></property>
                                </bean>
                        </list>
                </property>
        </bean>

        <bean id='transformer.worker.dwg2svg' class='org.alfresco.repo.content.transform.RuntimeExecutableContentTransformerWorker'>
                <property name='mimetypeService'>
                        <ref bean='mimetypeService' />
                </property>
                <property name='checkCommand'>
                        <bean class='org.alfresco.util.exec.RuntimeExec'>
                                <property name='commandsAndArguments'>
                                        <map>
                                                <entry key='.*'>
                                                        <list>
                                                                <value>/usr/local/bin/cad2svg</value>
                                                                <value>--version</value>
                                                        </list>
                                                </entry>
                                        </map>
                                </property>
                                <property name='errorCodes'>
                                        <value>2</value>
                                </property>
                        </bean>
                </property>

                <property name='transformCommand'>
                        <bean class='org.alfresco.util.exec.RuntimeExec'>
                                <property name='commandsAndArguments'>
                                        <map>
                                                <entry key='.*'>
                                                        <list>
                                                                <value>/usr/local/bin/cad2svg</value>
                                                                <value>${source}</value>
                                                                <value>-o</value>
                                                                <value>${target}</value>
                                                        </list>
                                                </entry>
                                        </map>
                                </property>
                                <property name='errorCodes'>
                                        <value>1</value>
                                </property>
                        </bean>
                </property>

                <property name='explicitTransformations'>
                        <list>
                                <bean class='org.alfresco.repo.content.transform.ExplictTransformationDetails'>
                                        <property name='sourceMimetype'><value>image/x-dwg</value></property>
                                        <property name='targetMimetype'><value>image/svg+xml</value></property>
                                </bean>
                        </list>
                </property>
        </bean>

        <bean id='transformer.worker.svg2pdf' class='org.alfresco.repo.content.transform.RuntimeExecutableContentTransformerWorker'>
                <property name='mimetypeService'>
                        <ref bean='mimetypeService' />
                </property>
                <property name='checkCommand'>
                        <bean class='org.alfresco.util.exec.RuntimeExec'>
                                <property name='commandsAndArguments'>
                                        <map>
                                                <entry key='.*'>
                                                        <list>
                                                                <value>java</value>
                                                                <value>-jar</value>
                                                                <value>/opt/batik-1.7/batik-rasterizer.jar</value>
                                                        </list>
                                                </entry>
                                        </map>
                                </property>
                        </bean>
                </property>

                <property name='transformCommand'>
                        <bean class='org.alfresco.util.exec.RuntimeExec'>
                                <property name='commandsAndArguments'>
                                        <map>
                                                <entry key='.*'>
                                                        <list>
                                                                <value>java</value>
                                                                <value>-jar</value>
                                                                <value>/opt/batik-1.7/batik-rasterizer.jar</value>
                                                                <value>-m</value>
                                                                <value>application/pdf</value>
                                                                <value>-d</value>
                                                                <value>${target}</value>
                                                                <value>${source}</value>
                                                        </list>
                                                </entry>
                                        </map>
                                </property>
                        </bean>
                </property>

                <property name='explicitTransformations'>
                        <list>
                                <bean class='org.alfresco.repo.content.transform.ExplictTransformationDetails'>
                                        <property name='sourceMimetype'><value>image/svg+xml</value></property>
                                        <property name='targetMimetype'><value>application/pdf</value></property>
                                </bean>
                        </list>
                </property>
        </bean>

        <bean id='transformer.worker.svg2png' class='org.alfresco.repo.content.transform.RuntimeExecutableContentTransformerWorker'>
                <property name='mimetypeService'>
                        <ref bean='mimetypeService' />
                </property>
                <property name='checkCommand'>
                        <bean class='org.alfresco.util.exec.RuntimeExec'>
                                <property name='commandsAndArguments'>
                                        <map>
                                                <entry key='.*'>
                                                        <list>
                                                                <value>java</value>
                                                                <value>-jar</value>
                                                                <value>/opt/batik-1.7/batik-rasterizer.jar</value>
                                                        </list>
                                                </entry>
                                        </map>
                                </property>
                        </bean>
                </property>

                <property name='transformCommand'>
                        <bean class='org.alfresco.util.exec.RuntimeExec'>
                                <property name='commandsAndArguments'>
                                        <map>
                                                <entry key='.*'>
                                                        <list>
                                                                <value>java</value>
                                                                <value>-jar</value>
                                                                <value>/opt/batik-1.7/batik-rasterizer.jar</value>
                                                                <value>-m</value>
                                                                <value>image/png</value>
                                                                <value>-d</value>
                                                                <value>${target}</value>
                                                                <value>${source}</value>
                                                        </list>
                                                </entry>
                                        </map>
                                </property>
                        </bean>
                </property>

                <property name='explicitTransformations'>
                        <list>
                                <bean class='org.alfresco.repo.content.transform.ExplictTransformationDetails'>
                                        <property name='sourceMimetype'><value>image/svg+xml</value></property>
                                        <property name='targetMimetype'><value>image/png</value></property>
                                </bean>
                        </list>
                </property>
        </bean>

        <bean id='transformer.dwg2pdf' class='org.alfresco.repo.content.transform.ProxyContentTransformer' parent='baseContentTransformer'>
                <property name='worker'>
                        <ref bean='transformer.worker.dwg2pdf' />
                </property>
        </bean>

        <bean id='transformer.dwg2svg' class='org.alfresco.repo.content.transform.ProxyContentTransformer' parent='baseContentTransformer'>
                <property name='worker'>
                        <ref bean='transformer.worker.dwg2svg' />
                </property>
        </bean>

        <bean id='transformer.svg2pdf' class='org.alfresco.repo.content.transform.ProxyContentTransformer' parent='baseContentTransformer'>
                <property name='worker'>
                        <ref bean='transformer.worker.svg2pdf' />
                </property>
        </bean>

        <bean id='transformer.svg2png' class='org.alfresco.repo.content.transform.ProxyContentTransformer' parent='baseContentTransformer'>
                <property name='worker'>
                        <ref bean='transformer.worker.svg2png' />
                </property>
        </bean>

        <bean id='transformer.complex.dwg2png' class='org.alfresco.repo.content.transform.ComplexContentTransformer' parent='baseContentTransformer'>
                <property name='transformers'>
                        <list>
                                <ref bean='transformer.dwg2pdf' />
                                <ref bean='transformer.complex.PDF.Image' />
                        </list>
                </property>
                <property name='intermediateMimetypes'>
                        <list>
                                <value>application/pdf</value>
                        </list>
                </property>
        </bean>

        <bean id='transformer.complex.dwg2swf' class='org.alfresco.repo.content.transform.ComplexContentTransformer' parent='baseContentTransformer'>
                <property name='transformers'>
                        <list>
                                <ref bean='transformer.dwg2pdf' />
                                <ref bean='transformer.Pdf2swf' />
                        </list>
                </property>
                <property name='intermediateMimetypes'>
                        <list>
                                <value>application/pdf</value>
                        </list>
                </property>
        </bean>

        <bean id='transformer.complex.svg2image' class='org.alfresco.repo.content.transform.ComplexContentTransformer' parent='baseContentTransformer'>
                <property name='explicitTransformations'>
                        <list>
                                <bean class='org.alfresco.repo.content.transform.ExplictTransformationDetails'>
                                        <property name='sourceMimetype'><value>image/svg+xml</value></property>
                                        <property name='targetMimetype'><value>image/jpeg</value></property>
                                </bean>
                                <bean class='org.alfresco.repo.content.transform.ExplictTransformationDetails'>
                                        <property name='sourceMimetype'><value>image/svg+xml</value></property>
                                        <property name='targetMimetype'><value>image/png</value></property>
                                </bean>
                                <bean class='org.alfresco.repo.content.transform.ExplictTransformationDetails'>
                                        <property name='sourceMimetype'><value>image/svg+xml</value></property>
                                        <property name='targetMimetype'><value>image/gif</value></property>
                                </bean>
                        </list>
                </property>
                <property name='transformers'>
                        <list>
                                <ref bean='transformer.svg2png' />
                                <ref bean='transformer.ImageMagick' />
                        </list>
                </property>
                <property name='intermediateMimetypes'>
                        <list>
                                <value>image/png</value>
                        </list>
                </property>
        </bean>

        <bean id='transformer.complex.dwg2svg2png2image' class='org.alfresco.repo.content.transform.ComplexContentTransformer' parent='baseContentTransformer'>
                <property name='transformers'>
                        <list>
                                <ref bean='transformer.dwg2svg' />
                                <ref bean='transformer.complex.svg2image' />
                        </list>
                </property>
                <property name='intermediateMimetypes'>
                        <list>
                                <value>image/xvg+xml</value>
                        </list>
                </property>
        </bean>

        <bean id='transformer.complex.dwg2svg2pdf2swf' class='org.alfresco.repo.content.transform.ComplexContentTransformer' parent='baseContentTransformer'>
                <property name='transformers'>
                        <list>
                                <ref bean='transformer.dwg2svg' />
                                <ref bean='transformer.svg2pdf' />
                                <ref bean='transformer.Pdf2swf' />
                        </list>
                </property>
                <property name='intermediateMimetypes'>
                        <list>
                                <value>image/svg+xml</value>
                                <value>application/pdf</value>
                        </list>
                </property>
        </bean>

</beans>

This configuration supports both the use of a converter from DWG to PDF as well as cad2svg to convert from DWG to SVG. It also uses Batik to provide a SVG to PNG converter so that the ImageMagick transformer can be used to generate thumbnails and more.


Issues


Currently I've found only one issue: vectorized PDF's can't always be converted to SWF. In SWFTools there's a limit on the amount of vertices drawn or something similar, so for drawings with lots of elements the transformation will fail and the preview won't be available.

Also, the SWF files can become quite resource intensive for end users. When the SWF files get loaded in linux the browser locks up until Flash is done loading, which can be up to a few seconds.


Conclusion


Using the instructions on this page you should be able to setup conversion from DWG files to other file formats so you will have previews and thumbnails in Alfresco Share. Depending on the way your PDF is generated you might even be able to view different workspaces or viewports using the SWF preview.
Content Transformation
Customizing and Extending

1 person found this helpful

Attachments

Outcomes