Search in sources :

Example 1 with PicturesTable

use of org.apache.poi.hwpf.model.PicturesTable in project poi by apache.

the class TestHWPFPictures method testImageData.

/**
	 * Test that we have the right images in at least one file
	 */
public void testImageData() {
    HWPFDocument docB = HWPFTestDataSamples.openSampleFile(docBFile);
    PicturesTable picB = docB.getPicturesTable();
    List<Picture> picturesB = picB.getAllPictures();
    assertEquals(2, picturesB.size());
    Picture pic1 = picturesB.get(0);
    Picture pic2 = picturesB.get(1);
    assertNotNull(pic1);
    assertNotNull(pic2);
    // Check the same
    byte[] pic1B = readFile(imgAFile);
    byte[] pic2B = readFile(imgBFile);
    assertEquals(pic1B.length, pic1.getContent().length);
    assertEquals(pic2B.length, pic2.getContent().length);
    assertBytesSame(pic1B, pic1.getContent());
    assertBytesSame(pic2B, pic2.getContent());
}
Also used : Picture(org.apache.poi.hwpf.usermodel.Picture) PicturesTable(org.apache.poi.hwpf.model.PicturesTable)

Example 2 with PicturesTable

use of org.apache.poi.hwpf.model.PicturesTable in project poi by apache.

the class TestHWPFPictures method testCompressedImageData.

/**
	 * Test that compressed image data is correctly returned.
	 */
public void testCompressedImageData() {
    HWPFDocument docC = HWPFTestDataSamples.openSampleFile(docCFile);
    PicturesTable picC = docC.getPicturesTable();
    List<Picture> picturesC = picC.getAllPictures();
    assertEquals(1, picturesC.size());
    Picture pic = picturesC.get(0);
    assertNotNull(pic);
    // Check the same
    byte[] picBytes = readFile(imgCFile);
    assertEquals(picBytes.length, pic.getContent().length);
    assertBytesSame(picBytes, pic.getContent());
}
Also used : Picture(org.apache.poi.hwpf.usermodel.Picture) PicturesTable(org.apache.poi.hwpf.model.PicturesTable)

Example 3 with PicturesTable

use of org.apache.poi.hwpf.model.PicturesTable in project poi by apache.

the class TestPictures method testPictureDetectionWithPNG.

@Test
public void testPictureDetectionWithPNG() {
    HWPFDocument document = HWPFTestDataSamples.openSampleFile("PngPicture.doc");
    PicturesTable pictureTable = document.getPicturesTable();
    assertEquals(1, pictureTable.getAllPictures().size());
    Picture p = pictureTable.getAllPictures().get(0);
    assertEquals(PictureType.PNG, p.suggestPictureType());
    assertEquals("png", p.suggestFileExtension());
}
Also used : HWPFDocument(org.apache.poi.hwpf.HWPFDocument) PicturesTable(org.apache.poi.hwpf.model.PicturesTable) Test(org.junit.Test)

Example 4 with PicturesTable

use of org.apache.poi.hwpf.model.PicturesTable in project poi by apache.

the class TestPictures method testPictureWithAlternativeText.

@Test
public void testPictureWithAlternativeText() {
    HWPFDocument document = HWPFTestDataSamples.openSampleFile("Picture_Alternative_Text.doc");
    PicturesTable pictureTable = document.getPicturesTable();
    Picture picture = pictureTable.getAllPictures().get(0);
    assertEquals("This is the alternative text for the picture.", picture.getDescription());
}
Also used : HWPFDocument(org.apache.poi.hwpf.HWPFDocument) PicturesTable(org.apache.poi.hwpf.model.PicturesTable) Test(org.junit.Test)

Example 5 with PicturesTable

use of org.apache.poi.hwpf.model.PicturesTable in project poi by apache.

the class TestPictures method expectImages.

private void expectImages(HWPFDocument docA, int expectedCount) {
    assertNotNull(docA.getPicturesTable());
    PicturesTable picA = docA.getPicturesTable();
    List<Picture> picturesA = picA.getAllPictures();
    assertEquals(expectedCount, picturesA.size());
}
Also used : PicturesTable(org.apache.poi.hwpf.model.PicturesTable)

Aggregations

PicturesTable (org.apache.poi.hwpf.model.PicturesTable)12 HWPFDocument (org.apache.poi.hwpf.HWPFDocument)6 Picture (org.apache.poi.hwpf.usermodel.Picture)6 Test (org.junit.Test)5 Paragraph (org.apache.poi.hwpf.usermodel.Paragraph)2 BufferedImage (java.awt.image.BufferedImage)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 OldWordFileFormatException (org.apache.poi.hwpf.OldWordFileFormatException)1 SavedByEntry (org.apache.poi.hwpf.model.SavedByEntry)1 SavedByTable (org.apache.poi.hwpf.model.SavedByTable)1 StyleDescription (org.apache.poi.hwpf.model.StyleDescription)1 CharacterRun (org.apache.poi.hwpf.usermodel.CharacterRun)1 Field (org.apache.poi.hwpf.usermodel.Field)1 HeaderStories (org.apache.poi.hwpf.usermodel.HeaderStories)1 Range (org.apache.poi.hwpf.usermodel.Range)1 Table (org.apache.poi.hwpf.usermodel.Table)1 TableCell (org.apache.poi.hwpf.usermodel.TableCell)1 TableRow (org.apache.poi.hwpf.usermodel.TableRow)1 DirectoryEntry (org.apache.poi.poifs.filesystem.DirectoryEntry)1