Search in sources :

Example 6 with HWPFDocument

use of org.apache.poi.hwpf.HWPFDocument in project poi by apache.

the class TestBugs method test47958.

/**
     * Bug 47958 - Exception during Escher walk of pictures
     */
@Test
public void test47958() {
    HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Bug47958.doc");
    doc.getPicturesTable().getAllPictures();
}
Also used : HWPFDocument(org.apache.poi.hwpf.HWPFDocument) Test(org.junit.Test)

Example 7 with HWPFDocument

use of org.apache.poi.hwpf.HWPFDocument in project poi by apache.

the class TestPictures method testFastSaved3.

@Test
public void testFastSaved3() {
    HWPFDocument doc = HWPFTestDataSamples.openSampleFile("ob_is.doc");
    // just check that we do not throw Exception
    doc.getPicturesTable().getAllPictures();
}
Also used : HWPFDocument(org.apache.poi.hwpf.HWPFDocument) Test(org.junit.Test)

Example 8 with HWPFDocument

use of org.apache.poi.hwpf.HWPFDocument in project poi by apache.

the class TestBugs method test51604p3.

/**
     * [RESOLVED FIXED] Bug 51604 - replace text fails for doc (poi 3.8 beta
     * release from download site )
     */
@Test
public void test51604p3() throws Exception {
    HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Bug51604.doc");
    byte[] originalData = new byte[doc.getFileInformationBlock().getLcbDop()];
    System.arraycopy(doc.getTableStream(), doc.getFileInformationBlock().getFcDop(), originalData, 0, originalData.length);
    HWPFOutputStream outputStream = new HWPFOutputStream();
    doc.getDocProperties().writeTo(outputStream);
    final byte[] oldData = outputStream.toByteArray();
    assertEqualsIgnoreNewline(Arrays.toString(originalData), Arrays.toString(oldData));
    Range range = doc.getRange();
    int numParagraph = range.numParagraphs();
    replaceText(range, numParagraph);
    doc = HWPFTestDataSamples.writeOutAndReadBack(doc);
    outputStream = new HWPFOutputStream();
    doc.getDocProperties().writeTo(outputStream);
    final byte[] newData = outputStream.toByteArray();
    assertEqualsIgnoreNewline(Arrays.toString(oldData), Arrays.toString(newData));
}
Also used : HWPFDocument(org.apache.poi.hwpf.HWPFDocument) HWPFOutputStream(org.apache.poi.hwpf.model.io.HWPFOutputStream) Test(org.junit.Test)

Example 9 with HWPFDocument

use of org.apache.poi.hwpf.HWPFDocument in project poi by apache.

the class TestPictures method testPicturesInHeader.

@Test
public void testPicturesInHeader() {
    HWPFDocument doc = HWPFTestDataSamples.openSampleFile("header_image.doc");
    List<Picture> pics = doc.getPicturesTable().getAllPictures();
    assertEquals(2, pics.size());
}
Also used : HWPFDocument(org.apache.poi.hwpf.HWPFDocument) Test(org.junit.Test)

Example 10 with HWPFDocument

use of org.apache.poi.hwpf.HWPFDocument 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)

Aggregations

HWPFDocument (org.apache.poi.hwpf.HWPFDocument)126 Test (org.junit.Test)66 InputStream (java.io.InputStream)15 FileInputStream (java.io.FileInputStream)10 Range (org.apache.poi.hwpf.usermodel.Range)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8 HSLFSlideShow (org.apache.poi.hslf.usermodel.HSLFSlideShow)7 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)7 WordExtractor (org.apache.poi.hwpf.extractor.WordExtractor)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 PicturesTable (org.apache.poi.hwpf.model.PicturesTable)6 Bookmark (org.apache.poi.hwpf.usermodel.Bookmark)6 NPOIFSFileSystem (org.apache.poi.poifs.filesystem.NPOIFSFileSystem)6 File (java.io.File)4 FileOutputStream (java.io.FileOutputStream)4 Transformer (javax.xml.transform.Transformer)4 DOMSource (javax.xml.transform.dom.DOMSource)4 Picture (org.apache.poi.hwpf.usermodel.Picture)4 DirectoryNode (org.apache.poi.poifs.filesystem.DirectoryNode)4 POIFSFileSystem (org.apache.poi.poifs.filesystem.POIFSFileSystem)4