kh-fataoui / xdocreport

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

DOCX to PDF #452

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hi guys,
i am unable to convert the attached docx into pdf and am using latest 1.0.4 
libraries.Please suggest this.

Error:
org.apache.poi.xwpf.converter.core.XWPFConverterException: 
org.apache.xmlbeans.impl.values.XmlValueOutOfRangeException: Invalid integer 
value: 720.0
    at org.apache.poi.xwpf.converter.pdf.PdfConverter.doConvert(PdfConverter.java:59)
    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 com.word.pdf.wordtopdf.createPDF(wordtopdf.java:37)
    at com.word.pdf.wordtopdf.main(wordtopdf.java:18)
Caused by: org.apache.xmlbeans.impl.values.XmlValueOutOfRangeException: Invalid 
integer value: 720.0
    at org.apache.xmlbeans.impl.values.XmlObjectBase$ValueOutOfRangeValidationContext.invalid(XmlObjectBase.java:285)
    at org.apache.xmlbeans.impl.values.JavaIntegerHolder.lex(JavaIntegerHolder.java:50)
    at org.apache.xmlbeans.impl.values.JavaIntegerHolderEx.set_text(JavaIntegerHolderEx.java:40)
    at org.apache.xmlbeans.impl.values.XmlObjectBase.update_from_wscanon_text(XmlObjectBase.java:1135)
    at org.apache.xmlbeans.impl.values.XmlObjectBase.check_dated(XmlObjectBase.java:1274)
    at org.apache.xmlbeans.impl.values.JavaIntegerHolder.bigIntegerValue(JavaIntegerHolder.java:58)
    at org.apache.xmlbeans.impl.values.XmlObjectBase.getBigIntegerValue(XmlObjectBase.java:1504)
    at org.openxmlformats.schemas.wordprocessingml.x2006.main.impl.CTPageMarImpl.getHeader(Unknown Source)
    at org.apache.poi.xwpf.converter.pdf.internal.PdfMapper.visitHeader(PdfMapper.java:180)
    at org.apache.poi.xwpf.converter.pdf.internal.PdfMapper.visitHeader(PdfMapper.java:112)
    at org.apache.poi.xwpf.converter.core.XWPFDocumentVisitor.visitHeaderRef(XWPFDocumentVisitor.java:1098)
    at org.apache.poi.xwpf.converter.core.MasterPageManager.visitHeadersFooters(MasterPageManager.java:213)
    at org.apache.poi.xwpf.converter.core.MasterPageManager.addSection(MasterPageManager.java:180)
    at org.apache.poi.xwpf.converter.core.MasterPageManager.compute(MasterPageManager.java:127)
    at org.apache.poi.xwpf.converter.core.MasterPageManager.initialize(MasterPageManager.java:90)
    at org.apache.poi.xwpf.converter.core.XWPFDocumentVisitor.visitBodyElements(XWPFDocumentVisitor.java:227)
    at org.apache.poi.xwpf.converter.core.XWPFDocumentVisitor.start(XWPFDocumentVisitor.java:194)
    at org.apache.poi.xwpf.converter.pdf.PdfConverter.doConvert(PdfConverter.java:55)
    ... 4 more

Regards,
Kumar

Original issue reported on code.google.com by tulasi.k...@gmail.com on 14 Nov 2014 at 8:53

GoogleCodeExporter commented 9 years ago
> It looks like more a POI problem which expect an integer for 

I agree with you Pascal, but perhaps we could try/catch this error?

@tulasi : please add your docx.

@pascal : it seems that xdocreport users cannot attach document in xdocreport 
forum (size of attached document is not enough)

Original comment by angelo.z...@gmail.com on 18 Nov 2014 at 8:41

GoogleCodeExporter commented 9 years ago
Thanks for your reply.Can you please tell me how can i attach the document.

Original comment by tulasi.k...@gmail.com on 25 Nov 2014 at 5:06

GoogleCodeExporter commented 9 years ago
I asked again google to increase the quota but It takes time It seems.

As a workaround, can you please try posing your content on the mailing list ?

https://groups.google.com/forum/#!forum/xdocreport ? 

Original comment by pascal.leclercq on 25 Nov 2014 at 5:18

GoogleCodeExporter commented 9 years ago
Hi tulasi,

Your problem is because your docx contains not valid integer.

If you unzip you docx and you see the word/document.xml you can see that page 
margin, page size contains dot character : 

---------------------------------------------------------------------
<w:sectPr>
  <w:pgSz w:w="12240.0" w:orient="portrait" w:h="15840.0"/>
  <w:pgMar w:right="1440.0" w:left="1440.0" w:top="1440.0" w:header="720.0" w:gutter="0" w:footer="720.0" w:bottom="1440.0"/>
</w:sectPr>
---------------------------------------------------------------------

For instance header is "720.0" altough it should have "720".

The problem coes from xmlbeans JavaIntegerHolder lex method 
http://grepcode.com/file/repo1.maven.org/maven2/org.apache.xmlbeans/xmlbeans/2.4
.0/org/apache/xmlbeans/impl/values/JavaIntegerHolder.java#46

To fix your problem, lex should remove the '.' like this : 

---------------------------------------------------------------------
int index = s.indexOf( '.' );
if ( index != -1 )
{
  s = s.substring( 0, index );
}
---------------------------------------------------------------------

So I suggest you that you post your problem to POI forum by attaching your docx 
and explaining your problem.

Regard's Angelo

Original comment by angelo.z...@gmail.com on 26 Nov 2014 at 9:28

GoogleCodeExporter commented 9 years ago
Thanks for your reply.I am able to resolve the above exceptions with your 
fix.But getting some other exceptions.
java.lang.ExceptionInInitializerError
    at org.openxmlformats.schemas.wordprocessingml.x2006.main.DocumentDocument$Factory.parse(Unknown Source)
    at org.apache.poi.xwpf.usermodel.XWPFDocument.onDocumentRead(XWPFDocument.java:134)
    at org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:159)
    at org.apache.poi.xwpf.usermodel.XWPFDocument.<init>(XWPFDocument.java:123)
    at com.word.pdf.wordtopdf.createPDF(wordtopdf.java:62)
    at com.word.pdf.wordtopdf.main(wordtopdf.java:20)
Caused by: java.lang.IllegalStateException: Cannot load getContextTypeLoader: 
verify that xbean.jar is on the classpath
    at org.apache.xmlbeans.XmlBeans.buildMethod(XmlBeans.java:181)
    at org.apache.xmlbeans.XmlBeans.buildNoArgMethod(XmlBeans.java:190)
    at org.apache.xmlbeans.XmlBeans.buildGetContextTypeLoaderMethod(XmlBeans.java:200)
    at org.apache.xmlbeans.XmlBeans.<clinit>(XmlBeans.java:126)
    ... 6 more
Caused by: java.lang.ClassNotFoundException: 
org.apache.xmlbeans.impl.schema.SchemaTypeLoaderImpl
    at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:344)
    at org.apache.xmlbeans.XmlBeans.buildMethod(XmlBeans.java:174)
    ... 9 more

Are you able to convert the provided docx to pdf.

Original comment by siva.kar...@gmail.com on 26 Nov 2014 at 7:31

GoogleCodeExporter commented 9 years ago
It's a problem with POI. Please post your question to POI forum.

Thank's

Original comment by angelo.z...@gmail.com on 26 Nov 2014 at 8:20

GoogleCodeExporter commented 9 years ago
Thanq so much for all your help.Can you please provide me POI forum link.I 
didn't find proper link from google.

Original comment by tulasi.k...@gmail.com on 27 Nov 2014 at 6:07