OKMStamp
Methods
Section titled “Methods”calculateStampCoordinates
Section titled “calculateStampCoordinates”Description:
| Method | Return values | Description |
|---|---|---|
| calculateStampCoordinates(String token, long imgToStampWidth, long imgToStampHeight, long floatingDivWidth,long floatingDivHeight, String exprX, String exprY, String stampType, String stampAlign) | StampCoordinates | Returns the calculated stamp coordinates. |
Available values:
- left
- center
- right
- The parameter stampAlign.
- The parameter stampAlign is the text alignment
Example:
package com.openkm;
import com.openkm.api.OKMStamp;import com.openkm.util.ContextWrapper;import com.openkm.ws.rest.util.StampCoordinates;
public class Test {
public static void main(String[] args) { try { OKMStamp okmStamp = ContextWrapper.getContext().getBean(OKMStamp.class); // 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 = okmStamp.calculateStampCoordinates(null, 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(String token, 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.api.OKMStamp;import com.openkm.util.ContextWrapper;import com.openkm.ws.rest.util.StampExpressions;
public class Test {
public static void main(String[] args) { try { OKMStamp okmStamp = ContextWrapper.getContext().getBean(OKMStamp.class); // Parameters long imgToStampWidth = 100; long imgToStampHeight = 100; long posX = 10; long posY = 50; StampExpressions stampExpressions = okmStamp.calculateStampExpressions(null, imgToStampWidth, imgToStampHeight, posX, posY); System.out.println("X = " + stampExpressions.getExprX() + ", Y = " + stampExpressions.getExprY()); } catch (Exception e) { e.printStackTrace(); } }}stampDocument
Section titled “stampDocument”Description:
| Method | Return values | Description |
|---|---|---|
| stampDocument(String token, long id, int type, String uuid) | void | Stamps the document. |
- Value 0 for text type
- Value 1 for image type
- The parameter type.
Example:
package com.openkm;
import com.openkm.api.OKMStamp;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMStamp okmStamp = ContextWrapper.getContext().getBean(OKMStamp.class); long stampId = 1; okmStamp.stampDocument(null, stampId, 1, "babe24df-c443-49a5-9453-39dfc9b27924"); } catch (Exception e) { e.printStackTrace(); } }}stampTextCustom
Section titled “stampTextCustom”Description:
| Method | Return values | Description |
|---|---|---|
| stampTextCustom(String token, String docId, long stId, String exprX, String exprY, String range, String text) | void | Stamp a document with custom text. |
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:
package com.openkm;
import com.openkm.api.OKMStamp;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMStamp okmStamp = ContextWrapper.getContext().getBean(OKMStamp.class); long stampTextId = 1; String text = "OpenKM"; String exprX = "PAGE_CENTER"; String exprY = "PAGE_MIDDLE"; okmStamp.stampTextCustom(null, "05b14eee-2e57-4d1d-925a-c9bc3f526e24", stampTextId, exprX, exprY, "", text); } catch (Exception e) { e.printStackTrace(); } }}stampImageCustom
Section titled “stampImageCustom”Description:
| Method | Return values | Description |
|---|---|---|
| stampImageCustom(String token, String uuid, long id, String exprX, String exprY, String range, String personalStampUuid) | void | Stamp a document with a custom image. |
The personalStampUuid must be a valid document UUID. The document must be an image (jpg or png).
Example:
package com.openkm;
import com.openkm.api.OKMStamp;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMStamp okmStamp = ContextWrapper.getContext().getBean(OKMStamp.class); long stampId = 3; String exprX = "PAGE_CENTER - IMAGE_WIDTH / 2"; String exprY = "PAGE_MIDDLE - IMAGE_HEIGHT / 2"; okmStamp.stampImageCustom(null, "babe24df-c443-49a5-9453-39dfc9b27924", stampId, exprX, exprY, "", "928de61e-6ceb-4f94-bf20-9ba2405c5cee"); } catch (Exception e) { e.printStackTrace(); } }}stampImageCustom
Section titled “stampImageCustom”Description:
| Method | Return values | Description |
|---|---|---|
| stampImageCustom(String token, String uuid, long id, String exprX, String exprY, String range, byte[] image) | void | Stamp a document with a custom image. |
The image must be an image (jpg or png).
Example:
package com.openkm;
import com.openkm.api.OKMStamp;import com.openkm.util.ContextWrapper;import org.apache.commons.io.*;import java.io.*;
public class Test {
public static void main(String[] args) { try { OKMStamp okmStamp = ContextWrapper.getContext().getBean(OKMStamp.class); InputStream is = new FileInputStream("/home/test/image.png"); byte[] image = IOUtils.toByteArray(is); long stampId = 3; String exprX = "PAGE_CENTER - IMAGE_WIDTH / 2"; String exprY = "PAGE_MIDDLE - IMAGE_HEIGHT / 2"; okmStamp.stampImageCustom(null, "babe24df-c443-49a5-9453-39dfc9b27924", stampId, exprX, exprY, "", image); } catch (Exception e) { e.printStackTrace(); } }}getAllStamps
Section titled “getAllStamps”Description:
| Method | Return values | Description |
|---|---|---|
| getAllStamps(String token) | List |
Returns a list of stamps. |
Example:
package com.openkm;
import java.util.List;
import com.openkm.api.OKMStamp;import com.openkm.util.ContextWrapper;import com.openkm.ws.rest.util.StampItem;
public class Test {
public static void main(String[] args) { try { OKMStamp okmStamp = ContextWrapper.getContext().getBean(OKMStamp.class); List<StampItem> result = okmStamp.getAllStamps(null); for (StampItem stampItem : result) { System.out.println(stampItem.getName()); } } catch (Exception e) { e.printStackTrace(); } }}getStampTextByPk
Section titled “getStampTextByPk”Description:
| Method | Return values | Description |
|---|---|---|
| getStampTextByPk(String token, long itemId, String docId) | StampText | Returns the stamp object by id. |
Example:
package com.openkm;
import com.openkm.api.OKMStamp;import com.openkm.db.bean.StampText;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMStamp okmStamp = ContextWrapper.getContext().getBean(OKMStamp.class); int stampId = 1; StampText stampText = okmStamp.getStampTextByPk(null, stampId, "928de61e-6ceb-4f94-bf20-9ba2405c5cee"); 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(String token, long id, String docId) | StampImage | Returns the stamp object by id. |
Example:
package com.openkm;
import com.openkm.api.OKMStamp;import com.openkm.db.bean.StampImage;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMStamp okmStamp = ContextWrapper.getContext().getBean(OKMStamp.class); int stampId = 3; StampImage stampImage = okmStamp.getStampImageByPk(null, stampId, "928de61e-6ceb-4f94-bf20-9ba2405c5cee"); 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(String token, long id, String docId) | StampBarcode | Returns the stamp object by id. |
Example:
package com.openkm;
import com.openkm.api.OKMStamp;import com.openkm.db.bean.StampBarcode;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMStamp okmStamp = ContextWrapper.getContext().getBean(OKMStamp.class); int stampId = 3; StampBarcode stampBarcode = okmStamp.getStampBarcodeByPk(null, stampId, "928de61e-6ceb-4f94-bf20-9ba2405c5cee"); System.out.println(stampBarcode.getName()); System.out.println(stampBarcode.getDescription()); } catch (Exception e) { e.printStackTrace(); } }}calculateFlyImageDimensions
Section titled “calculateFlyImageDimensions”Description:
| Method | Return values | Description |
|---|---|---|
| calculateFlyImageDimensions(String token, String uuid, long imgToStampWidth, long imgToStampHeight,long floatingImageWidth, long floatingImageHeight, int pageNumber) | StampImageSize | Returns the calculated image dimensions of the stamp. |
Example:
package com.openkm;
import com.openkm.api.OKMStamp;import com.openkm.util.ContextWrapper;import com.openkm.ws.rest.util.StampImageSize;
public class Test {
public static void main(String[] args) { try { OKMStamp okmStamp = ContextWrapper.getContext().getBean(OKMStamp.class); // Parameters long imgToStampWidth = 100; long imgToStampHeight = 100; long floatingImageWidth = 300; long floatingImageHeight = 300; int pageNumber = 2;
StampImageSize stampImageSize = okmStamp.calculateFlyImageDimensions(null, "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(String token) | 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.api.OKMStamp;import com.openkm.bean.Document;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMStamp okmStamp = ContextWrapper.getContext().getBean(OKMStamp.class); List<Document> result = okmStamp.getPersonalStamps(null); for (Document doc : result) { System.out.println(doc); } } catch (Exception e) { e.printStackTrace(); } }}getPersonalStampImage
Section titled “getPersonalStampImage”Description:
| Method | Return values | Description |
|---|---|---|
| getPersonalStampImage(String token, String docId, String imgId, long id) | StampPersonalImage | Returns the processed personal seal. |
When stamping a document with an image, the image also can have a text layer.
This method processes the image and returns an image with the text layer.
The uuid must be one of the values returned by the method getPersonalStamps.
Example:
package com.openkm;
import com.openkm.api.OKMStamp;import com.openkm.util.ContextWrapper;import com.openkm.ws.rest.util.StampPersonalImage;
public class Test {
public static void main(String[] args) { try { OKMStamp okmStamp = ContextWrapper.getContext().getBean(OKMStamp.class); long stampId = 1; String imgId = ""; // stamp image id StampPersonalImage stampPersonalImage = okmStamp.getPersonalStampImage(null, "928de61e-6ceb-4f94-bf20-9ba2405c5cee", imgId, stampId); System.out.println(stampPersonalImage); } catch (Exception e) { e.printStackTrace(); } }}