Conversion samples
Basic
Suggested code sample
First, you must create the webservice object:
OKMWebservices ws = OKMWebservicesFactory.newInstance(host);
Then should login using the method "login". You can access the "login" method from webservice object "ws" as is shown below:
ws.login(user, password);
Once you are logged with the webservices the session is keep in the webservice Object. Then you can use the other API method
At this point you can use all the Conversion methods from "conversion" class as is shown below:
ws.conversion.doc2pdf(is, "test.docx");
Methods
doc2pdf
Description:
Method | Return values | Description |
---|---|---|
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 = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try
{
ws.login(user, password);
FileStream inputFile = new FileStream("C:\\Documents\\test.docx", FileMode.Open);
Stream tmpFile= ws.conversion.doc2pdf(inputFile, "test.docx");
inputFile.Close();
FileStream outputFile = new FileStream("C:\\Documents\\out.pdf", FileMode.OpenOrCreate, FileAccess.ReadWrite);
tmpFIle.CopyTo(outputFile);
outputFile.Close();
tmpFIle.Close();
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
imageConvert
Description:
Method | Return values | Description |
---|---|---|
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 ImageMagic 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 = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try
{
ws.login(user, password);
FileStream fileStream = new FileStream("C:\\Documents\\test.jpg", FileMode.Open, FileAccess.Read);
List<string> param = new List<string>();
param.Add("-resize 50% ${fileIn} ${fileOut}");
Stream tmpFIle = ws.conversion.imageConvert(fileStream, test.jpg, param, "image/png");
fileStream.Close();
FileStream destFile = new FileStream("C:\\Documents\\test.png", FileMode.OpenOrCreate);
tmpFIle.CopyTo(destFile);
destFile.Close();
tmpFIle.Close();
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
html2pdf
Description:
Method | Return values | Description |
---|---|---|
html2pdf(String url) |
Stream |
Retrieve the PDF of an URL. |
The HTML to PDF conversion tool must be enabled in OpenKM server to get it running |
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 = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try
{
ws.login(user, password);
Stream tmpFile = ws.conversion.html2pdf("http://www.openkm.com");
FileStream destFile = new FileStream("C:\\Documents\\test.pdf", FileMode.OpenOrCreate);
tmpFile.CopyTo(destFile);
destFile.Close();
tmpFile.Close();
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
doc2txt
Description:
Method | Return values | Description |
---|---|---|
doc2txt(FileStream fs, String fileName) |
String |
Extracts the text from the uploaded document. |
Must be enabled a Text Extractor for the document MIME TYPE 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 System.IO;
namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8080/openkm";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try
{
ws.login(user, password);
FileStream fileStream = new FileStream("C:\\Documents\\test.docx", FileMode.Open);
System.Console.WriteLine(ws.conversion.doc2txt(fileStream, "test.docx"));
fileStream.Close();
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
img2txt
Description:
Method | Return values | Description |
---|---|---|
img2txt(FileStream fs, String fileName) |
String |
Extracts the text from the uploaded image. |
The OCR engine 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 System.IO;
namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8080/openkm";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try
{
ws.login(user, password);
FileStream fileStream = new FileStream("C:\\Images\\test.png", FileMode.Open);
System.Console.WriteLine(ws.conversion.img2txt(fileStream, "test.png"));
fileStream.Close();
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
barcode2txt
Description:
Method | Return values | Description |
---|---|---|
barcode2txt(FileStream fs, String fileName) |
String |
Extracts the barcode text from the uploaded image. |
The Bar Code tool 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 System.IO;
namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8080/openkm";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try
{
ws.login(user, password);
FileStream fileStream = new FileStream("C:\\Images\\test.png", FileMode.Open);
System.Console.WriteLine(ws.conversion.barcode2txt(fileStream, "test.png"));
fileStream.Close();
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}