使用以下代码创建操作 (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>
动作.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
}
});
}
});
这是执行转换的 webscript 代码。
var node = args["noderef"];
var docNode = search.findNode(node);
var nodeTrans = docNode.transformDocument("application/pdf");
model.pdfNodeRef = nodeTrans.nodeRef;