Skip to end of metadata
Go to start of metadata

PDF generation with table recognition

 WordTemplateService RECOMMENDED

Example
String templateName = "Example template" ;
WordTemplateService wordTemplateService = SpringContext.getBean( WordTemplateService.class );
File outputFile = TemporaryFile.create();
            
wordTemplateService.generateForProcess( outputFile, templateName, processId, OutputFormat.PDF );

Similarly, you can also use wordTemplateService.generateForActivity to generate from a task context.

There are also variants to both wordTemplateService.generateForProcess and wordTemplateService.generateForProcess, to which you can attach a map with additional data to be taken for generation outside the process/task context.

The generated pdf can be connected to the process and archive using 'WordTemplateUtil'.

Example
String archiveDocumentClassName = "Example class";
WfDocument wfDoc = WordTemplateUtil.archiveAndAttachToProcess( outputFile, processId, activityId, archiveDocumentClassName, templateName, OutputFormat.PDF, true, false );

If, after inserting a document, it is necessary to set the index values or set the document description, then it is enough to set an appropriate action in the archive for this purpose for a given document class. In this case, an action with action source 'Add new document from process level' and action type 'Rewrite indexes from process to documents' or 'Run script'. More details can be found here.

Directly from PrepeareDoc NOT RECOMMENDED

Not recommended

If it is necessary to invoke Java generation, it is recommended to use WordTemplateService.

Przykład uruchomienia :

Example with connection to archive and process
DocumentTemplateService templateService = ServiceFactory.getDocumentTemplateService();
DocumentTemplateTable template = templateService.getByName( "Example template" );
String templatePath = template.getTemplatePath();
String archiveDocumentClassName = "Example class";
Map<String, Object> mOptionalParameters = null;
            
PrepeareDoc.createPdfAndSaveInArchive( templatePath, archiveDocumentClassName, processId, mOptionalParameters );

Do not use

Do not insert variablesMarker, whichTables, whichHeaders parameters into 'mOptionalParameters'. Technically you can specify them, but inserting or changing the default value will result in incorrect operation, e.g. tables or variables will not be recognized correctly and the document will not be generated correctly.

You can use the parameters documentDescription, documentIndices and pageNumbers. The description of the parameters is up to date in the documentation.

PDF generation without table recognition NOT RECOMMENDED

This way requires explicit information about the tables used in the template, it can not recognize whether the individual tables are static or dynamic.

A dynamic table is one where the number of records is not known and can be different each time.

Not recommended

This way is no longer recommended. It has been kept with the following documentation for backward compatibility only.

If it is necessary to call Java generation, it is recommended to use WordTemplateService.

Example:

Example with connection to archive and process
Map<String, Object> mOptionalParameters = new HashMap<String, Object>();
//first two tables static, third dynamic
mOptionalParameters.put( "whichTables", Arrays.asList( false, false, true ));
            
PrepeareDoc.createPdfAndSaveInArchive( templatePath, archiveDocumentClassName, processId, mOptionalParameters );

In 'mOptionalParameters' the parameter 'whichTables' is required, the other parameters are optional.

The description of the parameters is current in the documentation.
Parameter 'variablesMarker' takes the value @ by default, but if you change it to another one, it also works ok. However, it is not necessary, because the variables should be recognized correctly for the default setting even if the @ sign is used in the template content.

 

  • No labels