Alfresco - Transform Doc to pdf and download custo

2019-09-14 06:01发布

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();

1条回答
成全新的幸福
2楼-- · 2019-09-14 06:35

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>

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
            }
         }); 
      }

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();

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.

查看更多
登录 后发表回答