cancel
Showing results for 
Search instead for 
Did you mean: 

Custom action for create PDF

sebbri
Champ in-the-making
Champ in-the-making
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
Sébastien Brière
5 REPLIES 5

sebbri
Champ in-the-making
Champ in-the-making
I add this in share-config-custom.xml :
   <config evaluator="string-compare" condition="transform-to-pdf-action">      <forms>         <form>            <field-visibility>               <show id="destination-folder" />            </field-visibility>            <appearance>               <field id="destination-folder" label="Choisir la destination">                        <control template="/org/alfresco/components/form/controls/myassociation.ftl">                                <control-param name="displayMode">items</control-param>                                <control-param name="showTargetLink">true</control-param>                                <control-param name="compactMode">true</control-param>                        </control>               </field>            </appearance>         </form>      </forms>   </config>‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍


Why "myassociation.ftl" ? : it's for this bug https://forums.alfresco.com/forum/developer-discussions/alfresco-share-development/potential-share-a...

It works, but now big problem: how to pass the destination-folder value to JS script ???

Pleaaaase !
Sébastien Brière

muralidharand
Star Contributor
Star Contributor
You can develop a simple form / control in the document library actions, like how we will be uploading new version of the document.
It just popups a small windows select the document, selection major or minor version and comment, then document will be uploaded into document library. Does this kind of approach will help you ?
You can even think like, Manage aspects, Manage permission option from the document library.
Please let me know, if you need additional help on this.

sebbri
Champ in-the-making
Champ in-the-making
Thank you very much for your answer.

I tried to explain what I want to do (not easy because my English is not very good).

I want my users to have the ability to create a PDF from a document ( such as a .doc , etc.). I first activate the Transform action that allows it but that does not suit me perfectly.

Indeed, the action of native processing allows the user to select the type . Except that I only want a transformation in PDF .
The other constraint is that the created PDF document must have a property containing one hand the name of the source document and version . It is a request of my users.

So I experienced my own JS script that does this.

I try to create an action " Transform to PDF " which launches this script after the user chose the destination folder.

I managed to create an action with a form that lets you choose a destination folder. Now I'm stuck because I can not pass to the script the value of the destination folder.

Greetings
Sébastien Brière

sebbri
Champ in-the-making
Champ in-the-making
Thanks
Sébastien Brière

sebbri
Champ in-the-making
Champ in-the-making
Hello,

I 'm sorry but I 'm completely stuck . I need help.

How can I have a value entered in a form from a JS script?

Here, my action displays a form to choose the destination folder but I do not know how to extract this value from the script !!! I despair
Sébastien Brière