Conversion samples

Methods

doc2pdf

Description:

MethodReturn valuesDescription

doc2pdf(FileStream is, String fileName)

Stream

Retrieve the uploaded document converted to PDF format.

The parameter fileName is the document file name. The 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:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.util;
using System.IO;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/OpenKM";
            String username = "user1";
            String password = "pass1";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
            try
            {
                BeanHelper beanHelper = new BeanHelper();
                FileStream fileInput = new FileStream("C:\\Documents\\test.docx", FileMode.Open);
                Stream stream = ws.doc2pdf(fileInput, "test.docx");
                Byte[] data = beanHelper.ReadToEnd(stream);
                FileStream fileStream = new FileStream("C:\\Documents\\out.pdf", FileMode.OpenOrCreate, FileAccess.ReadWrite);
                foreach (byte b in data)
                {
                    fileStream.WriteByte(b);
                }
                fileStream.Close();
                fileInput.Close();
            } 
            catch (Exception e)
            {
                System.Console.WriteLine(e.ToString());
            } 
        }
    }
}

imageConvert

Description:

MethodReturn valuesDescription

imageConvert(FileStream fs, String fileName, List<String> params, String dstMimeType)

Stream

Retrieve the uploaded image with transformation.

The variable fileName is the document file name. The 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 the server side the ImageMagick convert tool.

You can set a lot of parameters - transformations - in the 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 contain ends with the chain "${fileIn} ${fileOut}".

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

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

Example:

using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.util;
using System.IO;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/OpenKM";
            String username = "user1";
            String password = "pass1";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
            try
            {
                FileStream filestream = new FileStream("C:\\Documents\\test.png", FileMode.Open);
                List<string> param = new List<string>();
                param.Add("-resize 50% ${fileIn} ${fileOut}");
                Stream stream = ws.imageConvert(filestream, "test.png", param, "image/jpeg");
                BeanHelper beanHelper = new BeanHelper();
                Byte[] data = beanHelper.ReadToEnd(stream);
                FileStream fileStream = new FileStream("C:\\Documents\\test.png", FileMode.OpenOrCreate, FileAccess.ReadWrite);
                foreach (byte b in data)
                {
                    fileStream.WriteByte(b);
                }
                fileStream.Close();
            } 
            catch (Exception e)
            {
                System.Console.WriteLine(e.ToString());
            } 
        }
    }
}