Conversion samples
Methods
Section titled “Methods”doc2pdf
Section titled “doc2pdf”Description:
| Method | Return values | Description |
|---|---|---|
| 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.
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(); } }}pdf2swf
Section titled “pdf2swf”Description:
| Method | Return values | Description |
|---|---|---|
| pdf2swf(InputStream is, String fileName) | InputStream | Retrieve the uploaded document converted to SWF format. |
The parameter fileName is the document file name. Application uses this parameter to identify by document extension the document MIME TYPE.
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/jllort/files/test.pdf"); FileOutputStream fos = new FileOutputStream("/home//files/out.swf"); InputStream convertedStream = ws.pdf2swf(is, "test.pdf"); IOUtils.copy(convertedStream, fos); is.close(); convertedStream.close(); fos.close(); } catch (Exception e) { e.printStackTrace(); } }}imageConvert
Section titled “imageConvert”Description:
| Method | Return values | Description |
|---|---|---|
| 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.
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(); } }}html2pdf
Section titled “html2pdf”Description:
| Method | Return values | Description |
|---|---|---|
| html2pdf(String url) | InputStream | Retrieve the PDF of an URL. |
Example:
package com.openkm;
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 { FileOutputStream fos = new FileOutputStream("/home/files/out.pdf"); InputStream is = ws.html2pdf("http://www.openkm.com"); IOUtils.copy(is, fos); is.close(); fos.close(); } catch (Exception e) { e.printStackTrace(); } }}doc2txt
Section titled “doc2txt”Description:
| Method | Return values | Description |
|---|---|---|
| doc2txt(InputStream is, String fileName) | String | Extracts the text from the upload document. |
Example:
package com.openkm;
import java.io.FileInputStream;import java.io.InputStream;
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"); System.out.println(ws.doc2txt(is, "test.docx")); is.close(); } catch (Exception e) { e.printStackTrace(); } }}img2txt
Section titled “img2txt”Description:
| Method | Return values | Description |
|---|---|---|
| img2txt(InputStream is, String fileName) | String | Extracts the text from the uploaded image. |
Example:
package com.openkm;
import java.io.FileInputStream;import java.io.InputStream;
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"); System.out.println(ws.img2txt(is, "test.png")); is.close(); } catch (Exception e) { e.printStackTrace(); } }}barcode2txt
Section titled “barcode2txt”Description:
| Method | Return values | Description |
|---|---|---|
| barcode2txt(InputStream is, String fileName) | String | Extracts the barcode text from the uploaded image. |
Example:
package com.openkm;
import java.io.FileInputStream;import java.io.InputStream;
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"); System.out.println(ws.barcode2txt(is, "test.png")); is.close(); } catch (Exception e) { e.printStackTrace(); } }}