zkh152 / xdocreport

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

Exception while creating a pdf from a docx via XWPF #200

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
In 0.9.8 I was used to the ConverterTypeVia.ITEXT but I can't find it in the 
new 1.0 release
Then I'm testing with ConverterTypeVia.XWPF

1. Get all libs from docxandvelocity.converters-1.0.0 in the build path
2. source code:
InputStream in = new FileInputStream("something.docx"); 
IXDocReport report = XDocReportRegistry.getRegistry().loadReport(in, 
TemplateEngineKind.Velocity);
IContext context = report.createContext();
context.put(MyModel.class.getSimpleName(), myModel);
OutputStream outPdf = new FileOutputStream(new File("./Result.pdf"));
Options options = Options.getTo(ConverterTypeTo.PDF).via(ConverterTypeVia.XWPF);
report.convert(context, options, out); // line 134
3. simply execute

I was expecting a pdf output of my report and I have an Exception:
fr.opensagres.xdocreport.converter.XDocConverterException: 
java.lang.NoSuchMethodError: 
org.apache.poi.xwpf.usermodel.XWPFParagraph.getBody()Lorg/apache/poi/xwpf/usermo
del/IBody;
    at fr.opensagres.xdocreport.document.AbstractXDocReport.convert(AbstractXDocReport.java:745)
    at ....Report.main(Report.java:134)

Then I tried a simplier source code from xdocreport samples:
XWPFDocument document = new XWPFDocument(new FileInputStream("./Result.docx"));
OutputStream outPdf = new FileOutputStream(new File("./Result.pdf"));
PdfOptions options = PdfOptions.create().fontEncoding("windows-1250");
PdfConverter.getInstance().convert(document, outPdf, options); // line 139

and I have the same issue:
Exception in thread "main" java.lang.NoSuchMethodError: 
org.apache.poi.xwpf.usermodel.XWPFParagraph.getBody()Lorg/apache/poi/xwpf/usermo
del/IBody;
    at org.apache.poi.xwpf.converter.core.utils.StylesHelper.getEmbeddedTableCell(StylesHelper.java:73)
    at org.apache.poi.xwpf.converter.core.styles.paragraph.AbstractParagraphValueProvider.getParentTableCell(AbstractParagraphValueProvider.java:116)
    at org.apache.poi.xwpf.converter.core.styles.paragraph.AbstractParagraphValueProvider.getParentTableCell(AbstractParagraphValueProvider.java:41)
    at org.apache.poi.xwpf.converter.core.styles.AbstractValueProvider.getValueFromStyles(AbstractValueProvider.java:89)
    at org.apache.poi.xwpf.converter.core.styles.AbstractValueProvider.internalGetValue(AbstractValueProvider.java:61)
    at org.apache.poi.xwpf.converter.core.styles.AbstractValueProvider.getValue(AbstractValueProvider.java:41)
    at org.apache.poi.xwpf.converter.core.styles.XWPFStylesDocument.getParagraphNumPr(XWPFStylesDocument.java:410)
    at org.apache.poi.xwpf.converter.core.XWPFDocumentVisitor.visitParagraph(XWPFDocumentVisitor.java:270)
    at org.apache.poi.xwpf.converter.core.XWPFDocumentVisitor.visitBodyElements(XWPFDocumentVisitor.java:233)
    at org.apache.poi.xwpf.converter.pdf.internal.PdfMapper.visitFooter(PdfMapper.java:182)
    at org.apache.poi.xwpf.converter.pdf.internal.PdfMapper.visitFooter(PdfMapper.java:108)
    at org.apache.poi.xwpf.converter.core.XWPFDocumentVisitor.visitFooterRef(XWPFDocumentVisitor.java:1094)
    at org.apache.poi.xwpf.converter.core.MasterPageManager.visitHeadersFooters(MasterPageManager.java:208)
    at org.apache.poi.xwpf.converter.core.MasterPageManager.addSection(MasterPageManager.java:166)
    at org.apache.poi.xwpf.converter.core.MasterPageManager.compute(MasterPageManager.java:113)
    at org.apache.poi.xwpf.converter.core.MasterPageManager.initialize(MasterPageManager.java:83)
    at org.apache.poi.xwpf.converter.core.XWPFDocumentVisitor.visitBodyElements(XWPFDocumentVisitor.java:219)
    at org.apache.poi.xwpf.converter.core.XWPFDocumentVisitor.start(XWPFDocumentVisitor.java:186)
    at org.apache.poi.xwpf.converter.pdf.PdfConverter.doConvert(PdfConverter.java:55)
    at org.apache.poi.xwpf.converter.pdf.PdfConverter.doConvert(PdfConverter.java:37)
    at org.apache.poi.xwpf.converter.core.AbstractXWPFConverter.convert(AbstractXWPFConverter.java:45)
    at ....Report.main(Report.java:139)

All that with:
docxandvelocity.converters-1.0.0
ConvertDocxResumeToPDF.java
DocxResume.docx

With the 0.9.8, it was ok with iText except some graphic issues that would have 
been resolved in the 1.0.0 (background color in table, footer page number, ...)

What I'm doing wrong ? Am I doing something wrong ?

Thanks for all your work

Original issue reported on code.google.com by manudrag...@gmail.com on 3 Dec 2012 at 2:54

GoogleCodeExporter commented 9 years ago
Hi,

At first as you have seen in 1.0.0, ConverterTypeVia.ITEXT doesn't exists and 
it is replaced with ConverterTypeVia.XWPF

I have tested the zip and it works well? Have you tried with clean project 
(just with JARs coming from the zip?) Are you sure to add in your claspath the 
whole JARs?

ConvertDocxResumeToPDF, DocxProjectWithVelocityList2PDF works for me? Have you 
problem with this samples?

Perhaps your problem is with your docx? If you have Eclipse, perhaps you could 
attach your Java project and tell me which reports fails?

Regards Angelo

Original comment by angelo.z...@gmail.com on 3 Dec 2012 at 3:27

GoogleCodeExporter commented 9 years ago
It's ok with a new clean project and jars from docxandvelocity.converters-1.0.0
sorry for disturbing

Original comment by manudrag...@gmail.com on 4 Dec 2012 at 11:02

GoogleCodeExporter commented 9 years ago
Ok tha'ts cool. i close this isuue.

Regards Angelo

Original comment by angelo.z...@gmail.com on 4 Dec 2012 at 1:08

GoogleCodeExporter commented 9 years ago
I'm getting this problem with mine:

java.lang.NoSuchMethodError: 
org.apache.poi.xwpf.usermodel.XWPFParagraph.getBody()Lorg/apache/poi/xwpf/usermo
del/IBody;
    at org.apache.poi.xwpf.converter.core.utils.StylesHelper.getEmbeddedTableCell(StylesHelper.java:73)
    at org.apache.poi.xwpf.converter.core.styles.paragraph.AbstractParagraphValueProvider.getParentTableCell(AbstractParagraphValueProvider.java:116)
    at org.apache.poi.xwpf.converter.core.styles.paragraph.AbstractParagraphValueProvider.getParentTableCell(AbstractParagraphValueProvider.java:41)
    at org.apache.poi.xwpf.converter.core.styles.AbstractValueProvider.getValueFromStyles(AbstractValueProvider.java:89)
    at org.apache.poi.xwpf.converter.core.styles.AbstractValueProvider.internalGetValue(AbstractValueProvider.java:61)
    at org.apache.poi.xwpf.converter.core.styles.AbstractValueProvider.getValue(AbstractValueProvider.java:41)
    at org.apache.poi.xwpf.converter.core.styles.XWPFStylesDocument.getParagraphNumPr(XWPFStylesDocument.java:423)
    at org.apache.poi.xwpf.converter.core.XWPFDocumentVisitor.visitParagraph(XWPFDocumentVisitor.java:278)
    at org.apache.poi.xwpf.converter.core.XWPFDocumentVisitor.visitBodyElements(XWPFDocumentVisitor.java:241)
    at org.apache.poi.xwpf.converter.core.XWPFDocumentVisitor.start(XWPFDocumentVisitor.java:193)
    at org.apache.poi.xwpf.converter.pdf.PdfConverter.doConvert(PdfConverter.java:55)
    at org.apache.poi.xwpf.converter.pdf.PdfConverter.doConvert(PdfConverter.java:37)
    at org.apache.poi.xwpf.converter.core.AbstractXWPFConverter.convert(AbstractXWPFConverter.java:45)
    at easy.ConvertDocxBigToPDF.main(ConvertDocxBigToPDF.java:39)

My code is:

File inFile = new File( "D:\\3pageDoc.docx" );
            InputStream in = new FileInputStream(inFile); 

            // 1) Load docx with POI XWPFDocument
            XWPFDocument document = new XWPFDocument(in);

            // 2) Convert POI XWPFDocument 2 PDF with iText
            File outFile = new File( "D:/Converted_docx.pdf" );
            outFile.getParentFile().mkdirs();

            OutputStream out = new FileOutputStream( outFile );
            PdfOptions options = PdfOptions.create().fontEncoding( "windows-1250" );
            PdfConverter.getInstance().convert(document, out, options);

Original comment by dannypha...@gmail.com on 21 Nov 2013 at 4:36