cancel
Showing results for 
Search instead for 
Did you mean: 

Using the .transformDocument function

rodrigoa
Champ in-the-making
Champ in-the-making
Good Afternoon all,

I am having some problems to transform a .doc into a .pdf. I am creating a .doc and trying to convert it to a .pdf and put it into a specific site. Is that possible? or is there any other way to do what I need?

Here is my code:

         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
               var site = siteService.getSite("revision");
               var doc1 = userhome.createFile("transform_me1.doc");
               doc1.mimetype = "text/plain";
               doc1.content = "This is plain text";
               var trans1 = doc1.transformDocument("application/pdf", site);
            </script>
         </action>

Thanks in advance,

Rodrigo Araujo.
9 REPLIES 9

amandaluniz_z
Champ on-the-rise
Champ on-the-rise
Hi Rodrigo,

Following your other post it would be:


var revisionSite = siteService.getSite("revision");
var documentLibrary = revisionSite.getContainer("documentLibrary");
var myDocument = documentLibrary. childByNamePath("path/to/my/document.doc");
var trans1 = myDocument.transformDocument("application/pdf", documentLibrary);

That code would place the PDF in the document library in the 'revision' site.

Adei

rodrigoa
Champ in-the-making
Champ in-the-making
Hi Adei,

thank very much for your answer. If you do not mind, I would like to ask one thing more.

I am getting the below error:

10:49:28,842 DEBUG [org.alfresco.repo.jscript.ScriptLogger] org.alfresco.service.cmr.workflow.WorkflowException: 00170005 Failed to signal transition approuver from workflow task jbpm$217.
10:49:28,842 DEBUG [org.alfresco.repo.jscript.ScriptLogger] Returning 500 status code

I tried the code you sent to me, and I also tried to change the "path/to/my/document.doc" for "documentLibrary", because I want to get the document that is located into the revision site, but in both cases the return of childByNamePath are null.

Thanks in advance,

Rodrigo Araujo

amandaluniz_z
Champ on-the-rise
Champ on-the-rise
Hi Rodrigo,

That error is not related to the code I sent you but to the workflow definition.

Could you post the workflow definition process and the error log you are getting?

Adei

mitpatoliya
Star Collaborator
Star Collaborator
Also I believe you you must be saving the document at the end of the script.
myDocument .save();
This is the format I guess.

amandaluniz_z
Champ on-the-rise
Champ on-the-rise
You don't need to save the document as you're not changing anything in myDocument

rodrigoa
Champ in-the-making
Champ in-the-making
Hello Adei,

thank you very much again for your answer.

Actually I resolve half of this problem, with this….

var revisionSite = siteService.getSite("revision");
var publieesSite = siteService.getSite("publiees");
var documentLibraryRevision = revisionSite.getContainer("documentLibrary");
var documentLibraryPubliees = publieesSite.getContainer("documentLibrary");
var myDocument = documentLibraryRevision.childByNamePath("test.doc");
var trans = myDocument.transformDocument("application/pdf");

I just replaced the "path/to/my/document.doc" for "test.doc", and it works now. But, unfortunatelly, It brought me to another problem, I wrote test.doc because I know the .doc I am using to do my test, but in a real situation I would not know the name of the file. Is there anyway to this in a generic way?!!

As you requested, here is my workflow definition process:

<?xml version="1.0" encoding="UTF-8"?>
<process-definition xmlns="urn:jbpm.org:jpdl-3.3"
   name="capvpwf:validation_procedure">
   <swimlane name="initiator" />
   <swimlane name="reviewer">
      <assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
         <actor>#{bpm_assignee}</actor>
      </assignment>
   </swimlane>
   <start-state name="start-state">
      <task name="capvpwf:validProcedureStartTask" swimlane="initiator" />
      <transition to="validation_procedure"></transition>
   </start-state>
   <task-node name="validation_procedure">
      <task name="capvpwf:validProcedureTask" swimlane="reviewer">
         <event type="task-create">
            <action class="com.lacapitale.workflow.action.LacapitaleTaskStart" />
         </event>
         <event type="task-end">
            <action class="com.lacapitale.workflow.action.LacapitaleTaskEnd" />
         </event>
      </task>
      <event type="node-enter">
         <action class="com.lacapitale.workflow.action.DeplaceProcedureAction"
            config-type="bean">
            <site>revision</site>
         </action>
      </event>
      <transition to="end-state" name="approuver">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
               var revisionSite = siteService.getSite("revision");
               var publieesSite = siteService.getSite("publiees");
               var documentLibraryRevision = revisionSite.getContainer("documentLibrary");
               var documentLibraryPubliees = publieesSite.getContainer("documentLibrary");
               var myDocument = documentLibraryRevision.childByNamePath("test.doc");
               var trans = myDocument.transformDocument("application/pdf");
            </script>
         </action>
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
               logger.log("*** approuver ***");
               var group = people.getGroup('GROUP_NOTIFICATION_PROCEDURES');
               if (group != null){
                  for each(user in people.getMembers(group)){
                     logger.log("*** User name: " + user.properties.firstName);
                     logger.log("*** User mail: " + user.properties.email);
                     var mail = actions.create("mail");
                     mail.parameters.to = user.properties.email;
                     mail.parameters.subject = "" + bpm_workflowDescription;
                     mail.parameters.from = bpm_assignee.properties.email;
                     mail.parameters.text = "Procédure a été APPROUVÉE";
                     mail.execute(bpm_package);
                  }
               }
              </script>
         </action>
         <action class="com.lacapitale.workflow.action.DeplaceProcedureAction"
            config-type="bean">
            <site>publiees</site>
         </action>
         <!– <action class="com.lacapitale.workflow.action.Test"></action> –>
      </transition>
      <transition to="end-state" name="rejeter">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
               logger.log("*** rejeter ***");
               var mail = actions.create("mail");
               mail.parameters.to = initiator.properties.email;
               mail.parameters.subject = "" + bpm_workflowDescription;
               mail.parameters.from = bpm_assignee.properties.email;
               mail.parameters.text = "Procédure a été REJETÉE";
               mail.execute(bpm_package);
           </script>
         </action>
         <action class="com.lacapitale.workflow.action.ReplaceProcedureAction">
         </action>
      </transition>
   </task-node>
   <end-state name="end-state"></end-state>
</process-definition>

Thanks very much,

Best Regards,

Rodrigo Araujo

amandaluniz_z
Champ on-the-rise
Champ on-the-rise
Hi Rodrigo,

I guess that you want to use your doc in the workflow to approve it.

For that purpose you'll need to attach it to the workflow (I guess the user will manually). if so, the document will be available in bpm_package variable. That is a scriptNode object containing all the nodes attached to the workflow.

To get access to your doc you should use this code:


for (var i = 0; i &lt; bpm_package.children.length; i++)
                   {

                      var myDoc = bpm_package.children[i]
                      …….
                   }

If you know there'll be just one doc in the workflow you could do bpm_package.children[0]

Adei

rodrigoa
Champ in-the-making
Champ in-the-making
Hi Adei,

It worked, I don't know how to thank you.

Thank you very very much,

Best Regards,

Rodrigo Araujo

amandaluniz_z
Champ on-the-rise
Champ on-the-rise
You're welcome Rodrigo Smiley Wink