Skip to main content

Groovy Script - Insert Document Status and Attributes for PDF Files

Description: Sample Groovy script to insert Document Status, Standard and Custom Document Attributes into PDF files when they're printed, viewed, or downloaded based on the event defined in the related workflow trigger.

NOTE: This script doesn't impact the actual file. The document status is also inserted and displayed on the file only based on the configured event.

Context: Document

Remark: Accessible in Pre task mode and only when the event is configured as Print Document, View Document, or Download Documents.

Script:

def execute(){

/**

* Supported measurements:

* 1. MeasureIn.PIXEL

* 2. MeasureIn.INCH

* 3. MeasureIn.CENTIMETER

*

* Supported attributes:

* 1. SystemAttributeBanner.STATUS

* 2. SystemAttributeBanner.POI

* 3. SystemAttributeBanner.DOC_TITLE

* 4. SystemAttributeBanner.REVISION

* 5. SystemAttributeBanner.DOC_REF

* 6. SystemAttributeBanner.REV_NOTES

* 7. CUSTOM_ATTRIBUTES

*

* Supported font types:

* 1. EntityFontType.COURIER

* 2. EntityFontType.HELVETICA

* 3. EntityFontType.TIMES_ROMAN

*

* Supported attribute positions:

* 1. Location.TOP_LEFT

* 2. Location.TOP_CENTER

* 3. Location.TOP_RIGHT

* 4. Location.BOTTOM_LEFT

* 5. Location.BOTTOM_CENTER

* 6. Location.BOTTOM_RIGHT

*/

EmbedAttributeConfigEntity embedAttributeConfigEntity = new EmbedAttributeConfigEntity();

embedAttributeConfigEntity.setApplyOnAllPage(false);

embedAttributeConfigEntity.setDisplacementTop(0);

embedAttributeConfigEntity.setDisplacementBottom(0);

embedAttributeConfigEntity.setDisplacementRight(0);

embedAttributeConfigEntity.setDisplacementLeft(0);

embedAttributeConfigEntity.setAttributePosition(Location.TOP_LEFT);

embedAttributeConfigEntity.setMeasureIn(MeasureIn.PIXEL);

embedAttributeConfigEntity.setAttributeLblPrefix("View Doc Status : ");

embedAttributeConfigEntity.setFontSize(20);

embedAttributeConfigEntity.setColor("#cc0099");

embedAttributeConfigEntity.setFont(EntityFontType.TIMES_ROMAN);

embedAttributeConfigEntity.setBold(true);

embedAttributeConfigEntity.setItalic(true);

EmbedAttributeConfigEntity embedAttributeConfigEntity1 = new EmbedAttributeConfigEntity();

embedAttributeConfigEntity1.setApplyOnAllPage(false);

embedAttributeConfigEntity1.setDisplacementTop(100);

embedAttributeConfigEntity1.setDisplacementBottom(100);

embedAttributeConfigEntity1.setDisplacementRight(100);

embedAttributeConfigEntity1.setDisplacementLeft(1000);

embedAttributeConfigEntity1.setAttributePosition(Location.TOP_RIGHT);

embedAttributeConfigEntity1.setMeasureIn(MeasureIn.PIXEL);

embedAttributeConfigEntity1.setAttributeLblPrefix("View Doc poi : ");

embedAttributeConfigEntity1.setFontSize(20);

embedAttributeConfigEntity1.setColor("#cc0099");

embedAttributeConfigEntity1.setFont(EntityFontType.TIMES_ROMAN);

embedAttributeConfigEntity1.setBold(true);

embedAttributeConfigEntity1.setItalic(true);

EmbedAttributeConfigEntity embedAttributeConfigEntity2 = new EmbedAttributeConfigEntity();

embedAttributeConfigEntity2.setApplyOnAllPage(false);

embedAttributeConfigEntity2.setDisplacementTop(200);

embedAttributeConfigEntity2.setDisplacementBottom(200);

embedAttributeConfigEntity2.setDisplacementRight(200);

embedAttributeConfigEntity2.setDisplacementLeft(2000);

embedAttributeConfigEntity2.setAttributePosition(Location.TOP_RIGHT);

embedAttributeConfigEntity2.setMeasureIn(MeasureIn.PIXEL);

embedAttributeConfigEntity2.setAttributeLblPrefix("View Custom_Attribute_Name : ");

embedAttributeConfigEntity2.setFontSize(20);

embedAttributeConfigEntity2.setColor("#cc0099");

embedAttributeConfigEntity2.setFont(EntityFontType.TIMES_ROMAN);

embedAttributeConfigEntity2.setBold(true);

embedAttributeConfigEntity2.setItalic(true);

Map<SystemAttributeBanner, EmbedAttributeConfigEntity> sysAttributes = new HashMap<SystemAttributeBanner, EmbedAttributeConfigEntity>();

sysAttributes.put(SystemAttributeBanner.STATUS, embedAttributeConfigEntity);

sysAttributes.put(SystemAttributeBanner.POI, embedAttributeConfigEntity1);

sysAttributes.put("Custom_Attribute_Name", embedAttributeConfigEntity2);

return documentService.embedAttributesInFile(sysAttributes);

}


Did this answer your question?