Breadcrumbs

signoAPI Android – STSignoUtils class

The STSignoUtils class is a Utility class in the libSignoPDFSigner and consists of static methods. This class can be used to edit the PDF documents and to create new PDF documents without displaying them. The class is part of libSignoPDFSigner.

appendPage method

This method can be used to append a blank page to a document. Images can be inserted on this page if desired.

Java
public static byte[] appendPage(STRectDTO size, byte[] document, List<STImageDTO> images);

Parameter

Description

STRectDTO size

The size of the new page.

byte[] document

The document as a byte array.

List<STImageDTO> images

A list of STImageDTO objects. May be null, in which case no images are added.

Return value

Description

byte[]

The changed document as a byte array.

Usage:

Java
STRectDTO size = new STRectDTO();
size.setUnit(STRectDTO.Unit. UnitMillimetres);
size.setRectangle(new RectF(0.0f, 0.0f, 210.0f, 297.0f));

STImageDTO imageDTO = new STImageDTO();
Bitmap myimage = BitmapFactory.decodeResource(this.getResources(), R.drawable.myimage);
imageDTO.setImage(myimage);
imageDTO.setRectDTO(size);

List<STImageDTO> images = new ArrayList<>();
images.add(imageDTO);
byte[] changedDoc = STSignoUtils.appendPage(size, document, images);

createDocument method

This method can be used to create a document consisting of blank pages. Images can be inserted into the pages as an option.

Java
public static byte[] createDocument(STRectDTO size, int pages, PdfACompliance compliance, List<STImageDTO> images);

Parameter

Description

STRectDTO size

The size of the new page.

int pages

The number of pages.

PdfACompliance compliance

PDF/A Compliance

List<STImageDTO> images

A list of STImageDTO objects. May be null, in which case no images are added.

Return value

Description

byte[]

The changed document as a byte array.

The PdfACompliance enumeration is defined in the STSignoUtils class as follows:

Java
public enum PdfACompliance {
    None,
    PdfA1b,
    PdfA3b
}

Value

Description

None

No PDF/A Compliance

PdfA1b

PDF/A1b Compliance

PdfA3b

PDF/A3b Compliance

Usage:

Java
STRectDTO size = new STRectDTO();
size.setUnit(STRectDTO.Unit.UnitMillimetres);
size.setRectangle(new RectF(0.0f, 0.0f, 210.0f, 297.0f));

STImageDTO imageDTO = new STImageDTO();
Bitmap myimage = BitmapFactory.decodeResource(this.getResources(), R.drawable.myimage);
imageDTO.setImage(myimage);
imageDTO.setRectDTO(size);

List<STImageDTO> images = new ArrayList<>(); 
images.add(imageDTO);
byte[] createdDoc = STSignoUtils.createDocument(size, 1, STSignoUtils.PdfACompliance.None, images);

getDocumentMetaDataFromFile method

This method reads the document’s metadata without affecting any of the existing instances of the STSignoViewer class.

Java
public static String getDocumentMetaDataFromFile(byte[] document);

Parameter

Description

byte[] document

The document as a byte array.

Return value

Description

String

‘Metadata’ entry from the ‘Document Catalog’

Usage:

Java
String metaData = STSignoUtils.getDocumentMetaDataFromFile(document);

getFormFieldsInfoFromFile method

This method is deprecated and is only included for compatibility reasons. Please use the getFormFieldsFromFile() method instead.

getFormFieldsFromFile method

This method can be used to retrieve information about the form fields contained within the document without affecting any of the existing instances of the STSignoViewer class.

Java
public static <T extends STFormFieldInfoDTO> List<T> getFormFieldsFromFile(EnumSet<STFormFieldType> formFieldTypes, byte[] document);

Parameter

Description

EnumSet<STFormFieldType> formFieldTypes

EnumSet object of the enum class STFormFieldType

byte[] document

The document as a byte array.

Return value

Description

<T extends STFormFieldInfoDTO> List<T>

A list with one STFormFieldInfoDTO object or one object of the class derived from the STFormFieldInfoDTO class for each form field, or an empty list if the document does not contain any form fields that correspond to the form field types searched for.

Usage:

Java
byte[] document = ...
List<STFormFieldInfoDTO> allFields = STSignoUtils.getFormFields(EnumSet.allOf(STFormFieldType.class), document);
List<STEditableFieldInfoDTO> allEditableFields = STSignoUtils.getFormFields(EnumSet.of(STFormFieldType.TEXT, STFormFieldType.CHOICE, STFormFieldType.BUTTON), document);
List<STSignatureFieldInfoDTO> signatureFields = STSignoUtils.getFormFields(EnumSet.of(SIGNATURE), document);
List<STTextFieldInfoDTO> textFields = STSignoUtils.getFormFields(EnumSet.of(TEXT), document);
List<STButtonFieldInfoDTO> buttonFields = STSignoUtils.getFormFields(EnumSet.of(BUTTON), document);
List<STButtonFieldInfoDTO> choiceFields = STSignoUtils.getFormFields(EnumSet.of(CHOICE), document);
List<STFormFieldInfoDTO> allEditableFields = STSignoUtils.getFormFields(EnumSet.of(STFormFieldType.TEXT, STFormFieldType.CHOICE, STFormFieldType.BUTTON), document);
List<STFormFieldInfoDTO> signatureFields = STSignoUtils.getFormFields(EnumSet.of(SIGNATURE), document);
List<STFormFieldInfoDTO> textFields = STSignoUtils.getFormFields(EnumSet.of(TEXT), document);
List<STFormFieldInfoDTO> buttonFields = STSignoUtils.getFormFields(EnumSet.of(BUTTON), document);
List<STFormFieldInfoDTO> choiceFields = STSignoUtils.getFormFields(EnumSet.of(CHOICE), document);

setFormFieldsInfoToFile method

This method can be used to change the content and ‘read only’ property of form fields.

Java
public static byte[] setFormFieldsInfoToFile(List<STFormFieldInfoDTO> formFieldsInfo, byte[] document);

Parameter

Description

List<STFormFieldInfoDTO> formFieldsInfo

Form fields, whose properties are to be changed, as a list of STFormFieldInfoDTO objects. Only the name, value and readOnly properties of the objects are currently evaluated.

byte[] document

The document as a byte array.

Return value

Description

byte[]

The changed document as a byte array.

Usage:

Java
List<STFormFieldInfoDTO> formFields = STSignoUtils.getFormFieldsInfoFromFile(document);
for (STFormFieldInfo formField : formFields) {
  if (formField.getName().equals("MyField")) {
      formFields.setValue("My value");
      formField.setReadOnly(true);
  }
}
byte[] changedDoc = STSignoUtils.setFormFieldsInfo(formFields, document);

getSignatureInfoFromFile method

This method is deprecated and is only included for compatibility reasons. Please use the getFormFieldsFromFile() method instead.

appendPages method

This method can be used to append several empty pages to a document and to insert images on this page (optional).

Java
public static byte[] appendPages(STRectDTO size, byte[] document, int pages, List<STImageDTO> images);

Parameter

Description

STRectDTO size

The size of the new page.

byte[] document

The document as a byte array.

int pages

The number of pages to be appended.

List<STImageDTO> images

A list of STImageDTO objects. May be null, in which case no images are added.

Return value

Description

byte[]

The changed document as a byte array.

Usage:

Java
STRectDTO size = new STRectDTO();
size.setUnit(STRectDTO.Unit. UnitMillimetres);
size.setRectangle(new RectF(0.0f, 0.0f, 210.0f, 297.0f));

STImageDTO imageDTO = new STImageDTO();
Bitmap myimage = BitmapFactory.decodeResource(this.getResources(), R.drawable.myimage);
imageDTO.setImage(myimage);
imageDTO.setRectDTO(size);

List<STImageDTO> images = new ArrayList<>(); 
images.add(imageDTO);
byte[] changedDoc = STSignoUtils.appendPages(size, document, 2, images);