AnsweredAssumed Answered

PS To PDF Transformation using Ghostview Alfresco 2.0

Question asked by peterdavidson on Mar 20, 2007
Latest reply on Apr 25, 2008 by birgir
Here is an example of how to transform postscript files to pdf using ghostview in alfresco 2.0.  (I only tested this on Windows XP, but would guess it works the same.)

In my custom-transformers-context.xml, I added the following bean definition. 

   <bean id="transformer.GhostScript.PS2PDF" class="org.alfresco.repo.content.transform.RuntimeExecutableContentTransformer" parent="baseContentTransformer">
      <property name="checkCommand">
         <bean class="org.alfresco.util.exec.RuntimeExec">
            <property name="commandMap">
                <map>
                    <entry key="Linux">
                        <value>ps2pdf</value>
                    </entry>
                    <entry key="Windows.*">
                        <value>cmd /C ps2pdf</value>
                    </entry>
                </map>
            </property>
            <property name="errorCodes">
               <value>1</value>
            </property>
         </bean>
      </property>
      <property name="transformCommand">
         <bean class="org.alfresco.util.exec.RuntimeExec">
            <property name="commandMap">
                <map>
                    <entry key="Linux">
                        <value>ps2pdf '${source}' '${target}'</value>
                    </entry>
                    <entry key="Windows.*">
                        <value>cmd /C ps2pdf "${source}" "${target}"</value>
                    </entry>
                </map>
            </property>
            <property name="errorCodes">
               <value>1</value>
            </property>
         </bean>
      </property>
      <property name="explicitTransformations">
         <list>
            <bean class="org.alfresco.repo.content.transform.ContentTransformerRegistry$TransformationKey" >
                <constructor-arg><value>application/postscript</value></constructor-arg>
                <constructor-arg><value>application/pdf</value></constructor-arg>
            </bean>
         </list>
      </property>
   </bean>   

Here are some things that I had to do to get the transformation working:

I included the following directories on the PATH:

<ghostview_install_path>/lib – this has the script
<ghostview_install_path>/bin – this has the actual binary file


Here are some assumptions that were made about ghostview, that hold true on windows (I'm not sure of how linux will work):

It returns an error code of 1 when it fails
It accepts the files in the order <source> <target>

Hope this helps someone.

Pete

Outcomes