use of org.apache.poi.xwpf.usermodel.XWPFDocument in project poi by apache.
the class TestXWPFHeaderFooterPolicy method testCreate.
@SuppressWarnings("resource")
public void testCreate() throws Exception {
XWPFDocument doc = new XWPFDocument();
assertEquals(null, doc.getHeaderFooterPolicy());
assertEquals(0, doc.getHeaderList().size());
assertEquals(0, doc.getFooterList().size());
XWPFHeaderFooterPolicy policy = doc.createHeaderFooterPolicy();
assertNotNull(doc.getHeaderFooterPolicy());
assertEquals(0, doc.getHeaderList().size());
assertEquals(0, doc.getFooterList().size());
// Create a header and a footer
XWPFHeader header = policy.createHeader(XWPFHeaderFooterPolicy.DEFAULT);
XWPFFooter footer = policy.createFooter(XWPFHeaderFooterPolicy.DEFAULT);
header.createParagraph().createRun().setText("Header Hello");
footer.createParagraph().createRun().setText("Footer Bye");
// Save, re-load, and check
doc = XWPFTestDataSamples.writeOutAndReadBack(doc);
assertNotNull(doc.getHeaderFooterPolicy());
assertEquals(1, doc.getHeaderList().size());
assertEquals(1, doc.getFooterList().size());
assertEquals("Header Hello\n", doc.getHeaderList().get(0).getText());
assertEquals("Footer Bye\n", doc.getFooterList().get(0).getText());
}
use of org.apache.poi.xwpf.usermodel.XWPFDocument in project poi by apache.
the class TestXWPFWordExtractor method testBug55733.
/**
* No Header or Footer in document
*/
public void testBug55733() throws Exception {
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("55733.docx");
XWPFWordExtractor extractor = new XWPFWordExtractor(doc);
// Check it gives text without error
extractor.getText();
extractor.close();
}
use of org.apache.poi.xwpf.usermodel.XWPFDocument in project poi by apache.
the class TestXWPFWordExtractor method testEndnotes.
public void testEndnotes() throws IOException {
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("endnotes.docx");
XWPFWordExtractor extractor = new XWPFWordExtractor(doc);
String text = extractor.getText();
assertContains(text, "XXX");
assertContains(text, "tilaka [endnoteRef:2]or 'tika'");
extractor.close();
}
use of org.apache.poi.xwpf.usermodel.XWPFDocument in project poi by apache.
the class TestXWPFWordExtractor method testFootnotes.
public void testFootnotes() throws IOException {
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("footnotes.docx");
XWPFWordExtractor extractor = new XWPFWordExtractor(doc);
String text = extractor.getText();
assertContains(text, "snoska");
assertContains(text, "Eto ochen prostoy[footnoteRef:1] text so snoskoy");
extractor.close();
}
use of org.apache.poi.xwpf.usermodel.XWPFDocument in project poi by apache.
the class TestXWPFWordExtractor method testDocTabs.
/**
* Test that we handle things like tabs and
* carriage returns properly in the text that
* we're extracting (bug #49189)
*
* @throws IOException
*/
public void testDocTabs() throws IOException {
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("WithTabs.docx");
XWPFWordExtractor extractor = new XWPFWordExtractor(doc);
// Check bits
assertContains(extractor.getText(), "a");
assertContains(extractor.getText(), "\t");
assertContains(extractor.getText(), "b");
// Now check the first paragraph in total
assertContains(extractor.getText(), "a\tb\n");
extractor.close();
}
Aggregations