use of org.apache.poi.hwpf.HWPFDocument in project poi by apache.
the class TestBugs method test51678And51524.
/**
* Bug 51678 - Extracting text from Bug51524.zip is slow Bug 51524 -
* PapBinTable constructor is slow
*/
@Test
public void test51678And51524() throws IOException {
// TODO: refactor into something nicer!
if (System.getProperty("poi.test.remote") != null) {
String href = "http://domex.nps.edu/corp/files/govdocs1/007/007488.doc";
HWPFDocument hwpfDocument = HWPFTestDataSamples.openRemoteFile(href);
WordExtractor wordExtractor = new WordExtractor(hwpfDocument);
try {
wordExtractor.getText();
} finally {
wordExtractor.close();
}
}
}
use of org.apache.poi.hwpf.HWPFDocument in project poi by apache.
the class TestPictures method test58804_1.
@Ignore("This bug is not fixed yet")
@Test
public void test58804_1() throws Exception {
HWPFDocument docA = HWPFTestDataSamples.openSampleFile("58804_1.doc");
expectImages(docA, 1);
HWPFDocument docB = HWPFTestDataSamples.writeOutAndReadBack(docA);
OutputStream out = new FileOutputStream("/tmp/58804_1_out.doc");
try {
docB.write(out);
} finally {
out.close();
}
expectImages(docB, 1);
}
use of org.apache.poi.hwpf.HWPFDocument in project poi by apache.
the class TestBugs method testHWPFSections.
@Test
@SuppressWarnings("SuspiciousNameCombination")
public void testHWPFSections() {
HWPFDocument document = HWPFTestDataSamples.openSampleFile("Bug53453Section.doc");
Range overallRange = document.getOverallRange();
int numParas = overallRange.numParagraphs();
for (int i = 0; i < numParas; i++) {
Paragraph para = overallRange.getParagraph(i);
int numSections = para.numSections();
for (int j = 0; j < numSections; j++) {
Section section = para.getSection(j);
if (para.text().trim().equals("Section1")) {
assertSection1Margin(section);
} else if (para.text().trim().equals("Section2")) {
assertSection2Margin(section);
// Change the margin widths
this.section2BottomMargin = (int) (1.5 * AbstractWordUtils.TWIPS_PER_INCH);
this.section2TopMargin = (int) (1.75 * AbstractWordUtils.TWIPS_PER_INCH);
this.section2LeftMargin = (int) (0.5 * AbstractWordUtils.TWIPS_PER_INCH);
this.section2RightMargin = (int) (0.75 * AbstractWordUtils.TWIPS_PER_INCH);
section.setMarginBottom(this.section2BottomMargin);
section.setMarginLeft(this.section2LeftMargin);
section.setMarginRight(this.section2RightMargin);
section.setMarginTop(this.section2TopMargin);
}
}
}
// Save away and re-read the document to prove the chages are permanent
document = HWPFTestDataSamples.writeOutAndReadBack(document);
overallRange = document.getOverallRange();
numParas = overallRange.numParagraphs();
for (int i = 0; i < numParas; i++) {
Paragraph para = overallRange.getParagraph(i);
int numSections = para.numSections();
for (int j = 0; j < numSections; j++) {
Section section = para.getSection(j);
if (para.text().trim().equals("Section1")) {
// No changes to the margins in Section1
assertSection1Margin(section);
} else if (para.text().trim().equals("Section2")) {
// The margins in Section2 have kept the new settings.
assertSection2Margin(section);
}
}
}
}
use of org.apache.poi.hwpf.HWPFDocument 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());
}
use of org.apache.poi.hwpf.HWPFDocument in project poi by apache.
the class TestPictures method testFloatingPictures.
/**
* In word you can have floating or fixed pictures.
* Fixed have a in place with an offset to the
* picture data.
* Floating have a in place, which references a
* which has the offset. More than one can
* reference the same
*/
@Test
public void testFloatingPictures() {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("FloatingPictures.doc");
PicturesTable pictures = doc.getPicturesTable();
// There are 19 images in the picture, but some are
// duplicate floating ones
assertEquals(17, pictures.getAllPictures().size());
int plain8s = 0;
int escher8s = 0;
int image1s = 0;
Range r = doc.getRange();
for (int np = 0; np < r.numParagraphs(); np++) {
Paragraph p = r.getParagraph(np);
for (int nc = 0; nc < p.numCharacterRuns(); nc++) {
CharacterRun cr = p.getCharacterRun(nc);
if (pictures.hasPicture(cr)) {
image1s++;
} else if (pictures.hasEscherPicture(cr)) {
escher8s++;
} else if (cr.text().startsWith("")) {
plain8s++;
}
}
}
// Total is 20, as the 4 escher 8s all reference
// the same regular image
assertEquals(16, image1s);
assertEquals(4, escher8s);
assertEquals(0, plain8s);
}
Aggregations