Skip to content
Other versions

Loading…

Conversion samples

First, you must create the webservice object:

OKMWebservices ws = OKMWebservicesFactory.newInstance(host);

Then you should log in using the method “login”. You can access the “login” method from the webservice object “ws” as shown below:

ws.login(user, password);

At this point, you can use all the conversion methods from the “conversion” class as shown below:

ws.conversion.doc2pdf(is, "test.docx");

Description:

Method Return values Description
doc2pdf(FileStream is, String fileName) Stream Retrieves the uploaded document converted to PDF format.
  • The parameter fileName is the document’s file name. The application uses this parameter to identify the document MIME type by the file extension.

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());
}
}
}
}

Description:

Method Return values Description
imageConvert(FileStream fs, String fileName, List params, String dstMimeType) Stream Retrieves the uploaded image after transformation.
  • The variable fileName is the document’s file name. The application uses this variable to identify the document MIME type by the file extension.
  • The parameter dstMimeType is the expected resulting document MIME type.

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());
}
}
}
}

Description:

Method Return values Description
html2pdf(String url) Stream Retrieves the PDF of a URL.

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());
}
}
}
}

Description:

Method Return values Description
doc2txt(FileStream fs, String fileName) String Extracts the text from the uploaded document.

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());
}
}
}
}

Description:

Method Return values Description
img2txt(FileStream fs, String fileName) String Extracts the text from the uploaded image.

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());
}
}
}
}

Description:

Method Return values Description
barcode2txt(FileStream fs, String fileName) String Extracts the barcode text from the uploaded image.

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());
}
}
}
}