Árvore de páginas

Índice


Document View

By definition, the internal view at TOTVS Fluig Platform supports the formats for documents, images, texts and PDF extension. However, there are cases where it is necessary that the Viewer be supported for other document formats, such as spreadsheets, DWG files, etc.

In order to ease the integration with different formats, TOTVS Fluig Platform has customization points that allows any file format to be supported in the internal viewer as long as there is any tool available to perform the conversion of the desired format to the PDF format.

The documents must have a copy in the PDF 1.4 format to be internally viewed in TOTVS Fluig Platform, whose specification is in http://www.adobe.com/devnet/pdf/pdf_reference_archive.html

TOTVS Fluig Platform makes the automatic conversion to PDF with text documents supported by Microsoft® Word or OpenOffice.org™. For other types, if one wishes to use them in the internal viewer, a conversion plugin for PDF must be built.

Necessary Knowledge

In order to build a converter, it is necessary to have the following skills:

  • Java ™ EE Technology
  • JavaScript Language

Construction of a Converter

The conversion plugin is made of two parts:

  1. A Message-Driven EJB component to receive the conversion request;
  2. Application/program that will convert it;
  3. Indicate that the document uses the internal viewer

This chapter will present an example of a converter for text (.txt) files to PDF, in order to use the internal viewer on TOTVS Fluig Platform.


Importante

Please download the following codes:

ECMExternalConvertion-project.zip




    Part 1: Building the Message-Driven EJB

    Create a Message-Driven that listens to the topic/wdkDocument topic: Find example source below:


    TxtMessageBean.java
    package com.fluig.conv;
    import javax.ejb.ActivationConfigProperty;
    import javax.ejb.MessageDriven;
    import javax.jms.Message;
    import javax.jms.MessageListener;
    @MessageDriven(name = "test/TxtConverter", activationConfig = {
        @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
        @ActivationConfigProperty(propertyName = "destination", propertyValue = "topic/wdkDocument")
    })
    public class TxtMessageBean implements MessageListener {
        @Override
        public void onMessage(Message message) {
            try {
                String event = message.getStringProperty("event");
                if (event != null && event.equals("EXTERNALCONVERTION")) {
                    String doc = message.getStringProperty("documentpath");
                    if (doc != null && doc.endsWith(".txt")) {
                        ProcessBuilder pb = new ProcessBuilder("txt2pdf.exe", doc, doc + ".pdf", "-lpp40");
                        pb.start();
                    }
                }
                
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        
    }


    The Message-Driven above configures the destinationType property for "javax.jms.Topic" to indicate that it will listen to a JMS topic, and the destination property to"topic/wdkDocument" to indicate which topic will be listened to. The "topic/wdkDocument" topic is where the document publishing events are sent to.

    Upon receiving a message, the type of published event must be checked through the StringProperty "event"; if the value of this property is "EXTERNALCONVERTION", it means that TOTVS Fluig Platform is indicating that this is the time for the customized conversion to take place.

    In order to obtain the document path, check the StringProperty "documentpath".

    After this, the file extension must be checked to validate if this is the correct converter, because there may be more than one converter for different extensions.

    Once the parameters are validated, the converter program can be called; in the example, the txt2pdf http://www.verypdf.com/txt2pdf/ freeware was used.

    The target document must have the same name plus the .pdf extension, and it should be in the same directory. Ex: doc.txt converted: doc.txt.pdf

    It is important to remember that the source document may not be modified, with the penalty of TOTVS Fluig Platform indicating that it has been externally changed (CRC validation).

    This Message-Driven must be packed and deployed on the application server according to Java™ EE specifications.



    Part 2: Message-Driven for the creation of long-term documents

    The Message-Driven presented in the previous item can be used in the creation of long-term documents, with a few changes being necessary. In order to know if the Message-Driven is being used for the creation of a long-term file, there is a new parameter called "isLongTerm", this parameter is a String, and if it is "true", the document it wants to generate is a PDF/A, considered a long-term file.

    TOTVS Fluig Platform considers only the PDF/A format as the one possible to generate long-term documents via Message-Driven.

     In order to identify the creation of a long-term file, the physical name of the document should be changed, including the string "PDFA" at the end of the file name. For example, if the file name is manual.txt, the name of this file after conversion will be manual.txtPDFA.pdf. See the example below showing the changes needed in Message-Driven to create the long-term document:


    String longTerm = message.getStringProperty("isLongTerm");
    if (doc != null && doc.endsWith(".txt")) {
    	if (longTerm != null && longTerm.equals("true")) {
    		String documentName = doc + "PDFA.pdf";
    		//Call the conversion method for PDF/A
    	}
    }

    On the first line, the parameter value "isLongTerm" is recovered to know if the creation of a long-term file is being requested. After checking the document extension, the longTerm variable value is checked. If it is not null and is "true", then the creation can be performed by calling the document conversion method using for such the file name with the "PDFA.pdf" string.


    Part 3: Registering the converter at TOTVS Fluig Platform

    In Fluig Studio, right-click the events folder, select the New option and then the Fluig Global Event option:



    The New Event wizard is opened. Select the addDocumentConvertionExt event and then click on the Finish button.

    The event is added to the project in the events folder and opened for editing. The objective of this global event is to add the extensions with a custom converter. In this example, it is necessary to add the txt extension, as seen in the source below:

    addDocumentConvertionExt.js
    function addDocumentConvertionExt(ext) {
    	ext.add("txt");
    }

    Attention: For printing published documents with the option "Update Controlled Copy Properties?" the external converter will NOT be used. Since it is necessary to apply the controlled copy properties to the original document and perform a new conversion, this process can only be performed at the execution time with the product standard converter. Therefore, in the printing of documents, format can be lost depending on the visual resources applied in its content (borders, colors, images, etc)..




    Part 4: Add the listener to the Fluig server

    Pack the JMS listener and add it to <SERVER FLUIG>/jboss/apps/.

     






    Part 5: Indicate that the document uses internal viewer

    Now that the .txt extension was recorded as having a customized converter, mark the option "Use Internal Viewer?" in the document publication:




    Notes:

    • In the example provided, integration examples are provided for the previously created Office (Word, Excel and PowerPoint) products.
    • In the example provided, an integration example for converting DWG formats using the dwg2pdf tool from the AutoDWG company.
    • The conversion codes are only examples, their development and configuration are the responsibility of the developer.
    • A packed plugin can be used made available in the attachment. The settings detailed in the guide Java® execution environment, allowing communication between the Fluig server and Office components are necessary for the integration with Microsoft products.