Search in sources :

Example 16 with XWPFDocument

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());
}
Also used : XWPFFooter(org.apache.poi.xwpf.usermodel.XWPFFooter) XWPFDocument(org.apache.poi.xwpf.usermodel.XWPFDocument) XWPFHeader(org.apache.poi.xwpf.usermodel.XWPFHeader)

Example 17 with XWPFDocument

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();
}
Also used : XWPFDocument(org.apache.poi.xwpf.usermodel.XWPFDocument)

Example 18 with XWPFDocument

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();
}
Also used : XWPFDocument(org.apache.poi.xwpf.usermodel.XWPFDocument)

Example 19 with XWPFDocument

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();
}
Also used : XWPFDocument(org.apache.poi.xwpf.usermodel.XWPFDocument)

Example 20 with XWPFDocument

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();
}
Also used : XWPFDocument(org.apache.poi.xwpf.usermodel.XWPFDocument)

Aggregations

XWPFDocument (org.apache.poi.xwpf.usermodel.XWPFDocument)51 Test (org.junit.Test)15 FileOutputStream (java.io.FileOutputStream)11 File (java.io.File)9 XWPFParagraph (org.apache.poi.xwpf.usermodel.XWPFParagraph)9 XWPFRun (org.apache.poi.xwpf.usermodel.XWPFRun)9 InputStream (java.io.InputStream)6 OutputStream (java.io.OutputStream)6 FileInputStream (java.io.FileInputStream)4 XWPFTable (org.apache.poi.xwpf.usermodel.XWPFTable)4 OPCPackage (org.apache.poi.openxml4j.opc.OPCPackage)3 NPOIFSFileSystem (org.apache.poi.poifs.filesystem.NPOIFSFileSystem)3 XMLSlideShow (org.apache.poi.xslf.usermodel.XMLSlideShow)3 XWPFWordExtractor (org.apache.poi.xwpf.extractor.XWPFWordExtractor)3 XWPFFooter (org.apache.poi.xwpf.usermodel.XWPFFooter)3 XWPFHeader (org.apache.poi.xwpf.usermodel.XWPFHeader)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ZipFile (java.util.zip.ZipFile)2 HSLFSlideShow (org.apache.poi.hslf.usermodel.HSLFSlideShow)2 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)2