MergeFieldImageDimensionUnit

Inheritance: java.lang.Object

public class MergeFieldImageDimensionUnit

Specifies an unit of an image dimension (i.e. the width or the height) used across a mail merge process.

Examples:

Shows how to set the dimensions of images as MERGEFIELDS accepts them during a mail merge.


 public void mergeFieldImageDimension() throws Exception {
     Document doc = new Document();

     // Insert a MERGEFIELD that will accept images from a source during a mail merge. Use the field code to reference
     // a column in the data source containing local system filenames of images we wish to use in the mail merge.
     DocumentBuilder builder = new DocumentBuilder(doc);
     FieldMergeField field = (FieldMergeField) builder.insertField("MERGEFIELD Image:ImageColumn");

     // The data source should have such a column named "ImageColumn".
     Assert.assertEquals("Image:ImageColumn", field.getFieldName());

     // Create a suitable data source.
     DataTable dataTable = new DataTable("Images");
     dataTable.getColumns().add(new DataColumn("ImageColumn"));
     dataTable.getRows().add(getImageDir() + "Logo.jpg");
     dataTable.getRows().add(getImageDir() + "Transparent background logo.png");
     dataTable.getRows().add(getImageDir() + "Enhanced Windows MetaFile.emf");

     // Configure a callback to modify the sizes of images at merge time, then execute the mail merge.
     doc.getMailMerge().setFieldMergingCallback(new MergedImageResizer(200.0, 200.0, MergeFieldImageDimensionUnit.POINT));
     doc.getMailMerge().execute(dataTable);

     doc.updateFields();
     doc.save(getArtifactsDir() + "Field.MERGEFIELD.ImageDimension.docx");
 }

 /// 
 /// Sets the size of all mail merged images to one defined width and height.
 /// 
 private static class MergedImageResizer implements IFieldMergingCallback {
     public MergedImageResizer(final double imageWidth, final double imageHeight, final int unit) {
         mImageWidth = imageWidth;
         mImageHeight = imageHeight;
         mUnit = unit;
     }

     public void fieldMerging(final FieldMergingArgs args) {
         throw new UnsupportedOperationException();
     }

     public void imageFieldMerging(final ImageFieldMergingArgs args) {
         args.setImageFileName(args.getFieldValue().toString());
         args.setImageWidth(new MergeFieldImageDimension(mImageWidth, mUnit));
         args.setImageHeight(new MergeFieldImageDimension(mImageHeight, mUnit));

         Assert.assertEquals(mImageWidth, args.getImageWidth().getValue());
         Assert.assertEquals(mUnit, args.getImageWidth().getUnit());
         Assert.assertEquals(mImageHeight, args.getImageHeight().getValue());
         Assert.assertEquals(mUnit, args.getImageHeight().getUnit());
     }

     private final double mImageWidth;
     private final double mImageHeight;
     private final int mUnit;
 }
 

Fields

FieldDescription
PERCENTThe percent of the original image dimension value.
POINTThe point (i.e.
length

Methods

MethodDescription
fromName(String mergeFieldImageDimensionUnitName)
getName(int mergeFieldImageDimensionUnit)
getValues()
toString(int mergeFieldImageDimensionUnit)

PERCENT

public static int PERCENT

The percent of the original image dimension value.

POINT

public static int POINT

The point (i.e. 1/72 inch).

length

public static int length

fromName(String mergeFieldImageDimensionUnitName)

public static int fromName(String mergeFieldImageDimensionUnitName)

Parameters:

ParameterTypeDescription
mergeFieldImageDimensionUnitNamejava.lang.String

Returns: int

getName(int mergeFieldImageDimensionUnit)

public static String getName(int mergeFieldImageDimensionUnit)

Parameters:

ParameterTypeDescription
mergeFieldImageDimensionUnitint

Returns: java.lang.String

getValues()

public static int[] getValues()

Returns: int[]

toString(int mergeFieldImageDimensionUnit)

public static String toString(int mergeFieldImageDimensionUnit)

Parameters:

ParameterTypeDescription
mergeFieldImageDimensionUnitint

Returns: java.lang.String