PDF samples

Basics

Suggested code sample

First, you must create the webservice object:

OKMWebservices ws = OKMWebservicesFactory.newInstance(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:

Stream stream = ws.pdf.getImage("e7d6860a-7e0b-4823-bd3d-75f88be1eedf", 1);

Methods

getImage

Description:

MethodReturn valuesDescription

getImage(String uuid, int page, String size)

Stream

Returns the image of a page.


The document must be a PDF or convertible to PDF.

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:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.bean;

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 stream = ws.pdf.getImage("1ec49da9-1746-4875-ae32-9281d7303a62", 1, null);
FileStream destFile = new FileStream("D:\\test.png", FileMode.OpenOrCreate, FileAccess.ReadWrite);
stream.CopyTo(destFile);
destFile.Close();
stream.Close();
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}

split

Description:

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

bool

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:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.bean;

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);
List<int> pages = new List<int>();
pages.Add(5);
pages.Add(10);
bool result = ws.pdf.split("e7d6860a-7e0b-4823-bd3d-75f88be1eedf", "1ec49da9-1746-4875-ae32-9281d7303a62", "split", pages);
if(result)
{
System.Console.Writeline("Split done");
}
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}

extract

Description:

MethodReturn valuesDescription

extract(String uuid, String dstId, String name, List<int> pages)

bool

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:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.bean;

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);
List<int> pages = new List<int>();
pages.Add(5);
pages.Add(10);
bool result = ws.pdf.extract("e7d6860a-7e0b-4823-bd3d-75f88be1eedf", "1ec49da9-1746-4875-ae32-9281d7303a62", "extract", pages);
if(result)
{
System.Console.Writeline("Extract done");
}
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}

remove

Description:

MethodReturn valuesDescription

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

bool

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:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.bean;

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);
List<int> pages = new List<int>();
pages.Add(5);
pages.Add(10);
bool result = ws.pdf.remove("e7d6860a-7e0b-4823-bd3d-75f88be1eedf", "1ec49da9-1746-4875-ae32-9281d7303a62", "remove", pages);
if(result)
{
System.Console.Writeline("Remove done");
}
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}

rotate

Description:

MethodReturn valuesDescription

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

bool

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:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.bean;

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);
List<int> pages = new List<int>();
pages.Add(5);
pages.Add(10);
bool result = ws.pdf.rotate("e7d6860a-7e0b-4823-bd3d-75f88be1eedf", "1ec49da9-1746-4875-ae32-9281d7303a62", "rotate", 180, pages);
if(result)
{
System.Console.Writeline("Rotate done");
}
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}

insertPages

Description:

MethodReturn valuesDescription

insertPages(String uuid, String srcId, int sourceFromPage, int sourceToPage, int insertFromPage)

bool

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


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 srcId is the UUID of the source document.

The value of sourceFromPage indicates from which page number of the source document will be inserted into the document.

The value of sourceToPage indicates up to which page number of the source document is to be inserted into the document.

The value of insertFromPage indicates from which page number the pages will be inserted into the document.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.bean;

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);
List<int> pages = new List<int>();
pages.Add(5);
pages.Add(10);
bool result = ws.pdf.insertPages("e7d6860a-7e0b-4823-bd3d-75f88be1eedf", "1ec49da9-1746-4875-ae32-9281d7303a62", 5, 10, 1);
if(result)
{
System.Console.Writeline("Insert pages done");
}
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}