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:

MethodReturn valuesDescription

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:

MethodReturn valuesDescription
split(String uuid, String dstId, String baseName, List<Integer> pages)

boolean

Return true when the pages of the document have been split.

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 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);
            boolean value = ws.pdf.split("e7d6860a-7e0b-4823-bd3d-75f88be1eedf", "0be057f1-efac-4e09-9c10-e7f27c731442", "split", pages);
            if (value) {
                System.out.println("split done");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

extract

Description:

MethodReturn valuesDescription

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:

MethodReturn valuesDescription

remove(String uuid, String dstId, String name, List<Integer> pages)

boolean

Return true when the pages of the document have been 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;

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);
            if (ws.pdf.extract("e7d6860a-7e0b-4823-bd3d-75f88be1eedf", "0be057f1-efac-4e09-9c10-e7f27c731442", "remove", pages)) {
                System.out.println("remove done");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

rotate

Description:

MethodReturn valuesDescription

rotate(String uuid, String dstId, String name, String angle, List<Integer> pages)

boolean

Return true when the pages of the document have been 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;

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