Blog Post

...

Alfresco CAD (dxf, dwg) preview support

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:

  1. Some content is uploaded, let’s say *.doc
  2. A user opens the file for the first time
  3. Alfresco reads its mime-type
  4. Using content mime-type Alfresco finds the appropriate converter config
  5. In this config there is a path to external software that performs doc to pdf conversion (LibreOffice path)
  6. Doc to pdf conversion takes place using LibreOffice
  7. 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).
  8. 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:

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

And a Worker to the same context file:

<bean id="transformer.worker.dwg2pdf"
    class="org.alfresco.repo.content.transform.RuntimeExecutableContentTransformerWorker">
    <property name="mimetypeService">
        <ref bean="mimetypeService" />
    </property>
    <property name="checkCommand">
        <bean name="transformer.dwg2pdf.checkCommand" class="org.alfresco.util.exec.RuntimeExec">
            <property name="commandsAndArguments">
                <map>
                    <entry key="Linux.*">
                        <list>
                            <value>sh</value>
                            <value>-c</value>                           
                            <value>${dwg2pdf.root}/dwg2pdf -h</value>
                        </list> 
                    </entry>                
                    <entry key="Windows.*">
                        <list>
                            <value>cmd</value> 
                            <value>/C</value>                           
                            <value>cd ${dwg2pdf.root} &amp;&amp; dwg2pdf -h</value>
                        </list>
                    </entry>
                </map>
            </property>
        </bean>
    </property>
    <property name="transformCommand">
        <bean name="transformer.dwg2pdf.Command" class="org.alfresco.util.exec.RuntimeExec">
            <property name="commandsAndArguments">
                <map>
                    <entry key="Linux.*">
                        <list>
                            <value>sh</value>
                            <value>-c</value>
                            <value>${dwg2pdf.root}/dwg2pdf -f -a -o ${target} ${source}</value>
                        </list> 
                    </entry>                        
                    <entry key=".*">
                        <list>
                            <value>cmd</value> 
                            <value>/C</value>                           
                            <value>cd ${dwg2pdf.root} &amp;&amp; dwg2pdf -f -a -o ${target} ${source}</value>
                        </list>
                    </entry>
                </map>
            </property>
            <property name="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 and transformer.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.

Comments (10)

Tags: alfresco


Comments:

...

gaos Apr 15, 2017 at 03:19 #

Explanation Thank you. Does qcad work with the alfresco community version? Do you know how to install it?

...

gaos Apr 15, 2017 at 03:24 #

What version should I purchase if I purchase qcad?

...

gaos Apr 15, 2017 at 03:26 #

Classpath: alfresco / extension / some-context.xml: Can you tell where the file is located? I can not find any.

...

Stan Apr 26, 2017 at 09:04 #

Hi Gaos, thanks. QCAD works fine with the Alfresco community version. You can pick any version of QCAD, e.g. the latest one. some-context.xml - is the file that you should create. Greets.

...

gaos Apr 30, 2017 at 16:39 #

I am using version 5.2 / Opt / alfresco / tomcat / shared / classes / alfresco / extension There is some-context.xml.bak file in the above path. The content is consistent with your article so I changed it to some-contest.xml and used it I can not log in to my site. My password is wrong. What is the problem? thank you~~

...

gaos Apr 30, 2017 at 16:58 #

And I get an error compiling Apache ant build.xml. Can I get more information to generate ..jar? thank you.

...

Stan May 06, 2017 at 11:51 #

Gaos, which Ant error are you getting? This And script is really simple, it zips a couple files and copies the jar-archive to your app server. Probably you misconfigured your Ant.

...

gaos May 08, 2017 at 07:02 #

Error message... I ran ant on the / opt / alfresco directory and the following error message was displayed clean: [delete] Deleting directory /opt/alfresco/build [mkdir] Created dir: /opt/alfresco/build build: BUILD FAILED /opt/alfresco/build.xml:15: /opt/alfresco/src does not exist. Total time: 0 seconds And where is the .gitignore file created? Where is the file? thank you~~^^;

...

Tushar Khanka Aug 08, 2017 at 13:21 #

QCAD takes quite a long time to open the pdf in alfresco. is there any better solution to that ?

...

Stan Aug 14, 2017 at 10:51 #

Hi Tushar, QCAD trial version adds extra 15 sec to each conversion. You can purchase a commercial version if you need a faster conversion.

Leave a Comment