Hello evryone,
I have create a program that converts .doc to .pdf/.html, found that code here
http://angelozerr.wordpress.com/2012/12/06/how-to-convert-docxodt-to-pdfhtml-with-java/[
^]. I use the
XDocReport
library and samples works fine. The 1st library I can't run it, the 2nd is there are some configurations.
When running the samples, which converts the doc file that is in the zip file(downloaded). It can convert to pdf or html. But when I try converting doc file created in my computer I got this error
Exception in thread "AWT-EventQueue-0" org.apache.poi.POIXMLException: org.apache.poi.openxml4j.exceptions.InvalidFormatException: Package should contain a content type part [M1.13]
at org.apache.poi.util.PackageHelper.open(PackageHelper.java:41)
at org.apache.poi.xwpf.usermodel.XWPFDocument.<init>(XWPFDocument.java:120)
at docconverter.Convert.ConvertToPDF(Convert.java:32)
Convert Code:
public static void ConvertToPDF(String docPath, String pdfPath) {
try {
InputStream doc = new FileInputStream(new File(docPath));
XWPFDocument document = new XWPFDocument(doc);
PdfOptions options = PdfOptions.create();
OutputStream out = new FileOutputStream(new File(pdfPath));
PdfConverter.getInstance().convert(document, out, options);
} catch (FileNotFoundException ex) {
Logger.getLogger(Convert.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(Convert.class.getName()).log(Level.SEVERE, null, ex);
}
}
public static void ConvertToHTML(String docPath, String htmlPath) {
try {
InputStream doc = new FileInputStream(new File(docPath));
XWPFDocument document = new XWPFDocument(doc);
XHTMLOptions options = XHTMLOptions.create();
OutputStream out = new FileOutputStream(new File(htmlPath));
XHTMLConverter.getInstance().convert(document, out, options);
} catch (FileNotFoundException ex) {
Logger.getLogger(Convert.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(Convert.class.getName()).log(Level.SEVERE, null, ex);
}
}
the error points on this
XWPFDocument document = new XWPFDocument(doc);
I dont know if this is the cause of the error
What I'm trying to convert is .doc file. If its true, can someone give me an code, idea or url anything that can convert .doc/.docx to .pdf/.html