PDF samples
Basics
Suggested code sample
First, you must create the webservice object:
OKMWebservices ws = OKMWebservicesFactory.getInstance(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 kept in the webservice Object. Then you can use the other API method
At this point you can use all the Pdf methods from "pdf" class as is shown below:
InputStream is = ws.pdf.getImage("e7d6860a-7e0b-4823-bd3d-75f88be1eedf", 1);
Methods
getImage
Description:
Method | Return values | Description |
---|---|---|
getImage(String uuid, int page, String size) |
InputStream |
Returns the image of a page. |
The document must be a PDF or convertible to PDF. The default value of size parameter is "150". The value is in pixels. The value of the uuid is the UUID of the document. The page is the number of the page in the document starting from the value "1". The size value is optional. When set is used to resize the image of the page, otherwise is used the default value. |
Example:
package com.openkm;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.commons.io.IOUtils;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
InputStream is = ws.pdf.getImage("e7d6860a-7e0b-4823-bd3d-75f88be1eedf", 1, null);
OutputStream fos = new FileOutputStream("/home/openkm/page-1.png");
IOUtils.copy(is, fos);
IOUtils.closeQuietly(is);
IOUtils.closeQuietly(fos);
} catch (Exception e) {
e.printStackTrace();
}
}
}
split
Description:
Method | Return values | Description |
---|---|---|
split(String uuid, String dstId, String baseName, List<Integer> pages) |
List<Document> |
Return a list of documents of the splitter pages. |
The document must be a PDF or convertible to PDF. The value of the uuid is the UUID of the document. The value of baseName is the base name to create a split document, for example, if baseName value is "test" and pages value is "1,3", the files created will be "test-001.pdf" and "test-003.pdf". The value of pages is the number of pages to be split. |
Example:
package com.openkm;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import com.openkm.sdk4j.bean.*;
import org.apache.commons.io.IOUtils;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String username = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(username, password);
List<Integer> pages = new ArrayList<>();
pages.add(2);
pages.add(3);
List<Document> documents = ws.pdf.split("e7d6860a-7e0b-4823-bd3d-75f88be1eedf", "0be057f1-efac-4e09-9c10-e7f27c731442", "split", pages);
System.out.println(documents);
} catch (Exception e) {
e.printStackTrace();
}
}
}
extract
Description:
Method | Return values | Description |
---|---|---|
extract(String uuid, String dstId, String name, List<Integer> pages) |
boolean |
Return true when the chosen pages of the document have been extracted. |
The document must be a PDF or convertible to PDF. The value of the uuid is the UUID of the document. The value of the dstId is the UUID of the destination ( folder or record ). The value of name is the name of the new document with extracted pages. The value of pages is the number of pages to be extracted. |
Example:
package com.openkm;
import java.util.ArrayList;
import java.util.List;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;
public class PdfExample {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String username = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(username, password);
//extract
List<Integer> pages = new ArrayList<>();
pages.add(2);
pages.add(3);
if (ws.pdf.extract("e7d6860a-7e0b-4823-bd3d-75f88be1eedf", "0be057f1-efac-4e09-9c10-e7f27c731442", "extract", pages)) {
System.out.println("extract done");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
remove
Description:
Method | Return values | Description |
---|---|---|
remove(String uuid, String dstId, String name, List<Integer> pages) |
Document |
Return a new document with the pages removed |
The document must be a PDF or convertible to PDF. The value of the uuid is the UUID of the document. The value of the dstId is the UUID of the destination ( folder or record ). The value of name is the name of the new document with extracted pages. The value of pages is the number of pages to be removed. |
Example:
package com.openkm;
import java.util.ArrayList;
import java.util.List;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;
import com.openkm.sdk4j.bean.*;
public class PdfExample {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String username = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(username, password);
// remove
List<Integer> pages = new ArrayList<>();
pages.add(2);
pages.add(3);
Document document = ws.pdf.extract("e7d6860a-7e0b-4823-bd3d-75f88be1eedf", "0be057f1-efac-4e09-9c10-e7f27c731442", "remove", pages);
System.out.println(document);
} catch (Exception e) {
e.printStackTrace();
}
}
}
rotate
Description:
Method | Return values | Description |
---|---|---|
rotate(String uuid, String dstId, String name, String angle, List<Integer> pages) |
Document |
Return a new document with the pages rotated |
The document must be a PDF or convertible to PDF. The value of the uuid is the UUID of the document. The value of the dstId is the UUID of the destination ( folder or record ). The value of name is the name of the new document with extracted pages. The value of angle is rotation applied in the chosen pages.. The value of pages is the number of pages to be rotated. |
Example:
package com.openkm;
import java.util.ArrayList;
import java.util.List;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;
import com.openkm.sdk4j.bean.*;
public class PdfExample {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String username = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(username, password);
// rotate
List<Integer> pages = new ArrayList<>();
pages.add(2);
pages.add(3);
Document document = ws.pdf.rotate("e7d6860a-7e0b-4823-bd3d-75f88be1eedf", "0be057f1-efac-4e09-9c10-e7f27c731442", "rotate", "180", pages);
System.out.println("rotation done");
} catch (Exception e) {
e.printStackTrace();
}
}
}
insertPages
Description:
Method | Return values | Description |
---|---|---|
insertPages(String uuid, String srcId, int sourceFromPage, int sourceToPage, int insertFromPage) |
boolean |
Returns true when the pages have been inserted into the document. |
The document must be a PDF or convertible to PDF. The value of the uuid is the UUID of the target document where the pages will be inserted. The value of srcId is the UUID of the source document from which the pages will be extracted. The value of sourceFromPage is the starting page number in the source document for page extraction. The value of sourceToPage is the ending page number in the source document for page extraction. Extraction is inclusive of this page. The value of insertFromPage is the page number in the target document where the extracted pages will be inserted. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;
public class PdfExample {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String username = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(username, password);
ws.pdf.insertPages("6a54d98b-6454-4484-8172-8359a2b4f2f2", "a573da75-ba1e-4f5b-98d2-fbb7da5f1cf1", 1, 3, 1);
} catch (Exception e) {
e.printStackTrace();
}
}
}
optimize
Description:
Method | Return values | Description |
---|---|---|
optimize(String uuid) |
boolean |
returns true when optimized successfully |
The uuid of the node must be a PDF document. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
boolean success = ws.pdf.optimize("cd4f69ed-e517-408b-b7eb-95cfe371ecba");
System.out.println("optimize success: " + success);
} catch (Exception e) {
e.printStackTrace();
}
}
}