OKMStamp

Methods

calculateStampCoordinates

Description:

MethodReturn valuesDescription

calculateStampCoordinates(String token, long imgToStampWidth, long imgToStampHeight, long floatingDivWidth,long floatingDivHeight, String exprX, String exprY, String stampType, String stampAlign)

StampCoordinates

Return the calculated stamp 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

The parameter stampAlign.

Available values:

  • text
  • image

The parameter stampAlign is the Text Align

Available values:

  • left
  • center
  • right

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

Description:

MethodReturn valuesDescription

calculateStampExpressions(String token, long imgToStampWidth, long imgToStampHeight, long posX, long posY)

StampExpressions

Return 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

Description:

MethodReturn valuesDescription

stampDocument(String token, long id, int type, String uuid)

void

Stamp the document

The parameter type.

  • Value 0 for type text
  • Value 1 for type image

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

Description:

MethodReturn valuesDescription

stampTextCustom(String token, String docId, long stId, String exprX, String exprY, String range, String text)

void

Stamp in a document with a custom text.

The id is the id of an image stamp which is created in 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.OKMDocument;
import com.openkm.util.ContextWrapper;

import java.io.FileInputStream;
import java.io.InputStream;

public class Test {

    public static void main(String[] args) {
        try {
            long stampTextId = 1;
            String text = "OpenKM";
            String exprX = "PAGE_CENTER";
            String exprY = "PAGE_MIDDLE";
            InputStream is = new FileInputStream("/home/gnujavasergio/okm/logo.png");
            OKMDocument okmDocument = ContextWrapper.getContext().getBean(OKMDocument.class);
            okmDocument.stampTextCustom(null, "05b14eee5-2e57-4d1d-925a-c9bc3f526e24", stampTextId, exprX, exprY, "", text);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

stampImageCustom

Description:

MethodReturn valuesDescription

void stampImageCustom(String token, String uuid, String 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

Description:

MethodReturn valuesDescription

void stampImageCustom(String token, String uuid, String 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 = 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

Description:

MethodReturn valuesDescription

getAllStamps(String token)

List<StampItem>

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();
            for (StampItem stampItem : result) {
                System.out.println(stampItem.getName());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getStampTextByPk

Description:

MethodReturn valuesDescription

getStampTextByPk(String token, long itemId, String docId)

StampText

Return the stamp Object by Id.

Example:

package com.openkm;

import com.openkm.api.OKMStamp;
import com.openkm.extension.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

Description:

MethodReturn valuesDescription

getStampImageByPk(String token, long id, String docId)

StampImage

Return the stamp Object by Id.

Example:

package com.openkm;

import com.openkm.api.OKMStamp;
import com.openkm.extension.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

Description:

MethodReturn valuesDescription

getStampBarcodeByPk(String token, long id, String docId)

StampBarcode

Return the stamp Object by Id.

Example:

package com.openkm;

import com.openkm.api.OKMStamp;
import com.openkm.extension.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

Description:

MethodReturn valuesDescription

calculateFlyImageDimensions(String token, String uuid, long imgToStampWidth, long imgToStampHeight,long floatingImageWidth, long floatingImageHeight, int pageNumber)

StampImageSize

Return 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

Description:

MethodReturn valuesDescription

getPersonalStamps(String token)

List<Document>

Returns a list of personal seals.

Return 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

Description:

MethodReturn valuesDescription

getPersonalStampImage(String token, String uuid, long id)

StampPersonalImage

Return the personal seal processed.

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;
            StampPersonalImage stampPersonalImage = okmStamp.getPersonalStampImage(null, "928de61e-6ceb-4f94-bf20-9ba2405c5cee", stampId);
            System.out.println(stampPersonalImage);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}