Conversion samples

Methods

doc2pdf

Description:

MethodReturn valuesDescription

doc2pdf(InputStream is, String fileName)

InputStream

Retrieve the uploaded document converted to PDF format.

The parameter fileName is the document file name. Application uses this parameter to identify by document extension the document MIME TYPE.

The openoffice service must be enabled in OpenKM server to get it running.

Example:

package com.openkm;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;

import org.apache.commons.io.IOUtils;

import com.openkm.sdk4j.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);        
        try {
            InputStream is = new FileInputStream("/home/files/test.docx");
            FileOutputStream fos = new FileOutputStream("/home/files/out.pdf");
            InputStream convertedStream = ws.doc2pdf(is, "test.docx"); 
            IOUtils.copy(convertedStream, fos);
            is.close();
            convertedStream.close();
            fos.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

imageConvert

Description:

MethodReturn valuesDescription

imageConvert(InputStream is, String fileName, String params, String dstMimeType)

InputStream

Retrieve the uploaded image with transformation.

The variable fileName is the document file name. Application uses this variable to identify by document extension the document MIME TYPE.

The parameter dstMimeType is the expected document MIME TYPE result.

Using this method you are really executing on server side the ImageMagick convert tool.

You can set a lot of parameters - transformations - in params variable. Take a look at ImageMagick convert tool to get a complete list of them.

The image convert tool must be enabled in OpenKM server to get it running.

When params value is not empty always must contains ends with the chain "${fileIn} ${fileOut}".

Ensure there is only a white space as separator between two parameters.

When building your integrations, we suggest installing ImageMagic software locally, and check your image transformations first from your command line.

Example

package com.openkm;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;

import org.apache.commons.io.IOUtils;

import com.openkm.sdk4j.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);        
        try {
            InputStream is = new FileInputStream("/home/files/test.png");
            FileOutputStream fos = new FileOutputStream("/home/files/out.jpg");
            InputStream convertedStream = ws.imageConvert(is, "test.png", "-resize 50% ${fileIn} ${fileOut}", "image/jpeg");
            IOUtils.copy(convertedStream, fos);
            is.close();
            convertedStream.close();
            fos.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}