PDF samples

Basics

Suggested code sample

First, you must create the webservice object:

OKMWebservices ws = OKMWebservicesFactory.newInstance(host);

Then you should log in using the "login" method. You can access the "login" method from the webservice object "ws" as shown below:

ws.login(user, password);

Once you are logged in to the web service, the session is kept in the webservice object. Then you can use the other API methods.

At this point you can use all the PDF methods from the "pdf" class as 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 at 1.

The size value is optional. When set, it is used to resize the image of the page; otherwise, the default value is used.

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)

List<Document>

Returns the split documents.


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);
List<Document> docs = ws.pdf.split("e7d6860a-7e0b-4823-bd3d-75f88be1eedf", "1ec49da9-1746-4875-ae32-9281d7303a62", "split", pages);
foreach(Document doc in docs)
{
System.Console.Writeline(doc.toString());
}
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}

extract

Description:

MethodReturn valuesDescription

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

Document

Returns a new document with the extracted 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 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);
Document result = ws.pdf.extract("e7d6860a-7e0b-4823-bd3d-75f88be1eedf", "1ec49da9-1746-4875-ae32-9281d7303a62", "extract", pages);
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}

remove

Description:

MethodReturn valuesDescription

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

Document

Returns the 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:

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);
Document doc = ws.pdf.remove("e7d6860a-7e0b-4823-bd3d-75f88be1eedf", "1ec49da9-1746-4875-ae32-9281d7303a62", "remove", pages);
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}

rotate

Description:

MethodReturn valuesDescription

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

Document

Returns the 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 the rotation applied to 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);
Document doc = ws.pdf.rotate("e7d6860a-7e0b-4823-bd3d-75f88be1eedf", "1ec49da9-1746-4875-ae32-9281d7303a62", "rotate", 180, pages);
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}

insertPages

Description:

MethodReturn valuesDescription

insertPages(String uuid,  InsertPagesRequest  request)

Document

Returns the new document created with the inserted pages.


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 InsertPagesRequest is an object that has a List of PageInsertOperation named insertOperations, a String dstId, that contains the UUID of the destination folder, and a String name for the newly generated document.

PageInsertOperation object has a String srcId, the UUID of the source file of the pagesa List of Integer named pages that stores the positions of the pages in the source PDF, and an int insertFromPage, the position where the pages have to be located in the target PDF.

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);

// Create the insert pages request
InsertPagesRequest request = new InsertPagesRequest();
request.name = "merged_document.pdf"; // Name for the new document
request.dstId = fld.uuid;

// Create a page insertion operation
PageInsertOperation operation = new PageInsertOperation();
operation.srcId = srcDoc.uuid; // Source document UUID
operation.pages = new List<int> { 1, 2, 3 }; // Pages to insert from source
operation.insertFromPage = 1; // Insert at position 1 in target document

request.insertOperations.Add(operation);

// Call insertPages with target document UUID and request
Document result = ws.pdf.insertPages(srcDoc.uuid, request);

System.Console.Writeline("New document created: " + result.uuid);
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}

optimize

Description:

MethodReturn valuesDescription
optimize(String uuid)

bool

Returns true when optimized successfully.


The UUID of the node must be a PDF 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); ;
bool result = ws.pdf.optimize("e7d6860a-7e0b-4823-bd3d-75f88be1eedf");
System.Console.Writeline("Optimize success: "+ result);
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}