Conversion samples
Methods
Section titled “Methods”doc2pdf
Section titled “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.
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, 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()); } } }}pdf2swf
Section titled “pdf2swf”Description:
| Method | Return values | Description |
|---|---|---|
| pdf2swf(FileStream fs, String fileName) | Stream | Retrieve the uploaded document converted to SWF format. |
- The parameter fileName is the document file name. The application uses this parameter to identify by document extension the document MIME TYPE.
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, username, password); try { FileStream fileInput = new FileStream("C:\\Documents\\bitcoin.pdf", FileMode.Open); Stream stream = ws.pdf2swf(fileInput, "bitcoin.pdf"); BeanHelper beanHelper = new BeanHelper(); Byte[] data = beanHelper.ReadToEnd(stream); FileStream fileStream = new FileStream("C:\\Documents\\out.swf", 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
Section titled “imageConvert”Description:
| Method | Return values | Description |
|---|---|---|
| imageConvert(FileStream fs, String fileName, List |
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.
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, 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()); } } }}html2pdf
Section titled “html2pdf”Description:
| Method | Return values | Description |
|---|---|---|
| html2pdf(String url) | Stream | Retrieve the PDF of an 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, username, password); try { BeanHelper beanHelper = new BeanHelper(); Stream stream = ws.html2pdf("http://www.openkm.com"); Byte[] data = beanHelper.ReadToEnd(stream); FileStream fileStream = new FileStream("C:\\Documents\\test.pdf", FileMode.OpenOrCreate, FileAccess.ReadWrite); foreach (byte b in data) { fileStream.WriteByte(b); } fileStream.Close(); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}doc2txt
Section titled “doc2txt”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, username, password); try { FileStream fileStream = new FileStream("C:\\Documents\\test.docx", FileMode.Open); System.Console.WriteLine(ws.doc2txt(fileStream, "test.docx")); fileStream.Close(); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}img2txt
Section titled “img2txt”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, username, password); try { FileStream fileStream = new FileStream("C:\\Images\\test.png", FileMode.Open); System.Console.WriteLine(ws.img2txt(fileStream, "test.png")); fileStream.Close(); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}barcode2txt
Section titled “barcode2txt”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, username, password); try { FileStream fileStream = new FileStream("C:\\Images\\test.png", FileMode.Open); System.Console.WriteLine(ws.barcode2txt(fileStream, "test.png")); fileStream.Close(); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}