Stamp samples
Basics
Section titled “Basics”Suggested code sample
Section titled “Suggested code sample”First, you must create the web service object:
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);Then you should log in using the method “login”. 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 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:
package com.openkm;
import java.util.List;
import com.openkm.sdk4j.OKMWebservicesFactory;import com.openkm.sdk4j.bean.StampItem;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); List<StampItem> result = ws.stamp.getAllStamps(); for (StampItem stampItem : result) { System.out.println(stampItem.getName()); } } catch (Exception e) { e.printStackTrace(); } }}getStampTextByPk
Section titled “getStampTextByPk”Description:
| Method | Return values | Description |
|---|---|---|
| getStampTextByPk(long id, String uuid) | StampText | Returns the stamp of type Text by ID. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;import com.openkm.sdk4j.bean.StampText;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); int stampTextId = 1; StampText stampText = ws.stamp.getStampTextByPk(stampTextId, "928de61e-6ceb-4f94-bf20-9ba2405c5cee"); System.out.println(stampText); System.out.println(stampText.getName()); System.out.println(stampText.getDescription()); } catch (Exception e) { e.printStackTrace(); } }}getStampImageByPk
Section titled “getStampImageByPk”Description:
| Method | Return values | Description |
|---|---|---|
| getStampImageByPk(long id, String uuid) | StampImage | Returns the stamp of type image by ID. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;import com.openkm.sdk4j.bean.StampImage;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); int stampImageId = 3; StampImage stampImage = ws.stamp.getStampImageByPk(stampImageId, "928de61e-6ceb-4f94-bf20-9ba2405c5cee"); System.out.println(stampImage); System.out.println(stampImage.getName()); System.out.println(stampImage.getDescription()); } catch (Exception e) { e.printStackTrace(); } }}getStampBarcodeByPk
Section titled “getStampBarcodeByPk”Description:
| Method | Return values | Description |
|---|---|---|
| getStampBarcodeByPk(long id, String uuid) | StampBarcode | Returns the stamp of type barcode by ID. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;import com.openkm.sdk4j.bean.StampBarcode;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); int stampBarcodeId = 3; StampBarcode stampBarcode = ws.stamp.getStampBarcodeByPk(stampBarcodeId, "6330d2a0-529f-4c14-baa1-ce6a92004e01"); System.out.println(stampBarcode); System.out.println(stampBarcode.getName()); System.out.println(stampBarcode.getDescription()); } catch (Exception e) { e.printStackTrace(); } }}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:
package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;import com.openkm.sdk4j.bean.StampCoordinates;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); // Parameters long 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.out.println("X = " + stampCoordinates.getX() + ", Y = " + stampCoordinates.getY());
} catch (Exception e) { e.printStackTrace(); } }}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:
package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;import com.openkm.sdk4j.bean.StampExpressions;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); // Parameters long imgToStampWidth = 100; long imgToStampHeight = 100; long posX = 10; long posY = 50; StampExpressions stampExpressions = ws.stamp.calculateStampExpressions(imgToStampWidth, imgToStampHeight, posX, posY); System.out.println("X = " + stampExpressions.getExprX() + ", Y = " + stampExpressions.getExprY());
} catch (Exception e) { e.printStackTrace(); } }}stampText
Section titled “stampText”Description:
| Method | Return values | Description |
|---|---|---|
| stampText(String uuid, long id) | void | Stamps text in a document. |
Example:
package com.openkm;
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); long stampTextId = 1; ws.stamp.stampText("babe24df-c443-49a5-9453-39dfc9b27924", stampTextId); } catch (Exception e) { e.printStackTrace(); } }}stampImage
Section titled “stampImage”Description:
| Method | Return values | Description |
|---|---|---|
| stampImage(String uuid, long id) | void | Stamps an image in a document. |
Example:
package com.openkm;
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); long stampImageId = 1; ws.stamp.stampImage("babe24df-c443-49a5-9453-39dfc9b27924", stampImageId); } catch (Exception e) { e.printStackTrace(); } }}stampBarcode
Section titled “stampBarcode”Description:
| Method | Return values | Description |
|---|---|---|
| stampBarcode(String uuid, long id) | void | Stamps a barcode in a document. |
Example:
package com.openkm;
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); long stampBarcodeId = 1; ws.stamp.stampBarcode("f02053e3-2264-4040-bb84-67983a0208f7", stampBarcodeId); } catch (Exception e) { e.printStackTrace(); } }}stampImageManually
Section titled “stampImageManually”Description:
| Method | Return values | Description |
|---|---|---|
| stampImageManually(String uuid, long id, String exprX, String exprY, String range, String personalStampUuid) | void | Stamp a document with an image that is in OpenKM |
The id is the ID of an image stamp 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 the 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 on the page you can use:
| Expr. X | PAGE_CENTER |
| Expr. Y | PAGE_MIDDLE |
| ::: |
Example:
package com.openkm;
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); long id = 1; String exprX = "PAGE_CENTER - IMAGE_WIDTH / 2"; String exprY = "PAGE_MIDDLE - IMAGE_HEIGHT / 2"; ws.stamp.stampImageManually("055b5206-35d0-4351-ba92-c304bbba7ddf", id, exprX, exprY, "", "ac9cdfb4-8051-4458-a4bb-ca93e6cf464e"); } catch (Exception e) { e.printStackTrace(); } }}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 an image stamp 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:
package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;import com.openkm.sdk4j.impl.OKMWebservices;
import java.io.FileInputStream;import java.io.InputStream;
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); long stampTextId = 1; String text = "OpenKM"; String exprX = "PAGE_CENTER"; String exprY = "PAGE_MIDDLE"; InputStream is = new FileInputStream("/home/gnujavasergio/okm/logo.png"); ws.stamp.stampTextCustom("05b14eee5-2e57-4d1d-925a-c9bc3f526e24", stampTextId, text, exprX, exprY, ""); } catch (Exception e) { e.printStackTrace(); } }}stampImageCustom
Section titled “stampImageCustom”Description:
| Method | Return values | Description |
|---|---|---|
| stampImageCustom(String uuid, long id, String exprX, String exprY, String range, double ratio, InputStream is) | void | Stamp in a document with a custom image. |
The id is the ID of an image stamp 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 the 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 on the page you can use:
| Expr. X | PAGE_CENTER |
| Expr. Y | PAGE_MIDDLE |
| ::: |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;import com.openkm.sdk4j.impl.OKMWebservices;
import java.io.FileInputStream;import java.io.InputStream;
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); long id = 1; String exprX = "PAGE_CENTER - IMAGE_WIDTH / 2"; String exprY = "PAGE_MIDDLE - IMAGE_HEIGHT / 2"; InputStream is = new FileInputStream("/home/gnujavasergio/okm/logo.png"); ws.stamp.stampImageCustom("055b5206-35d0-4351-ba92-c304bbba7ddf", id, exprX, exprY, "", 0, is); } catch (Exception e) { e.printStackTrace(); } }}calculateFlyImageDimensions
Section titled “calculateFlyImageDimensions”Description:
| Method | Return values | Description |
|---|---|---|
| calculateFlyImageDimensions(String uuid, long imgToStampWidth, long imgToStampHeight, long floatingImageWidth, long floatingImageHeight, int pageNumber) |
StampImageSize | Returns the calculated height and width for the image to stamp. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;import com.openkm.sdk4j.bean.StampImageSize;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); // Parameters long 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.out.println(stampImageSize); } catch (Exception e) { e.printStackTrace(); } }}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:
package com.openkm;
import java.util.List;
import com.openkm.sdk4j.OKMWebservicesFactory;import com.openkm.sdk4j.bean.Document;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); List<Document> result = ws.stamp.getPersonalStamps(); for (Document doc : result) { System.out.println(doc); } } catch (Exception e) { e.printStackTrace(); } }}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:
package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;import com.openkm.sdk4j.bean.StampPersonalImage;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); long stampId = 1; StampPersonalImage stampPersonalImage = ws.stamp.getPersonalStampImage("928de61e-6ceb-4f94-bf20-9ba2405c5cee", stampId); System.out.println(stampPersonalImage); } catch (Exception e) { e.printStackTrace(); } }}