cancel
Showing results for 
Search instead for 
Did you mean: 

Autocad (dwg) to pdf transformation

konsultex
Confirmed Champ
Confirmed Champ
I need to transform dwg files to pdf for read access by a group pf users in another space. I know that this is not something Alfresco does out of the box but I wonder if anyone has a suggestions. I imagine that there is some tool that can be called from the command line to do this. This leads to another question related to this problem. Since Alfresco uses OpenOffice to convert documents, I assume that I can configure dwg conversions to usat other program. Is this possible and where do I configure these things?
27 REPLIES 27

fast3r
Champ on-the-rise
Champ on-the-rise
Hi,
I'm fighting with transformations and thumbnails and I'm going crazy.
I don't know if it's the correct board, but it's related to this topic.

I want to add the web preview in Alfresco Share for DWG (AutoCAD) files.
I correctly configured the transformation for the image thumbnails for the documents list, but I'm not able to see the flash web preview!
I have created a complex transformation: DWG -> PDF -> SWF. The single conversions work, but when I access the web preview page the ComplexContentTransformer is called but not used, because I cannot see any swf file nor pdf file in the tomcat temp folder.
I think that's because DWG's mimetype is "image/x-dwg", that's recognized by ImageMagick, and it tries to open it.
I don't know if I have to set something in the Alfresco Thumbnail system for activating the preview for a new mime type.

Please help me, I'm stuck!

fast3r
Champ on-the-rise
Champ on-the-rise
I answer myself.
To enable previews of image types not supported by ImageMagick and SwfPreviewer, you need to modify the file tomcat\webapps\share\components\preview\web-preview.js

on line 279 (in Alfresco 3.0):

if (this.options.mimeType.match(/^image\/\w+/))

to

if (this.options.mimeType.match(/^image\/\w+/) && !this.options.mimeType.match(/image\/x-dwg/))

Eventually specifying each type of image you want to be converted to swf before previewing.

Hope this is helpful.

morze
Champ in-the-making
Champ in-the-making
fast3r
Please, tell me more in detail how you have created a complex transformation DWG -> PDF -> SWF.
Тhank you!

fast3r
Champ on-the-rise
Champ on-the-rise
I'll write down a small tutorial as soon as I can!

morze
Champ in-the-making
Champ in-the-making
With hope we will wait…
Thanks!

fast3r
Champ on-the-rise
Champ on-the-rise
Here I am, hope it's useful.

To implement DWG file web previews, you need two conversions: DWG -> PDF -> SWF:

The first conversion is made (in a Windows environment) with IrfanView (http://www.irfanview.com/), a free utility, to install with two plugins named InPDF.dll and CS_DWG.dll (this one costs about 9 dollars for each user). You can install IrfanView under Alfresco/bin for simplifying.
To convert from PDF to SWF we use the default command line utility used by Alfresco, Pdf2Swf.


You can add these lines to the alfresco debugger config file in case of troubles (tomcat\webapps\alfresco\WEB-INF\classes\log4j.properties😞

log4j.logger.org.alfresco.util.exec.RuntimeExec=DEBUG
log4j.logger.org.alfresco.repo.content.transform.ContentTransformerRegistry=DEBUG
log4j.logger.org.alfresco.repo.content.transform.AbstractContentTransformer2=DEBUG
log4j.logger.org.alfresco.repo.thumbnail.ThumbnailServiceImpl=DEBUG


The trasformation definition can be made in tomcat/shared/classes/alfresco/extension/transformers-custom-context.xml file

The file content will be the following:

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>

<beans>

<!– TRASFORMA DWG IN PDF   –>
<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>C:\Alfresco\bin\IrfanView\i_view32.exe</value>
                <value>C:\Alfresco\bin\IrfanView\jtp.gif</value>
                <value>/convert=C:\Alfresco\bin\IrfanView\jtp.png</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>C:\Alfresco\bin\IrfanView\i_view32.exe</value>
                <value>${source}</value>
                <value>/convert=${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.dwg2pdf" class="org.alfresco.repo.content.transform.ProxyContentTransformer" parent="baseContentTransformer">
        <property name="worker">
            <ref bean="transformer.worker.dwg2pdf" />
        </property>
    </bean>



<!– TRASFORMA DWG IN PNG (miniature) –>
    <bean id="transformer.complex.dwg2pdf.Image"
        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>



<!–      TRASFORMA DWG IN SWF (complex)    –>
    <bean id="transformer.complex.dwg2pdf.Pdf2swf"
        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>
      <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/x-shockwave-flash</value></property>
            </bean>
         </list>
      </property>   
   </bean>
          
</beans>


AutoCAD file mimetype is "image/x-dwg".
To avoid dwg files being treated as image types (causing a failure of WebPreviewer.swf), you need to modify the file tomcat\webapps\share\components\preview\web-preview.js

on line 279 (in Alfresco 3.0) you need to change:

if (this.options.mimeType.match(/^image\/\w+/))

with

if (this.options.mimeType.match(/^image\/\w+/) && !this.options.mimeType.match(/image\/x-dwg/))

This should be done for each "image/*" file format that ImageMagick can't read.

The same procedure can be followed for each custom file type that you want to be previewed by Share.



I apologize if I've made something that's not perfectly in line with the Alfresco specifications. BTW, it works!

morze
Champ in-the-making
Champ in-the-making
Thanks huge!
I will try, only at me - debian… I will try under wine to use

mycroes
Champ in-the-making
Champ in-the-making
Nice to see that my example is already used! (I added it to the wiki).

AutoCAD file mimetype is "image/x-dwg".
To avoid dwg files being treated as image types (causing a failure of WebPreviewer.swf), you need to modify the file tomcat\webapps\share\components\preview\web-preview.js

on line 279 (in Alfresco 3.0) you need to change:

if (this.options.mimeType.match(/^image\/\w+/))

with

if (this.options.mimeType.match(/^image\/\w+/) && !this.options.mimeType.match(/image\/x-dwg/))

This should be done for each "image/*" file format that ImageMagick can't read.

The same procedure can be followed for each custom file type that you want to be previewed by Share.



I apologize if I've made something that's not perfectly in line with the Alfresco specifications. BTW, it works!

I didn't do this, and it works as expected. I don't know what causes this inconvenience for you, but when there's a converter to SWF available I don't think you need to change it… Anyway, I also made a converter that uses the same approach as the DWG to SWF converter as outlined on the wiki, but converting to thumbnail in last step, so I also have thumbnails generated from the DWGs.

Also, if you want to offer your PDF files to customers or anything I'd suggest using a converter that generates vector PDF files. One way of doing this is by chaining cad2svg (http://etc.nkadesign.com/Download/Cad2svg) and the Apache Batik Rasterizer (http://xmlgraphics.apache.org/batik/).
Regards,

Michael

fast3r
Champ on-the-rise
Champ on-the-rise
Nice to see that my example is already used! (I added it to the wiki).

Which example? I can't find it!

AutoCAD file mimetype is "image/x-dwg".
To avoid dwg files being treated as image types (causing a failure of WebPreviewer.swf), you need to modify the file tomcat\webapps\share\components\preview\web-preview.js

I didn't do this, and it works as expected. I don't know what causes this inconvenience for you, but when there's a converter to SWF available I don't think you need to change it… Anyway, I also made a converter that uses the same approach as the DWG to SWF converter as outlined on the wiki, but converting to thumbnail in last step, so I also have thumbnails generated from the DWGs.

I don't know why, that could be because I'm still using Alfresco 3.0 Stable, without this modification, the preview couldn't be displayed. BTW, good for you!
I skipped the code for DWG thumbnails in the "tutorial", but you're right, it's very simple and could be useful.

Also, if you want to offer your PDF files to customers or anything I'd suggest using a converter that generates vector PDF files. One way of doing this is by chaining cad2svg (http://etc.nkadesign.com/Download/Cad2svg) and the Apache Batik Rasterizer (http://xmlgraphics.apache.org/batik/).

Great! Thank you very much, I did not find any DWG converter in Linux, that's why I was using Windows apps…

mycroes
Champ in-the-making
Champ in-the-making
Nice to see that my example is already used! (I added it to the wiki).

Which example? I can't find it!
This one: http://wiki.alfresco.com/wiki/Content_Transformations#RuntimeExecutableContentTransformerWorker_.28A.... I was under the impression you used that as base for the latest transformer you posted.

I don't know why, that could be because I'm still using Alfresco 3.0 Stable, without this modification, the preview couldn't be displayed. BTW, good for you!
I'm on Community Edition 3.2r2, might be the difference.

Great! Thank you very much, I did not find any DWG converter in Linux, that's why I was using Windows apps…
Depending on the type of business you are in (or your company is in) it might be worth the money to join the OpenDesign alliance (http://www.opendwg.org/), they offer a library which you can use to read DWG files and included is also a PDF export library (including partial source). Cad2Svg is based on an older version of the same library, meanwhile compatibility between the library and AutoCAD DWG files has improved a bit, so if you have any DWG files that you can't convert well with cad2svg this could be very appealing.
Regards,

Michael