com.aspose.words
Class MergeFieldImageDimensionUnit

java.lang.Object
    extended by com.aspose.words.MergeFieldImageDimensionUnit

public class MergeFieldImageDimensionUnit 
extends java.lang.Object

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

Example:

Shows how to set the dimensions of merged images.
public void mergeFieldImageDimension() throws Exception {
    Document doc = new Document();

    // Insert a merge field where images will be placed during the mail merge
    DocumentBuilder builder = new DocumentBuilder(doc);
    FieldMergeField field = (FieldMergeField) builder.insertField("MERGEFIELD Image:ImageColumn");

    Assert.assertEquals("Image:ImageColumn", field.getFieldName());

    // Create a data table for the mail merge
    // The name of the column that contains our image filenames needs to match the name of our merge field
    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");

    doc.getMailMerge().setFieldMergingCallback(new MergedImageResizer(200.0, 200.0, MergeFieldImageDimensionUnit.POINT));
    doc.getMailMerge().execute(dataTable);

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

/// <summary>
/// Sets the size of all mail merged images to one defined width and height.
/// </summary>
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 double mImageWidth;
    private double mImageHeight;
    private int mUnit;
}

Field Summary
static final intPOINT = 0
           The point (i.e. 1/72 inch).
static final intPERCENT = 1
           The percent of the original image dimension value.
 

Field Detail

POINT = 0

public static final int POINT
The point (i.e. 1/72 inch).

PERCENT = 1

public static final int PERCENT
The percent of the original image dimension value.

See Also:
          Aspose.Words Documentation - the home page for the Aspose.Words Product Documentation.
          Aspose.Words Support Forum - our preferred method of support.