sitimoen / xdocreport

Automatically exported from code.google.com/p/xdocreport
0 stars 0 forks source link

java.lang.NullPointerException When trying to extract images in a Docx file #280

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. java.lang.NullPointerException
2. image extraction from a docx file

Please provide any additional information below.
I am trying to convert a docx file into html file. It converts the file 
successfully. But when I try to extract images from the docx, extract() method 
of IImageExtractor class throws a "java.lang.NullPointerException".
Everything looks like fine but I can't understand why. Nothing is wrong with 
docx file. Just doesn't extract the image..

InputStream in= new FileInputStream(new File("/Users/name/file.docx"));
XWPFDocument document = new XWPFDocument(in);

List<XWPFPictureData> allpictures=document.getAllPictures();
IImageExtractor imageExtractor=XHTMLOptions.create().getExtractor();

for(int i=0;i<allpictures.size();i++)
{
    //this method throws the error
    imageExtractor.extract("images/"+allpictures.get(i).getFileName(), allpictures.get(i).getData());
}

// 2) Prepare XHTML options (here we set the IURIResolver to load images from a 
"word/media" folder)
XHTMLOptions options = XHTMLOptions.create().URIResolver(new 
FileURIResolver(new File("images")));

// 3) Convert XWPFDocument to XHTML
OutputStream out = new FileOutputStream(new File("file.htm")); 
XHTMLConverter.getInstance().convert(document, out, options);

Original issue reported on code.google.com by cmltoka...@gmail.com on 19 Jul 2013 at 3:12

GoogleCodeExporter commented 8 years ago
Hi,

To use extractor, ,you must set uri resolver too. See sample at 
https://code.google.com/p/xdocreport/source/browse/thirdparties-extension/org.ap
ache.poi.xwpf.converter.xhtml/src/test/java/org/apache/poi/xwpf/converter/xhtml/
XHTMLConverterTestCase.java

Regards Angelo

Original comment by angelo.z...@gmail.com on 21 Jul 2013 at 12:25

GoogleCodeExporter commented 8 years ago
I close this issue. Please see sample at 
https://code.google.com/p/xdocreport/source/browse/thirdparties-extension/org.ap
ache.poi.xwpf.converter.xhtml/src/test/java/org/apache/poi/xwpf/converter/xhtml/
XHTMLConverterTestCase.java to see how to use extractor.

Original comment by angelo.z...@gmail.com on 17 Sep 2013 at 4:14