opensagres / xdocreport

XDocReport means XML Document reporting. It's Java API to merge XML document created with MS Office (docx) or OpenOffice (odt), LibreOffice (odt) with a Java model to generate report and convert it if you need to another format (PDF, XHTML...).
https://github.com/opensagres/xdocreport
1.21k stars 372 forks source link

can not open the PDF converted by docx #107

Open yonglih opened 8 years ago

yonglih commented 8 years ago

I use IntelliJ to product, test by these steps below: // 1) Load DOCX into XWPFDocument InputStream in= new FileInputStream(new File("HelloWord.docx")); XWPFDocument document = new XWPFDocument(in);

// 2) Prepare Pdf options PdfOptions options = PdfOptions.create();

// 3) Convert XWPFDocument to Pdf OutputStream out = new FileOutputStream(new File("HelloWord.pdf")); PdfConverter.getInstance().convert(document, out, options);

then,it can product a PDF file,but throw exceptions below: java.lang.NoClassDefFoundError: Could not initialize class org.apache.poi.xwpf.usermodel.XWPFDocument. and the PDF file can not be opened.

could you give me some suggestions to resolve the problem?

angelozerr commented 8 years ago

It's a problem with classpath. If you use maven, it should work. Check you hav ethe well POI Jar

yonglih commented 8 years ago

I will test,thank you!

yonglih commented 8 years ago

org.apache.poi.POIXMLException: org.apache.poi.openxml4j.exceptions.InvalidFormatException: Package should contain a content type part [M1.13]

How to resolve this problem?

angelozerr commented 8 years ago

@yonglih your problem is about POI and not about XDocReport. So please post your question to the POI forum. Your error seems that your docx is not a valid docx.

yonglih commented 8 years ago

Sorry.Actually,I have tried to use XDocReport to convert docx to PDF,but failed.So,there will be some problems about XDocReport to show you below: I just copy the instance of code to run ,but throw a exception below, java.io.IOException: InputStream is not a zip. these are related codes: InputStream in = DocToPdf.class .getResourceAsStream("DocxProjectWithVelocity_Out.docx"); IXDocReport report = XDocReportRegistry.getRegistry().loadReport( in, TemplateEngineKind.Velocity);

angelozerr commented 8 years ago

@yonglih I have not a lot of time. If you need help, please share your project. It seems taht DocxProjectWithVelocity_Out.docx is not a valid docx.

yonglih commented 8 years ago

OK,I will check,thank you.