Create a document from an embedded task form


#6

You can use a Service Task for option 1.

If you do not need the PDF for the rest of your process, you can create it in the Frontend. This also scales better than a service task.


#7

@martin.stamm, I need the pdf for the rest of my process, so I assume that if I select your 1st option here, I must do this via a Service Task.
But I would like to ask what do you mean by saying that I can create it in the Frontend ?

Thanks,
Steve


#8

In that case I recommend using a service task.

Basically option 2, your process would not know about the PDF because it is generated in the browser


#9

Hi @martin.stamm,

So, from your hints here, I assume that the dynamic creation of the PDF in the form (your 2nd option above) isn’t so convenient in my case.
Could you please make clear to me what do you mean here ?

 Basically option 2, your process would not know about the PDF because it is generated in the browser

What I want to do, is to simply send the generated pdf via email (so it could be done out of the process’s scope) and by this way my process is completed.
Could you please give me a hint (by Docs) about the creation of a document via a Service Task ?

Thank you a lot,
Steve


#10

Hi @steftriant,

You need to generate the PDF with a service task then :slight_smile:
A Service Task can execute arbitrary Java code. You can use a java library to generate your code, for example itext. There are many others.


#11

Hi @martin.stamm,

In your opinion, which implementation way is the easiest for a user like me (with very little experience in programming) ?
By calling Java code or in the form of an external task ?

Thanks a lot,
Steve


#12

Hi @steftriant,

As you want to send the PDF via email, you will have to create it by calling Java code.
There should not be much difference in complexity in my opinion.

KR


#13

Hi again @martin.stamm,

My exact purpose is to produce a pdf document (with iText library maybe) from an html task form like the following:

This task form is displayed when the user loads his form in “Receive the Selected Products” User Task:

So, I don’t want to create an empty pdf document but to convert the above html form.
Must I do sth before the conversion (such as to get the task form in the form of a file by REST API call for example) ?

Thanks a lot,
Steve


#14

Hi @steftriant and sorry for the delay,

I’m not sure if I understood you use-case correctly.
Do you want the User of Tasklist to download the PDF or send it as an email via an automated task?

KR
Martin


#15

Hi @martin.stamm and thanks for your interest,

What I want to achieve is the following:

On the submission of a user task form (like my above screenshot here), to automatically create and download a pdf document with the same data as included in the task form. Something like conversion for example.

The pdf document will be sending (by email) outside of process by the user.

Thank you again,
Steven


#16

Thanks for the clarification.

That can be achieved with a JS library like jspdf. There is an example on how to use it here.

This will not need a Java Task and can be done in your embedded form alone.
You can include the library as a custom script and use it in your embedded forms.

Let me know if you need help getting the custom script to work correctly


#17

Hi @martin.stamm,

It looks like a dynamic creation and download of the pdf document from the html form.
I’m going to read thoroughly your suggested links here and I will let you know of course in any case. :slightly_smiling_face:

Thanks a lot,
Steve


#18

Hi again @martin.stamm,

I’ve been reading your suggested way here but I have some questions:

  1. First of all, I downloaded the free version of jspdf. How can I include and use it in my embedded task form ?
  2. As far as the coding is concerned, must I use the jQuery framework (like the example here) ? If yes, how can I include this framework in my Camunda project ? I’ve never used it.
  3. As far as the custom script is concerned, the required property “customScripts” is already included as a comment in the config.js file.
    I can’t understand here which AngularJS module names must be added as dependencies and where.
    Generally, could you please guide me a bit in the content of the config.js file ?

Many thanks,
Steve


#19

Hi @steftriant,

All your questions come down to the custom scripts, so I’ll guide you through that first:

You download the libraries and place them in the app/tasklist/scripts directory of your webapp. Then you add them in the app/tasklist/scripts/config.js. Here is an example how you would add JQuery:

  customScripts: {
    ngDeps: [], // can be left empty
    deps: ['jQuery'], // The variable which you use to reference the library
    paths: {
      'jQuery': 'scripts/jquery-XXX' // The filename without .js 
    }
  }

The library is then available for use in Tasklist and embedded forms. You might need to do a hard refresh (ctrl+F5 in chrome) to see the changes.

If this does not solve your question, let me know.

KR
Martin


#20

Hi @martin.stamm. jspdf downloaded library includes the following:


Have I to place in the suggested directory all the available js files ?


#21

@martin.stamm, could you please clarify the last line of the code ? Where does XXX is referenced and whose file must I write the name ?

Could you please take a look at my following screenshot (from my config.js file) and tell me if I’ve written sth wrong ?

Thank you very much,
Steven


#22

That’s the name of your javaScript file. For example, if you downloaded jquery-3.4.1.js, you would put 'jQuery': 'scripts/jquery-3.4.1'


#23

@martin.stamm by saying “place the libraries”, you mean all the downloaded folder of the jspdf or some specific js files ?

Inside my downloaded jspdf folder, there isn’t any jquery-XXX.js file :face_with_raised_eyebrow:
Could you please tell me where can I find it ?

Thanks a lot,
Steven


#24

Hi,

the JQuery is an example of a library you might want to add. Please replace the names and filepaths with the libraries you want to use


#25

Hi @martin.stamm,

Eventually, I decided to follow a different approach as far as the generation of the document.
My purpose here is to convert the following filled-in html form to a pdf document via a Service Task Java call.

Could you tell me please if I must get this html form as a file with a Rest Api Call like this one firstly ?
https://docs.camunda.org/manual/7.10/reference/rest/task/get-rendered-form/

Thanks a lot,
Steve