Search in sources :

Example 1 with ThumbnailType

use of org.apache.xmpbox.type.ThumbnailType in project pdfbox by apache.

the class DeserializationTest method testIsartorStyleWithThumbs.

@Test
public void testIsartorStyleWithThumbs() throws Exception {
    InputStream fis = DomXmpParser.class.getResourceAsStream("/org/apache/xmpbox/parser/ThumbisartorStyle.xml");
    DomXmpParser xdb = new DomXmpParser();
    XMPMetadata metadata = xdb.parse(fis);
    // <xmpMM:DocumentID>
    Assert.assertEquals("uuid:09C78666-2F91-3A9C-92AF-3691A6D594F7", metadata.getXMPMediaManagementSchema().getDocumentID());
    // <xmp:CreateDate>
    // <xmp:ModifyDate>
    // <xmp:MetadataDate>
    Assert.assertEquals(DateConverter.toCalendar("2008-01-18T16:59:54+01:00"), metadata.getXMPBasicSchema().getCreateDate());
    Assert.assertEquals(DateConverter.toCalendar("2008-01-18T16:59:54+01:00"), metadata.getXMPBasicSchema().getModifyDate());
    Assert.assertEquals(DateConverter.toCalendar("2008-01-18T16:59:54+01:00"), metadata.getXMPBasicSchema().getMetadataDate());
    // THUMBNAILS TEST
    List<ThumbnailType> thumbs = metadata.getXMPBasicSchema().getThumbnailsProperty();
    Assert.assertNotNull(thumbs);
    Assert.assertEquals(2, thumbs.size());
    ThumbnailType thumb = thumbs.get(0);
    Assert.assertEquals(Integer.valueOf(162), thumb.getHeight());
    Assert.assertEquals(Integer.valueOf(216), thumb.getWidth());
    Assert.assertEquals("JPEG", thumb.getFormat());
    Assert.assertEquals("/9j/4AAQSkZJRgABAgEASABIAAD", thumb.getImage());
    thumb = thumbs.get(1);
    Assert.assertEquals(Integer.valueOf(162), thumb.getHeight());
    Assert.assertEquals(Integer.valueOf(216), thumb.getWidth());
    Assert.assertEquals("JPEG", thumb.getFormat());
    Assert.assertEquals("/9j/4AAQSkZJRgABAgEASABIAAD", thumb.getImage());
}
Also used : XMPMetadata(org.apache.xmpbox.XMPMetadata) InputStream(java.io.InputStream) DomXmpParser(org.apache.xmpbox.xml.DomXmpParser) ThumbnailType(org.apache.xmpbox.type.ThumbnailType) Test(org.junit.Test)

Example 2 with ThumbnailType

use of org.apache.xmpbox.type.ThumbnailType in project pdfbox by apache.

the class XMPBasicSchema method addThumbnails.

/**
 * Add thumbnail to thumbnails list
 *
 * @param height
 *            height format
 * @param width
 *            width format
 * @param format
 *            thumbnail format
 * @param img
 *            Image data
 */
public void addThumbnails(Integer height, Integer width, String format, String img) {
    if (altThumbs == null) {
        altThumbs = createArrayProperty(THUMBNAILS, Cardinality.Alt);
        addProperty(altThumbs);
    }
    ThumbnailType thumb = new ThumbnailType(getMetadata());
    thumb.setHeight(height);
    thumb.setWidth(width);
    thumb.setFormat(format);
    thumb.setImage(img);
    altThumbs.getContainer().addProperty(thumb);
}
Also used : ThumbnailType(org.apache.xmpbox.type.ThumbnailType)

Example 3 with ThumbnailType

use of org.apache.xmpbox.type.ThumbnailType in project pdfbox by apache.

the class AbstractXMPSchemaTest method testGetSetThumbnail.

protected void testGetSetThumbnail() throws Exception {
    String addName = addMethod(property);
    String getName = getMethod(property);
    Method setMethod = schemaClass.getMethod(addName, Integer.class, Integer.class, String.class, String.class);
    Method getMethod = schemaClass.getMethod(getName);
    Integer height = 162;
    Integer width = 400;
    String format = "JPEG";
    String img = "/9j/4AAQSkZJRgABAgEASABIAAD";
    setMethod.invoke(schema, height, width, format, img);
    List<ThumbnailType> found = ((List<ThumbnailType>) getMethod.invoke(schema));
    Assert.assertTrue(found.size() == 1);
    ThumbnailType t1 = found.get(0);
    Assert.assertEquals(height, t1.getHeight());
    Assert.assertEquals(width, t1.getWidth());
    Assert.assertEquals(format, t1.getFormat());
    Assert.assertEquals(img, t1.getImage());
}
Also used : Method(java.lang.reflect.Method) ThumbnailType(org.apache.xmpbox.type.ThumbnailType)

Example 4 with ThumbnailType

use of org.apache.xmpbox.type.ThumbnailType in project pdfbox by apache.

the class MetadataValidationProcess method checkThumbnails.

// check thumbnails. See Bavaria Testsuite file PDFA_Conference_2009_nc.pdf for an example.
private void checkThumbnails(PreflightContext ctx, XMPMetadata metadata) {
    XMPBasicSchema xmp = metadata.getXMPBasicSchema();
    if (xmp == null) {
        return;
    }
    List<ThumbnailType> tbProp;
    try {
        tbProp = xmp.getThumbnailsProperty();
    } catch (BadFieldValueException e) {
        // should not happen here because it would have happened in XmpParser already
        addValidationError(ctx, new ValidationError(PreflightConstants.ERROR_METADATA_FORMAT, e.getMessage(), e));
        return;
    }
    if (tbProp == null) {
        return;
    }
    for (ThumbnailType tb : tbProp) {
        checkThumbnail(tb, ctx);
    }
}
Also used : BadFieldValueException(org.apache.xmpbox.type.BadFieldValueException) XMPBasicSchema(org.apache.xmpbox.schema.XMPBasicSchema) ValidationError(org.apache.pdfbox.preflight.ValidationResult.ValidationError) ThumbnailType(org.apache.xmpbox.type.ThumbnailType)

Aggregations

ThumbnailType (org.apache.xmpbox.type.ThumbnailType)4 InputStream (java.io.InputStream)1 Method (java.lang.reflect.Method)1 ValidationError (org.apache.pdfbox.preflight.ValidationResult.ValidationError)1 XMPMetadata (org.apache.xmpbox.XMPMetadata)1 XMPBasicSchema (org.apache.xmpbox.schema.XMPBasicSchema)1 BadFieldValueException (org.apache.xmpbox.type.BadFieldValueException)1 DomXmpParser (org.apache.xmpbox.xml.DomXmpParser)1 Test (org.junit.Test)1