Lilawood14
Lilawood14

Reputation: 35

Alfresco Action - Convert a file to PDF using an action

I'm using Alfresco V5.0.d and I need to add an action that permits user to transform this document into PDF Format and deplace the PDF document into another directory.

By default, Alfresco propose two actions for my need :

Or, I want to add an action that when user clicks on it, a PDF file is created from document and this PDF file is deplaced into another directory.

I don't know if it's possible to do that thanks to default actions (without developement or script) proposed by Alfresco or if I need to add this action by developping it / addind a script.

Can you please help me or give me some advices ?

Thanks !

Upvotes: 1

Views: 1523

Answers (2)

Sanjay
Sanjay

Reputation: 2503

Create Action using below code (share-config-custom.xml)

<config evaluator="string-compare" condition="DocLibActions">
                <actions>
                    <action id="transform-to-pdf" type="javascript" label="Download as PDF">
                        <param name="function">convertAndDownload</param>
                        <evaluator negate="true">alfresco.tutorials.evaluator.checkFileType
                        </evaluator>
                    </action>
                </actions>

                <actionGroups>
                    <actionGroup id="document-browse">
                        <action index="400" id="transform-to-pdf" />
                    </actionGroup>
                </actionGroups>
            </config>

            <config evaluator="string-compare" condition="DocLibCustom"
                replace="true">
                <dependencies>
                    <js src="components/myactions/actions.js" />
                </dependencies>
            </config>

action.js

YAHOO.Bubbling.fire("registerAction", {
    actionName : "convertAndDownload",
    fn : function convertAndDownload(record) {

        var nodeid = record.nodeRef;

        Alfresco.util.Ajax.request({
            url : Alfresco.constants.PROXY_URI+ "/transformer/filetopdf?noderef=" + nodeid,
            successCallback : {
                fn : function onTransformAction_success(response) {
                    var pdfNodeRef = response.json.pdfNodeRef;
                    var noderef = response.json.pdfNodeRef;
                    pdfNodeRef = pdfNodeRef.replace("://", "/");
                    window.open(Alfresco.constants.PROXY_URI+ "slingshot/node/content/" + pdfNodeRef+ "?a=true");

                    Alfresco.util.Ajax.request({
                        url : Alfresco.constants.PROXY_URI+ "/transformer/filedelete?noderef=" + noderef,
                        successCallback : {
                            fn : function onTransformAction_success(response) { },
                            scope : this
                        },
                        failureCallback : {

                            fn : function onTransformAction_failure(response) {},
                            scope : this
                        }
                    });
                },
                scope : this
            },
            failureCallback : {

                fn : function onTransformAction_failure(response) {
                    Alfresco.util.PopupManager.displayMessage({
                        text : "Something went wrong,please try again later"
                    });
                },
                scope : this
            }
        });
    }
});

this is webscript code where transform is performed.

var node = args["noderef"];
var docNode = search.findNode(node);
var nodeTrans = docNode.transformDocument("application/pdf");
model.pdfNodeRef = nodeTrans.nodeRef;

Upvotes: 1

Jeff R.
Jeff R.

Reputation: 188

As mentioned there is a some development that is required. The API to do the transform is trivial, but putting all the pieces together takes a bit if you've never done any Alfresco development. This describes a tutorial for what you'd do around adding a send email action http://docs.alfresco.com/5.2/tasks/dev-extensions-share-tutorials-add-action-doclib.html.

You might check out http://ecmarchitect.com/alfresco-developer-series around adding actions as well as http://docs.alfresco.com/5.2/references/dev-extension-points-actions.html and http://docs.alfresco.com/5.2/references/dev-services-content.html.

You can also do this with a javascript web script you create to do the transform on the repository end (that's just a few lines of javascript http://docs.alfresco.com/5.2/references/API-JS-Transformation-document.html) for the javascript part of the web script. You'd just need to add the share config and a little bit javascript to make the web script call.

If you've done work with Alfresco this is a couple of hours of effort. If you have no experience developing with Alfresco, however, the simplest way to do this is just to create a Transform and Copy Content rule as you mention. Remember, you can base it on location of course, but also have other criteria you can add like checking the value of a property on the node (e.g. when status=approved).

Upvotes: 2

Related Questions