AnsweredAssumed Answered

Custom action for create PDF

Question asked by sebbri on Jul 12, 2016
Latest reply on Jul 13, 2016 by sebbri
I want to create an action to allow the user to create a PDF document from another document ( eg DOCX ).

I took a sample found on this forum :

Step 1 : I created un custom action custom-action-services-context.xml

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>
      <bean id="transform-to-pdf-action" parent="script">
                <property name="scriptLocation">
                        <bean class="org.alfresco.repo.jscript.ClasspathScriptLocation">
                                <constructor-arg>
                                        <value>alfresco/extension/scripts/transformToPdf.js</value>
                                </constructor-arg>
                        </bean>
                </property>
    </bean>
</beans>


Step 2 : the JS script (transformToPdf.js) :
This script created a PDF document with a property containing the name of the original document and version.

var name = document.properties["cm:name"];
var version = document.properties["cm:versionLabel"];
newdoc = document.transformDocument("application/pdf");
newdoc.properties["gen:Version"] = name + " ("+ version +")";
newdoc.save();


Step 3 : share-config-custom.xml :

<config evaluator="string-compare" condition="DocLibActions">
        <actions>
                <!– Transfor Document To PDF –>
                <action id="transform-to-pdf" type="javascript" label="Transformer en PDF">
                        <param name="function">onActionFormDialog</param>
                        <!– Additional parameters for onFormDialog function  –>
                        <param name="itemKind">action</param>
                        <param name="itemId">transform-to-pdf-action</param>
                        <param name="mode">create</param>
                        <param name="destination">{node.nodeRef}</param>
                        <!–
                        <param name="action">transform-to-pdf-action</param>
                        –>
                        <param name="successMessage">Succcès : le document PDF a été créé</param>
                        <param name="failureMessage">Echec : Le document PDF n'a pas été créé"</param>
                </action>
        </actions>
        <actionGroups>
                 <actionGroup id="document-browse">
                         <action index="460" id="transform-to-pdf"/>
                 </actionGroup>
        </actionGroups>
   </config>


It works. But I'm missing something : I would like the user to select the destination folder . I do not find how to add arrige this form.
As it stands, the PDF is created in the same folder.

Please help !

(Sorry for my english)

Merci d'avance

Outcomes