Alfresco-将文档转换为pdf并下载自定义操作 [英] Alfresco - Transform Doc to pdf and download custom action
问题描述
我创建了一个自定义操作,可将文档转换为pdf.有效 很好,但是我想点击相同的自定义即可下载转换后的pdf 动作,我的意思是我要在单击时转换并下载文档 自定义动作.该怎么做? 我尝试了以下代码.
I have created one custom action to convert document to pdf. It worked fine but I want to download converted pdf on click of same custom action , I mean I want to convert and download document on clicking of custom action.How can do that? I have tried following code.
newdoc = document.transformDocument("application/pdf"); newdoc.save();
推荐答案
在这里,您需要传递实际的nodeRef值. 在share-custom-config.xml中添加了新的文档操作
Here you go and you need to pass your actual nodeRef values. Added new document action in share-custom-config.xml
<action id="convert-to-pdf-download" type="javascript" label="Download As PDF" icon="document-download">
<param name="function">onTransformToPDFAndDownload</param>
</action>
<actionGroups>
<actionGroup id="document-browse">
<action index="107" id="convert-to-pdf-download" />
</actionGroup>
<actionGroup id="document-details">
<action index="107" id="convert-to-pdf-download" />
</actionGroup>
</actionGroups>
现在,您需要像下面那样注入javascript,并且需要传递原始文档的nodeRef,并且我在此处具有硬代码.
Now you need to inject your javascript like below and you need to pass the original document's nodeRef and I have hard-code here.
onTransformToPDFAndDownload: function dla_onTransformToPDFAndDownload(record) {
Alfresco.util.Ajax.request(
{
url: Alfresco.constants.PROXY_URI + "com/quanticate/quanticliq/transformer/transform?noderef=workspace://SpacesStore/ec0ca4cf-9ea4-4c12-8f2c-5b0c406e454b",
successCallback:
{
fn: function onTransformAction_success(response)
{
debugger;
var pdfNodeRef = response.json.pdfNodeRef;
pdfNodeRef = pdfNodeRef.replace("://","/");
window.open(Alfresco.constants.PROXY_URI + "slingshot/node/content/" + pdfNodeRef +"?a=true");
},
scope: this
},
failureCallback:
{
fn: function onTransformAction_failure(response)
{
Alfresco.util.PopupManager.displayMessage(
{
text: "Something went wrong,please try again later"
});
},
scope: this
}
});
}
在Repoweb脚本上, convert.get.desc.xml
On the Repowebscript, convert.get.desc.xml
<webscript>
<shortname>toPDF</shortname>
<desciption>Return PDF Node</desciption>
<url>/com/quanticate/quanticliq/transformer/transform</url>
<authentication>user</authentication>
<format default="json">any</format>
</webscript>
convert.get.json.ftl
\"{\"pdfNodeRef\" :\"${pdfNodeRef.nodeRef}\"}\"
convert.get.js
function main()
{
var json = "{}";
var docNode = search.findNode("workspace://SpacesStore/ec0ca4cf-9ea4-4c12-8f2c-5b0c406e454b");
var nodeTrans = docNode.transformDocument("application/pdf");
model.pdfNodeRef = nodeTrans.nodeRef;
}
main();
单击另存为PDF"时,将生成PDF文档,并放置信息文档库(或原始文档所在的位置),并将自动下载.您需要检查现有的PDF文件是否存在.
When you click Download As PDF, the PDF document will be generated, placed info document library (or where the original document is present) and will be downloaded automatically. You need to check for the existing PDF files exists or not also.
这篇关于Alfresco-将文档转换为pdf并下载自定义操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!