Stamp samples
Basics
Section titled “Basics”Suggested code sample
Section titled “Suggested code sample”First, you must create the webservice object:
OKMWebservices ws = OKMWebservicesFactory.newInstance(host);Then you should log in using the method “login”. You can access the “login” method from the webservice object “ws” as shown below:
ws.login(user, password);At this point you can use all the Stamp methods from the “stamp class” as shown below:
ws.stamp.getAllStamps();Methods
Section titled “Methods”getAllStamps
Section titled “getAllStamps”Description:
| Method | Return values | Description |
|---|---|---|
| getAllStamps() | List |
Returns a list of stamp items. |
Example:
using System; using System.Collections.Generic;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<StampItem> stamps = ws.stamp.getAllStamps();foreach(StampItem stamItem in stamps){System.Console.WriteLine(stamItem.name);}}catch (Exception e){System.Console.WriteLine(e.ToString());
}}}}testGetStampTextByPk
Section titled “testGetStampTextByPk”Description:
| Method | Return values | Description |
|---|---|---|
| getStampTextByPk(long id, String uuid) | StampText | Returns the stamp of type Text by ID. |
Example:
using System; using System.Collections.Generic;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);long id = 1;List<StampItem> stamps = ws.stamp.getStampTextByPk(id, document.uuid);System.Console.WriteLine(stamp.name);System.Console.WriteLine(stamp.description);}catch (Exception e){System.Console.WriteLine(e.ToString());
}}}}getStampImageByPk
Section titled “getStampImageByPk”Description:
| Method | Return values | Description |
|---|---|---|
| getStampImageByPk(long id, String uuid) | StampImage | Returns the stamp of type Image by ID. |
Example:
using System;using System.Collections.Generic;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);long id = 1;List<StampItem> stamps = ws.stamp.getStampImageByPk(id, document.uuid);System.Console.WriteLine(stampImage.name);System.Console.WriteLine(stampImage.description);}catch (Exception e){System.Console.WriteLine(e.ToString());
}}}}getStampBarcodeByPk
Section titled “getStampBarcodeByPk”Description:
| Method | Return values | Description |
|---|---|---|
| getStampBarcodeByPk(long id, String uuid) | StampBarcode | Returns the stamp of type Barcode by ID. |
Example:
using System;using System.Collections.Generic;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);long id = 1;StampBarcode stampBarcode = ws.stamp.getStampBarcodeByPk(id, "6330d2a0-529f-4c14-baa1-ce6a92004e01");System.Console.WriteLine(stampBarcode.name);System.Console.WriteLine(stampBarcode.description);}catch (Exception e){System.Console.WriteLine(e.ToString());
}}}}calculateStampCoordinates
Section titled “calculateStampCoordinates”Description:
| Method | Return values | Description |
|---|---|---|
| calculateStampCoordinates(long imgToStampWidth, long imgToStampHeight, long floatingDivWidth, long floatingDivHeight, String exprX, String exprY, String stampType, String stampAlign) |
StampCoordinates | Returns the calculated stamp coordinates. |
The parameter stampAlign is the text alignment.
Available values:
- left
- center
- right
Example:
using System; using System.Collections.Generic;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);// Parameterslong imgToStampWidth = 100;long imgToStampHeight = 100;long floatingDivWidth = 250;long floatingDivHeight = 300;string exprX = "PAGE_CENTER - IMAGE_WIDTH / 2";string exprY = "PAGE_MIDDLE - IMAGE_HEIGHT / 2";string stampType = "text";string stampAlign = "center";StampCoordinates stampCoordinates = ws.stamp.calculateStampCoordinates(imgToStampWidth, imgToStampHeight,floatingDivWidth, floatingDivHeight, exprX, exprY, stampType, stampAlign);System.Console.WriteLine("X = " + stampCoordinates.x + ", Y = " + stampCoordinates.y);}catch (Exception e){System.Console.WriteLine(e.ToString());
}}}}calculateStampExpressions
Section titled “calculateStampExpressions”Description:
| Method | Return values | Description |
|---|---|---|
| calculateStampExpressions(long imgToStampWidth, long imgToStampHeight, long posX, long posY) | StampExpressions | Returns the calculated stamp expressions for X and Y. |
Example:
using System; using System.Collections.Generic;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);// Parameterslong imgToStampWidth = 100;long imgToStampHeight = 100;long posX = 10;long posY = 50;StampExpressions stampExpressions = ws.stamp.calculateStampExpressions(imgToStampWidth, imgToStampHeight, posX, posY);System.Console.WriteLine("X = " + stampExpressions.exprX + ", Y = " + stampExpressions.exprY);}catch (Exception e){System.Console.WriteLine(e.ToString());
}}}}stampText
Section titled “stampText”Description:
| Method | Return values | Description |
|---|---|---|
| stampText(String uuid, long id) | void | Stamps text in a document. |
Example:
using System; using System.Collections.Generic;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);long id = "1";ws.stamp.stampText("babe24df-c443-49a5-9453-39dfc9b27924", id);}catch (Exception e){System.Console.WriteLine(e.ToString());
}}}}stampImage
Section titled “stampImage”Description:
| Method | Return values | Description |
|---|---|---|
| stampImage(String uuid, long id) | void | Stamps an image in a document. |
Example:
using System; using System.Collections.Generic;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);long id = "3";ws.stamp.stampImage("babe24df-c443-49a5-9453-39dfc9b27924", id);}catch (Exception e){System.Console.WriteLine(e.ToString());
}}}}stampBarcode
Section titled “stampBarcode”Description:
| Method | Return values | Description |
|---|---|---|
| stampBarcode(String uuid, long id) | void | Stamps a barcode in a document. |
Example:
using System; using System.Collections.Generic;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);long id = 1;ws.stamp.stampBarcode("6330d2a0-529f-4c14-baa1-ce6a92004e01", id);}catch (Exception e){System.Console.WriteLine(e.ToString());
}}}}stampImageManually
Section titled “stampImageManually”Description:
| Method | Return values | Description |
|---|---|---|
| stampImageCustom(String uuid, long id, String exprX, String exprY, String range, String personalStampUuid) | void | Stamps a document with a custom image. |
The id is the ID of an image stamp which is created by the administrator.
The exprX is the expression to set the position in X coordinates.
The exprY is the expression to set the position in Y coordinates.
The personalStampUuid must be a valid document UUID. The document must be an image (jpg or png).
In Expr. X and Expr. Y input fields you can put more than a simple number. Currently, the following macros are defined:
- IMAGE_WIDTH
- IMAGE_HEIGHT
- PAGE_WIDTH
- PAGE_HEIGHT
- PAGE_CENTER
- PAGE_MIDDLE
So to center a stamp in the page you can use:
| Expr. X | PAGE_CENTER |
| Expr. Y | PAGE_MIDDLE |
| ::: |
Example:
using System; using System.Collections.Generic;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);long stampId = "1";string exprX = "PAGE_CENTER - IMAGE_WIDTH / 2";string exprY = "PAGE_MIDDLE - IMAGE_HEIGHT / 2";ws.stamp.stampImageCustom("babe24df-c443-49a5-9453-39dfc9b27924", stampId, exprX, exprY, "", "928de61e-6ceb-4f94-bf20-9ba2405c5cee");}catch (Exception e){System.Console.WriteLine(e.ToString());
}}}}stampTextCustom
Section titled “stampTextCustom”Description:
| Method | Return values | Description |
|---|---|---|
| stampTextCustom(String uuid, long id, String text, String exprX, String exprY, String range) | void | Stamp in a document with a custom text. |
The id is the ID of a text stamp which is created by the administrator.
The exprX is the expression to set the position in X coordinates.
The exprY is the expression to set the position in Y coordinates.
In Expr. X and Expr. Y input fields you can put more than a simple number. Currently, the following macros are defined:
- IMAGE_WIDTH
- IMAGE_HEIGHT
- PAGE_WIDTH
- PAGE_HEIGHT
- PAGE_CENTER
- PAGE_MIDDLE
So to center a stamp in the page you can use:
| Expr. X | PAGE_CENTER |
| Expr. Y | PAGE_MIDDLE |
| ::: |
Example:
using System; using System.Collections.Generic;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);long stampId = "1";string text = "Any text";string exprX = "PAGE_CENTER";string exprY = "PAGE_MIDDLE";ws.stamp.stampTextCustom("babe24df-c443-49a5-9453-39dfc9b27924", stampId, text, exprX, exprY, "");}catch (Exception e){System.Console.WriteLine(e.ToString());
}}}}stampImageCustom
Section titled “stampImageCustom”Description:
| Method | Return values | Description |
|---|---|---|
| stampImageCustom(String uuid, long id, String exprX, String exprY, String range, double ratio, FileStream fs) | void | Stamp in a document with a custom image. |
The id is the ID of an image stamp which is created by the administrator.
The exprX is the expression to set the position in X coordinates.
The exprY is the expression to set the position in Y coordinates.
In Expr. X and Expr. Y input fields you can put more than a simple number. Currently, the following macros are defined:
- IMAGE_WIDTH
- IMAGE_HEIGHT
- PAGE_WIDTH
- PAGE_HEIGHT
- PAGE_CENTER
- PAGE_MIDDLE
So to center a stamp in the page you can use:
| Expr. X | PAGE_CENTER |
| Expr. Y | PAGE_MIDDLE |
| ::: |
Example:
using System; using System.Collections.Generic;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);long stampId = "1";string exprX = "PAGE_CENTER - IMAGE_WIDTH / 2";string exprY = "PAGE_MIDDLE - IMAGE_HEIGHT / 2";FileStream fsimg = new FileStream(@"C:\test.jpg", FileMode.Open, FileAccess.Read);ws.stamp.stampImageCustom("babe24df-c443-49a5-9453-39dfc9b27924", stampId, exprX, exprY, "", 0, fsimg);fsimg.Close();}catch (Exception e){System.Console.WriteLine(e.ToString());}}}}calculateFlyImageDimensions
Section titled “calculateFlyImageDimensions”Description:
| Method | Return values | Description |
|---|---|---|
| calculateFlyImageDimensions(String uuid, long imgToStampWidth, long imgToStampHeight, long floatingImageWidth, long floatingImageHeight, int pageNumber) |
StampImageSize | Return the calculated image to stamp height and width size. |
Example:
using System; using System.Collections.Generic;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);// Parameterslong imgToStampWidth = 100;long imgToStampHeight = 100;long floatingImageWidth = 300;long floatingImageHeight = 300;int pageNumber = 2;
StampImageSize stampImageSize = ws.stamp.calculateFlyImageDimensions("babe24df-c443-49a5-9453-39dfc9b27924", imgToStampWidth, imgToStampHeight,floatingImageWidth, floatingImageHeight, pageNumber);System.Console.WriteLine(stampImageSize);}catch (Exception e){System.Console.WriteLine(e.ToString());
}}}}getPersonalStamps
Section titled “getPersonalStamps”Description:
| Method | Return values | Description |
|---|---|---|
| getPersonalStamps() | List |
Returns a list of personal seals. |
Returns a list of documents of type image (jpg or png) from /okm:templates/userId/stamps.
Example:
using System; using System.Collections.Generic;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<Document> docs = ws.stamp.getPersonalStamps();foreach (Document doc in docs){System.Console.WriteLine(doc.toString());}}catch (Exception e){System.Console.WriteLine(e.ToString());
}}}}getPersonalStampImage
Section titled “getPersonalStampImage”Description:
| Method | Return values | Description |
|---|---|---|
| getPersonalStampImage(String uuid, long id) | StampPersonalImage | Returns the processed personal seal. |
When stamping a document with an image, the image can also have a text layer.
This method processes the image and returns an image with the text layer.
The uuid must be a UUID returned by the method getPersonalStamps.
Example:
using System; using System.Collections.Generic;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);long stampId = 1;StampPersonalImage stampPersonalImage = ws.stamp.getPersonalStampImage("928de61e-6ceb-4f94-bf20-9ba2405c5cee", stampId);System.Console.WriteLine(stampPersonalImage.ToString());}catch (Exception e){System.Console.WriteLine(e.ToString());
}}}}