PDF samples
Basics
Section titled “Basics”Suggested code sample
Section titled “Suggested code sample”First, you must create the web service object:
OKMWebservices ws = OKMWebservicesFactory.newInstance(host);Then you should log in using the “login” method. You can access the “login” method from the web service object “ws” as shown below:
ws.login(user, password);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
Section titled “Methods”getImage
Section titled “getImage”Description:
| Method | Return values | Description |
|---|---|---|
| getImage(String uuid, int page, String size) | Stream | Returns the image of a page. |
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()); } } }}Description:
| Method | Return values | Description |
|---|---|---|
| split(String uuid, String dstId, String baseName, List |
List |
Returns true when the pages of the document have been split. |
The value of the uuid is the UUID of the document.
The value of baseName is the base name used to create split documents. For example, if the baseName value is “test” and the 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
Section titled “extract”Description:
| Method | Return values | Description |
|---|---|---|
| extract(String uuid, String dstId, String name, List |
Document | Returns a new document with the extracted pages. |
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); Documentresult = ws.pdf.extract("e7d6860a-7e0b-4823-bd3d-75f88be1eedf", "1ec49da9-1746-4875-ae32-9281d7303a62", "extract", pages); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}remove
Section titled “remove”Description:
| Method | Return values | Description |
|---|---|---|
| remove(String uuid, String dstId, String name, List |
Document | Returns true when the pages of the document have been removed. |
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
Section titled “rotate”Description:
| Method | Return values | Description |
|---|---|---|
| rotate(String uuid, String dstId, String name, int angle, List |
Document | Returns true when the pages of the document have been rotated. |
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
Section titled “insertPages”Description:
| Method | Return values | Description |
|---|---|---|
| insertPages(String uuid, InsertPagesRequest request) | Document | Returns the new document created with the inserted pages. |
The value of the uuid is the UUID of the target document where the pages will be inserted.
The value of the 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 pages**,** a 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 are 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
Section titled “optimize”Description:
| Method | Return values | Description |
|---|---|---|
| optimize(String uuid) | bool | Returns true when optimized successfully. |
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()); } } }}