Page 1 of 1

Not able to convert some .docx files to .pdf

PostPosted: Tue Apr 15, 2014 5:45 am
by mperezm77
Hello,

I'm using this template to convert some .docx files to .pdf.

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
import java.util.HashMap;

import org.docx4j.XmlUtils;
import org.docx4j.convert.out.pdf.viaXSLFO.PdfSettings;
import org.docx4j.fonts.IdentityPlusMapper;
import org.docx4j.fonts.Mapper;
import org.docx4j.fonts.PhysicalFont;
import org.docx4j.fonts.PhysicalFonts;
import org.docx4j.jaxb.Context;
import org.docx4j.openpackaging.io.SaveToZipFile;
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
import org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart;
import org.docx4j.convert.out.pdf.PdfConversion;

public class DocxEdit {

public static void main(String[] args) throws Exception {

// 1) Load DOCX into WordprocessingMLPackage

InputStream is = new FileInputStream(new File("Documento.docx"));
WordprocessingMLPackage wordMLPackage2 = WordprocessingMLPackage.load(is));

// 2) Prepare Pdf settings

PdfSettings pdfSettings = new PdfSettings();

// 3) Convert WordprocessingMLPackage to Pdf

org.docx4j.convert.out.pdf.PdfConversion conversion = new org.docx4j.convert.out.pdf.viaXSLFO.Conversion(wordMLPackage2);

OutputStream out = new FileOutputStream(new File("test.pdf"));
conversion.output(out,pdfSettings);

}

}


Some files are working fine but other are not. The ones not working shows the next error:

java.lang.NullPointerException
at org.docx4j.model.PropertyResolver.init(PropertyResolver.java:171)
at org.docx4j.model.PropertyResolver.<init>(PropertyResolver.java:149)
at org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart.getPropertyResolver(MainDocumentPart.java:154)
at org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart.fontsInUse(MainDocumentPart.java:211)
at org.docx4j.openpackaging.packages.WordprocessingMLPackage.setFontMapper(WordprocessingMLPackage.java:323)
at org.docx4j.openpackaging.packages.WordprocessingMLPackage.setFontMapper(WordprocessingMLPackage.java:303)
at org.docx4j.openpackaging.packages.WordprocessingMLPackage.getFontMapper(WordprocessingMLPackage.java:354)
at org.docx4j.convert.out.common.preprocess.PartialDeepCopy.process(PartialDeepCopy.java:93)
at org.docx4j.convert.out.common.Preprocess.process(Preprocess.java:75)
at org.docx4j.convert.out.common.Preprocess.process(Preprocess.java:133)
at org.docx4j.convert.out.common.AbstractWmlExporter.preprocess(AbstractWmlExporter.java:51)
at org.docx4j.convert.out.common.AbstractWmlExporter.preprocess(AbstractWmlExporter.java:32)
at org.docx4j.convert.out.common.AbstractExporter.export(AbstractExporter.java:63)
at org.docx4j.Docx4J.toFO(Docx4J.java:475)
at org.docx4j.Docx4J.toPDF(Docx4J.java:489)
at org.docx4j.convert.out.pdf.viaXSLFO.Conversion.output(Conversion.java:70)
at DocxEdit.main(DocxEdit.java:104)
Exception in thread "main" org.docx4j.openpackaging.exceptions.Docx4JException: Exception exporting package
at org.docx4j.convert.out.common.AbstractExporter.export(AbstractExporter.java:97)
at org.docx4j.Docx4J.toFO(Docx4J.java:475)
at org.docx4j.Docx4J.toPDF(Docx4J.java:489)
at org.docx4j.convert.out.pdf.viaXSLFO.Conversion.output(Conversion.java:70)
at DocxEdit.main(DocxEdit.java:104)
Caused by: org.docx4j.openpackaging.exceptions.Docx4JException: Error setting font mapper on copy
at org.docx4j.convert.out.common.preprocess.PartialDeepCopy.process(PartialDeepCopy.java:98)
at org.docx4j.convert.out.common.Preprocess.process(Preprocess.java:75)
at org.docx4j.convert.out.common.Preprocess.process(Preprocess.java:133)
at org.docx4j.convert.out.common.AbstractWmlExporter.preprocess(AbstractWmlExporter.java:51)
at org.docx4j.convert.out.common.AbstractWmlExporter.preprocess(AbstractWmlExporter.java:32)
at org.docx4j.convert.out.common.AbstractExporter.export(AbstractExporter.java:63)
... 4 more
Caused by: java.lang.NullPointerException
at org.docx4j.model.PropertyResolver.init(PropertyResolver.java:171)
at org.docx4j.model.PropertyResolver.<init>(PropertyResolver.java:149)
at org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart.getPropertyResolver(MainDocumentPart.java:154)
at org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart.fontsInUse(MainDocumentPart.java:211)
at org.docx4j.openpackaging.packages.WordprocessingMLPackage.setFontMapper(WordprocessingMLPackage.java:323)
at org.docx4j.convert.out.common.preprocess.PartialDeepCopy.process(PartialDeepCopy.java:93)
... 9 more


You web application (http://webapp.docx4java.org/OnlineDemo/ ... f_fop.html) doesn't seem to work with those files neither.
What is the problem with them?

Mi system:
Windows 7 64bits
Java JDK 1.7.0_51-b13
Tried with docx4j-3.0.1 and docx4j-3.1.0-beta

Thanks!!

Re: Not able to convert some .docx files to .pdf

PostPosted: Tue Apr 15, 2014 9:04 pm
by jason
Hi there, these documents can be considered "edge cases" because they both have an empty styles definition part.

That said, I've commited https://github.com/plutext/docx4j/commi ... c442bb23f0 which allows the conversion to proceed.

Thanks for the report.

Re: Not able to convert some .docx files to .pdf

PostPosted: Tue Apr 15, 2014 10:58 pm
by mperezm77
Does it means that the next nigthly will be able to convert those files, or it just will not give an error message?

Regarding the files, one of the files was created using Wordpad software from Microsoft and the other one is a docx file example downloaded from internet. How can I set the style definition part?

Thanks you for your support!!

Re: Not able to convert some .docx files to .pdf

PostPosted: Wed Apr 16, 2014 1:50 pm
by jason
It'll convert the files.

Re: Not able to convert some .docx files to .pdf

PostPosted: Fri Apr 18, 2014 5:25 am
by rich
I'm using code to covert to a PDF exactly the same as mperezm77, and getting very similar errors. The only difference is I'm converting docx to pdf. However, the documents I am using are generated from scratch using docx4j. I suspect I might be missing some important things that are making the pdf conversion fail, but I'm completely lost as to what they are. I attached a sample of a document I'm trying to convert. Did I miss a document part while building it or something?

Re: Not able to convert some .docx files to .pdf

PostPosted: Fri Apr 18, 2014 9:54 am
by jason
Hi there Rich, which version of docx4j are you using?

Your docx works for me. You could use the 3.1.0 beta, or the more recent http://www.docx4java.org/docx4j/docx4j- ... 140418.jar (which mperezm77 would need).

The webapp (see menu above) can output your docx as PDF; it is using 3.1.0 beta.

If you continue to have problems, please post the stack trace.

Re: Not able to convert some .docx files to .pdf

PostPosted: Sat Apr 19, 2014 1:03 am
by rich
Hi Jason,
Thank you for your speedy response.
I am using the docx4j 3.1.0 beta. I replaced the 3.0.0 version I was using with the beta in the hopes that it would work. I'm still getting the errors unfortunately. It may be because I'm using a web application, and I can't find the version of Java they are using on the host servers. In my IDE I am using Java JRE6.

Here's the code I'm using:
Code: Select all
InputStream is = new FileInputStream(new File("/tmp/" + eventName + fileNameSuffix + ".docx"));
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(is);
           
File outputFile = new File("/tmp/" + eventName + fileNameSuffix + ".pdf");
OutputStream os = new FileOutputStream(outputFile);

PdfSettings pdfSettings = new PdfSettings();
org.docx4j.convert.out.pdf.PdfConversion conversion = new org.docx4j.convert.out.pdf.viaXSLFO.Conversion(wordMLPackage);
           
OutputStream out = new FileOutputStream(outputFile);
conversion.output(out, pdfSettings);


I know that it is generating the docx version properly, but when I try to save it as a pdf it throws the following errors from the line [conversion.output(out, pdfSettings);]:
Code: Select all
2014-04-18T13:48:22.613486+00:00 app[web.1]: java.lang.NumberFormatException: Zero length BigInteger
2014-04-18T13:48:22.614293+00:00 app[web.1]:    at java.math.BigInteger.<init>(BigInteger.java:296)
2014-04-18T13:48:22.614400+00:00 app[web.1]:    at java.math.BigInteger.<init>(BigInteger.java:470)
2014-04-18T13:48:22.614501+00:00 app[web.1]:    at com.sun.xml.internal.bind.DatatypeConverterImpl._parseInteger(DatatypeConverterImpl.java:76)
2014-04-18T13:48:22.614600+00:00 app[web.1]:    at com.sun.xml.internal.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl$22.parse(RuntimeBuiltinLeafInfoImpl.java:730)
2014-04-18T13:48:22.614702+00:00 app[web.1]:    at com.sun.xml.internal.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl$22.parse(RuntimeBuiltinLeafInfoImpl.java:728)
2014-04-18T13:48:22.614798+00:00 app[web.1]:    at com.sun.xml.internal.bind.v2.runtime.reflect.TransducedAccessor$CompositeTransducedAccessorImpl.parse(TransducedAccessor.java:230)
2014-04-18T13:48:22.615091+00:00 app[web.1]:    at com.sun.xml.internal.bind.v2.runtime.unmarshaller.StructureLoader.startElement(StructureLoader.java:191)
2014-04-18T13:48:22.615200+00:00 app[web.1]:    at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:470)
2014-04-18T13:48:22.615296+00:00 app[web.1]:    at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:448)
2014-04-18T13:48:22.615391+00:00 app[web.1]:    at com.sun.xml.internal.bind.v2.runtime.unmarshaller.InterningXmlVisitor.startElement(InterningXmlVisitor.java:60)
2014-04-18T13:48:22.615486+00:00 app[web.1]:    at com.sun.xml.internal.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:137)
2014-04-18T13:48:22.615583+00:00 app[web.1]:    at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:228)
2014-04-18T13:48:22.615679+00:00 app[web.1]:    at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:265)
2014-04-18T13:48:22.615774+00:00 app[web.1]:    at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:234)
2014-04-18T13:48:22.615868+00:00 app[web.1]:    at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:265)
2014-04-18T13:48:22.615962+00:00 app[web.1]:    at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:234)
2014-04-18T13:48:22.616193+00:00 app[web.1]:    at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:265)
2014-04-18T13:48:22.616299+00:00 app[web.1]:    at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:234)
2014-04-18T13:48:22.616396+00:00 app[web.1]:    at com.sun.xml.internal.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:111)
2014-04-18T13:48:22.616495+00:00 app[web.1]:    at com.sun.xml.internal.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:94)
2014-04-18T13:48:22.616627+00:00 app[web.1]:    at com.sun.xml.internal.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:87)
2014-04-18T13:48:22.616758+00:00 app[web.1]:    at com.sun.xml.internal.bind.v2.runtime.BinderImpl.associativeUnmarshal(BinderImpl.java:145)
2014-04-18T13:48:22.616886+00:00 app[web.1]:    at com.sun.xml.internal.bind.v2.runtime.BinderImpl.unmarshal(BinderImpl.java:116)
2014-04-18T13:48:22.617014+00:00 app[web.1]:    at org.docx4j.openpackaging.parts.JaxbXmlPartXPathAware.unmarshal(JaxbXmlPartXPathAware.java:360)
2014-04-18T13:48:22.617142+00:00 app[web.1]:    at org.docx4j.openpackaging.parts.JaxbXmlPart.getJaxbElement(JaxbXmlPart.java:136)
2014-04-18T13:48:22.617432+00:00 app[web.1]:    at org.docx4j.convert.out.common.preprocess.PartialDeepCopy.deepCopyContent(PartialDeepCopy.java:243)
2014-04-18T13:48:22.617700+00:00 app[web.1]:    at org.docx4j.convert.out.common.preprocess.PartialDeepCopy.copyPart(PartialDeepCopy.java:227)
2014-04-18T13:48:22.617842+00:00 app[web.1]:    at org.docx4j.convert.out.common.preprocess.PartialDeepCopy.deepCopyPart(PartialDeepCopy.java:203)
2014-04-18T13:48:22.617969+00:00 app[web.1]:    at org.docx4j.convert.out.common.preprocess.PartialDeepCopy.deepCopyRelationships(PartialDeepCopy.java:188)
2014-04-18T13:48:22.618191+00:00 app[web.1]:    at org.docx4j.convert.out.common.preprocess.PartialDeepCopy.process(PartialDeepCopy.java:79)
2014-04-18T13:48:22.618407+00:00 app[web.1]:    at org.docx4j.convert.out.common.Preprocess.process(Preprocess.java:75)
2014-04-18T13:48:22.618627+00:00 app[web.1]:    at org.docx4j.convert.out.common.Preprocess.process(Preprocess.java:133)
2014-04-18T13:48:22.618846+00:00 app[web.1]:    at org.docx4j.convert.out.common.AbstractWmlExporter.preprocess(AbstractWmlExporter.java:51)
2014-04-18T13:48:22.619846+00:00 app[web.1]:    at org.docx4j.convert.out.common.AbstractWmlExporter.preprocess(AbstractWmlExporter.java:32)
2014-04-18T13:48:22.620036+00:00 app[web.1]:    at org.docx4j.convert.out.common.AbstractExporter.export(AbstractExporter.java:63)
2014-04-18T13:48:22.620168+00:00 app[web.1]:    at org.docx4j.Docx4J.toFO(Docx4J.java:475)
2014-04-18T13:48:22.620434+00:00 app[web.1]:    at org.docx4j.Docx4J.toPDF(Docx4J.java:489)
2014-04-18T13:48:22.620753+00:00 app[web.1]:    at org.docx4j.convert.out.pdf.viaXSLFO.Conversion.output(Conversion.java:70)
2014-04-18T13:48:22.620886+00:00 app[web.1]:    at closingDocument.createDocument(closingDocument.java:504)
2014-04-18T13:48:22.621017+00:00 app[web.1]:    at closingDocument.doGet(closingDocument.java:2461)
2014-04-18T13:48:22.621148+00:00 app[web.1]:    at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
2014-04-18T13:48:22.621280+00:00 app[web.1]:    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
2014-04-18T13:48:22.621444+00:00 app[web.1]:    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
2014-04-18T13:48:22.621573+00:00 app[web.1]:    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
2014-04-18T13:48:22.621711+00:00 app[web.1]:    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
2014-04-18T13:48:22.621845+00:00 app[web.1]:    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
2014-04-18T13:48:22.622189+00:00 app[web.1]:    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
2014-04-18T13:48:22.622385+00:00 app[web.1]:    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
2014-04-18T13:48:22.622514+00:00 app[web.1]:    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
2014-04-18T13:48:22.622671+00:00 app[web.1]:    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
2014-04-18T13:48:22.622866+00:00 app[web.1]:    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1008)
2014-04-18T13:48:22.623066+00:00 app[web.1]:    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
2014-04-18T13:48:22.623205+00:00 app[web.1]:    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1686)
2014-04-18T13:48:22.623354+00:00 app[web.1]:    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146)
2014-04-18T13:48:22.623481+00:00 app[web.1]:    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
2014-04-18T13:48:22.623608+00:00 app[web.1]:    at java.lang.Thread.run(Thread.java:679)
2014-04-18T13:48:22.624353+00:00 app[web.1]: org.docx4j.openpackaging.exceptions.Docx4JException: Exception exporting package
2014-04-18T13:48:22.624623+00:00 app[web.1]:    at org.docx4j.convert.out.common.AbstractExporter.export(AbstractExporter.java:93)
2014-04-18T13:48:22.624751+00:00 app[web.1]:    at org.docx4j.Docx4J.toFO(Docx4J.java:475)
2014-04-18T13:48:22.624881+00:00 app[web.1]:    at org.docx4j.Docx4J.toPDF(Docx4J.java:489)
2014-04-18T13:48:22.625013+00:00 app[web.1]:    at org.docx4j.convert.out.pdf.viaXSLFO.Conversion.output(Conversion.java:70)
2014-04-18T13:48:22.625146+00:00 app[web.1]:    at closingDocument.createDocument(closingDocument.java:504)
2014-04-18T13:48:22.625282+00:00 app[web.1]:    at closingDocument.doGet(closingDocument.java:2461)
2014-04-18T13:48:22.625414+00:00 app[web.1]:    at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
2014-04-18T13:48:22.625545+00:00 app[web.1]:    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
2014-04-18T13:48:22.625698+00:00 app[web.1]:    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
2014-04-18T13:48:22.625958+00:00 app[web.1]:    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
2014-04-18T13:48:22.626099+00:00 app[web.1]:    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
2014-04-18T13:48:22.626230+00:00 app[web.1]:    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
2014-04-18T13:48:22.626360+00:00 app[web.1]:    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
2014-04-18T13:48:22.626492+00:00 app[web.1]:    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
2014-04-18T13:48:22.626623+00:00 app[web.1]:    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
2014-04-18T13:48:22.626753+00:00 app[web.1]:    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
2014-04-18T13:48:22.626885+00:00 app[web.1]:    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1008)
2014-04-18T13:48:22.627015+00:00 app[web.1]:    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
2014-04-18T13:48:22.627145+00:00 app[web.1]:    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1686)
2014-04-18T13:48:22.627417+00:00 app[web.1]:    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146)
2014-04-18T13:48:22.627558+00:00 app[web.1]:    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
2014-04-18T13:48:22.627689+00:00 app[web.1]:    at java.lang.Thread.run(Thread.java:679)
2014-04-18T13:48:22.627995+00:00 app[web.1]: Caused by: java.lang.IllegalArgumentException: Can't clone a null argument
2014-04-18T13:48:22.628133+00:00 app[web.1]:    at org.docx4j.XmlUtils.deepCopy(XmlUtils.java:727)
2014-04-18T13:48:22.628267+00:00 app[web.1]:    at org.docx4j.convert.out.common.preprocess.PartialDeepCopy.deepCopyContent(PartialDeepCopy.java:243)
2014-04-18T13:48:22.628397+00:00 app[web.1]:    at org.docx4j.convert.out.common.preprocess.PartialDeepCopy.copyPart(PartialDeepCopy.java:227)
2014-04-18T13:48:22.628527+00:00 app[web.1]:    at org.docx4j.convert.out.common.preprocess.PartialDeepCopy.deepCopyPart(PartialDeepCopy.java:203)
2014-04-18T13:48:22.628657+00:00 app[web.1]:    at org.docx4j.convert.out.common.preprocess.PartialDeepCopy.deepCopyRelationships(PartialDeepCopy.java:188)
2014-04-18T13:48:22.628788+00:00 app[web.1]:    at org.docx4j.convert.out.common.preprocess.PartialDeepCopy.process(PartialDeepCopy.java:79)
2014-04-18T13:48:22.629038+00:00 app[web.1]:    at org.docx4j.convert.out.common.Preprocess.process(Preprocess.java:75)
2014-04-18T13:48:22.629184+00:00 app[web.1]:    at org.docx4j.convert.out.common.Preprocess.process(Preprocess.java:133)
2014-04-18T13:48:22.629316+00:00 app[web.1]:    at org.docx4j.convert.out.common.AbstractWmlExporter.preprocess(AbstractWmlExporter.java:51)
2014-04-18T13:48:22.629445+00:00 app[web.1]:    at org.docx4j.convert.out.common.AbstractWmlExporter.preprocess(AbstractWmlExporter.java:32)
2014-04-18T13:48:22.629575+00:00 app[web.1]:    at org.docx4j.convert.out.common.AbstractExporter.export(AbstractExporter.java:63)
2014-04-18T13:48:22.629707+00:00 app[web.1]:    ... 21 more

Re: Not able to convert some .docx files to .pdf

PostPosted: Sat Apr 19, 2014 1:23 am
by rich
I had a thought and changed my code, and now I'm getting different errors, so I'll post it all again.

Here's the new code:
Code: Select all
try {
      File finalFile = new java.io.File("/tmp/" + eventName + fileNameSuffix + ".docx");
      wordMLPackage.save(finalFile);
} catch (Docx4JException e) {
      e.printStackTrace();
}

try {
      File outputFile = new File("/tmp/" + eventName + fileNameSuffix + ".pdf");
      OutputStream os = new FileOutputStream(outputFile);

      PdfSettings pdfSettings = new PdfSettings();
      org.docx4j.convert.out.pdf.PdfConversion conversion = new org.docx4j.convert.out.pdf.viaXSLFO.Conversion(wordMLPackage);
           
      OutputStream out = new FileOutputStream(outputFile);
      conversion.output(out, pdfSettings);
} catch (Exception e) {
        e.printStackTrace();
}


I suspected it may not be loading the file properly. So instead of saving the file and reloading it, I'm now passing the wordMLPackage I'd been building directly to the converter. It's still failing on the conversion.output line though. The new errors it's throwing are:
Code: Select all
2014-04-18T14:12:27.380815+00:00 app[web.1]: org.docx4j.openpackaging.exceptions.Docx4JException: Exception exporting package
2014-04-18T14:12:27.381144+00:00 app[web.1]:    at org.docx4j.convert.out.common.AbstractExporter.export(AbstractExporter.java:93)
2014-04-18T14:12:27.381205+00:00 app[web.1]:    at org.docx4j.Docx4J.toFO(Docx4J.java:475)
2014-04-18T14:12:27.381407+00:00 app[web.1]:    at org.docx4j.Docx4J.toPDF(Docx4J.java:489)
2014-04-18T14:12:27.381407+00:00 app[web.1]:    at org.docx4j.convert.out.pdf.viaXSLFO.Conversion.output(Conversion.java:70)
2014-04-18T14:12:27.381407+00:00 app[web.1]:    at closingDocument.createDocument(closingDocument.java:504)
2014-04-18T14:12:27.381407+00:00 app[web.1]:    at closingDocument.doGet(closingDocument.java:2461)
2014-04-18T14:12:27.381535+00:00 app[web.1]:    at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
2014-04-18T14:12:27.381645+00:00 app[web.1]:    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
2014-04-18T14:12:27.381645+00:00 app[web.1]:    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
2014-04-18T14:12:27.381645+00:00 app[web.1]:    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
2014-04-18T14:12:27.381795+00:00 app[web.1]:    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
2014-04-18T14:12:27.381874+00:00 app[web.1]:    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
2014-04-18T14:12:27.382063+00:00 app[web.1]:    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
2014-04-18T14:12:27.382063+00:00 app[web.1]:    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
2014-04-18T14:12:27.382130+00:00 app[web.1]:    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
2014-04-18T14:12:27.382555+00:00 app[web.1]:    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
2014-04-18T14:12:27.382623+00:00 app[web.1]:    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1008)
2014-04-18T14:12:27.382693+00:00 app[web.1]:    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
2014-04-18T14:12:27.382781+00:00 app[web.1]:    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1686)
2014-04-18T14:12:27.382997+00:00 app[web.1]:    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146)
2014-04-18T14:12:27.383065+00:00 app[web.1]:    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
2014-04-18T14:12:27.383188+00:00 app[web.1]:    at java.lang.Thread.run(Thread.java:679)
2014-04-18T14:12:27.384171+00:00 app[web.1]: Caused by: java.lang.NumberFormatException: Zero length BigInteger
2014-04-18T14:12:27.384353+00:00 app[web.1]:    at java.math.BigInteger.<init>(BigInteger.java:296)
2014-04-18T14:12:27.384393+00:00 app[web.1]:    at java.math.BigInteger.<init>(BigInteger.java:470)
2014-04-18T14:12:27.384639+00:00 app[web.1]:    at com.sun.xml.internal.bind.DatatypeConverterImpl._parseInteger(DatatypeConverterImpl.java:76)
2014-04-18T14:12:27.384756+00:00 app[web.1]:    at com.sun.xml.internal.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl$22.parse(RuntimeBuiltinLeafInfoImpl.java:730)
2014-04-18T14:12:27.385156+00:00 app[web.1]:    at com.sun.xml.internal.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl$22.parse(RuntimeBuiltinLeafInfoImpl.java:728)
2014-04-18T14:12:27.385225+00:00 app[web.1]:    at com.sun.xml.internal.bind.v2.runtime.reflect.TransducedAccessor$CompositeTransducedAccessorImpl.parse(TransducedAccessor.java:230)
2014-04-18T14:12:27.385293+00:00 app[web.1]:    at com.sun.xml.internal.bind.v2.runtime.unmarshaller.StructureLoader.startElement(StructureLoader.java:191)
2014-04-18T14:12:27.385415+00:00 app[web.1]:    at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:470)
2014-04-18T14:12:27.385415+00:00 app[web.1]:    at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:448)
2014-04-18T14:12:27.385486+00:00 app[web.1]:    at com.sun.xml.internal.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:137)
2014-04-18T14:12:27.385653+00:00 app[web.1]:    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:504)
2014-04-18T14:12:27.385653+00:00 app[web.1]:    at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:182)
2014-04-18T14:12:27.386418+00:00 app[web.1]:    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:353)
2014-04-18T14:12:27.386664+00:00 app[web.1]:    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2732)
2014-04-18T14:12:27.386806+00:00 app[web.1]:    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:625)
2014-04-18T14:12:27.386897+00:00 app[web.1]:    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:116)
2014-04-18T14:12:27.387019+00:00 app[web.1]:    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:488)
2014-04-18T14:12:27.387019+00:00 app[web.1]:    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:819)
2014-04-18T14:12:27.387084+00:00 app[web.1]:    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:748)
2014-04-18T14:12:27.387196+00:00 app[web.1]:    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:123)
2014-04-18T14:12:27.387581+00:00 app[web.1]:    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1208)
2014-04-18T14:12:27.387947+00:00 app[web.1]:    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:525)
2014-04-18T14:12:27.388171+00:00 app[web.1]:    at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:200)
2014-04-18T14:12:27.388312+00:00 app[web.1]:    at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:179)
2014-04-18T14:12:27.388583+00:00 app[web.1]:    at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:230)
2014-04-18T14:12:27.389224+00:00 app[web.1]:    at org.docx4j.XmlUtils.deepCopy(XmlUtils.java:760)
2014-04-18T14:12:27.389343+00:00 app[web.1]:    at org.docx4j.convert.out.common.preprocess.PartialDeepCopy.deepCopyContent(PartialDeepCopy.java:243)
2014-04-18T14:12:27.389343+00:00 app[web.1]:    at org.docx4j.convert.out.common.preprocess.PartialDeepCopy.copyPart(PartialDeepCopy.java:227)
2014-04-18T14:12:27.389466+00:00 app[web.1]:    at org.docx4j.convert.out.common.preprocess.PartialDeepCopy.deepCopyPart(PartialDeepCopy.java:203)
2014-04-18T14:12:27.389466+00:00 app[web.1]:    at org.docx4j.convert.out.common.preprocess.PartialDeepCopy.deepCopyRelationships(PartialDeepCopy.java:188)
2014-04-18T14:12:27.391232+00:00 heroku[router]: at=info method=GET path=/closingDocument/closingDocument/?resId=a0mG0000003rpFiIAI&serverURL=https%3A%2F%2Fc.na11.visual.force.com%2Fservices%2FSoap%2Fc%2F27.0%2F00DG0000000jsdw&sId=00DG0000000jsdw%21AREAQKuakggqb6ggbxbIyQwLqESHzIi0ADClbG0.n9R32HPs2AUDkzgc2hsn6tTLI7Nb1R6YiA0oTrYzIln_s_R.mNl__.Dd&userID=005G0000003IRDYIA4 host=closingdocument.herokuapp.com request_id=cb8b799d-5b78-4f2c-bdad-f9fc067cdb07 fwd="67.99.163.24" dyno=web.1 connect=2ms service=2545ms status=302 bytes=172
2014-04-18T14:12:27.389716+00:00 app[web.1]:    at org.docx4j.convert.out.common.preprocess.PartialDeepCopy.process(PartialDeepCopy.java:79)
2014-04-18T14:12:27.389716+00:00 app[web.1]:    at org.docx4j.convert.out.common.Preprocess.process(Preprocess.java:75)
2014-04-18T14:12:27.389716+00:00 app[web.1]:    at org.docx4j.convert.out.common.Preprocess.process(Preprocess.java:133)
2014-04-18T14:12:27.389716+00:00 app[web.1]:    at org.docx4j.convert.out.common.AbstractWmlExporter.preprocess(AbstractWmlExporter.java:51)
2014-04-18T14:12:27.389861+00:00 app[web.1]:    at org.docx4j.convert.out.common.AbstractWmlExporter.preprocess(AbstractWmlExporter.java:32)
2014-04-18T14:12:27.389861+00:00 app[web.1]:    at org.docx4j.convert.out.common.AbstractExporter.export(AbstractExporter.java:63)
2014-04-18T14:12:27.389861+00:00 app[web.1]:    ... 21 more

Re: Not able to convert some .docx files to .pdf

PostPosted: Sat Apr 19, 2014 9:07 am
by jason
Notice that in both cases the error is:

Code: Select all
java.lang.NumberFormatException: Zero length BigInteger
:
at com.sun.xml.internal.bind.DatatypeConverterImpl._parseInteger


That's a symptom of a bad version of JAXB, probably in an early Sun/Oracle Java 6. (The start of the docx4j logs will tell you what Java you are running).

If you are not able to use JAXB reference implementation via the endorsed dir mechanism, it may be easiest to switch to MOXy JAXB implementation.

For that, you need to add docx4j-MOXy-JAXBContext and the relevant org.eclipse.persistence jars.

See further docx-java-f6/moxy-t1242.html

Re: Not able to convert some .docx files to .pdf

PostPosted: Tue Apr 22, 2014 1:50 am
by rich
Jason,
Thanks again for your help. I was using an outdated JAXB implementation, so I went out and replaced it with JAXB 2.2.7. Unfortunately I'm still getting exceptions that are preventing the conversion. This time around it seems to be related to fonts though. I'm currently using Cambria as the main font and Arial as the backup font in all of my runs. I tried using the font mapper but it didn't seem to help:
Code: Select all
//try the font mapper
Mapper fontMapper = new IdentityPlusMapper();
wordMLPackage.setFontMapper(fontMapper);
PhysicalFont font = PhysicalFonts.getPhysicalFonts().get("Comic Sans MS");
fontMapper.getFontMappings().put("Cambria", font);


Here's the new stack trace:
Code: Select all
2014-04-21T14:27:43.977693+00:00 app[web.1]: java.lang.NullPointerException
2014-04-21T14:27:43.984867+00:00 app[web.1]:    at org.docx4j.fonts.RunFontSelector.unicodeRangeToFont(RunFontSelector.java:545)
2014-04-21T14:27:43.985035+00:00 app[web.1]:    at org.docx4j.fonts.RunFontSelector.fontSelector(RunFontSelector.java:519)
2014-04-21T14:27:43.985160+00:00 app[web.1]:    at org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart$FontAndStyleFinder.apply(MainDocumentPart.java:524)
2014-04-21T14:27:43.985454+00:00 app[web.1]:    at org.docx4j.TraversalUtil$CallbackImpl.walkJAXBElements(TraversalUtil.java:163)
2014-04-21T14:27:43.985591+00:00 app[web.1]:    at org.docx4j.TraversalUtil$CallbackImpl.walkJAXBElements(TraversalUtil.java:166)
2014-04-21T14:27:43.985726+00:00 app[web.1]:    at org.docx4j.TraversalUtil$CallbackImpl.walkJAXBElements(TraversalUtil.java:166)
2014-04-21T14:27:43.985843+00:00 app[web.1]:    at org.docx4j.TraversalUtil$CallbackImpl.walkJAXBElements(TraversalUtil.java:166)
2014-04-21T14:27:43.985967+00:00 app[web.1]:    at org.docx4j.TraversalUtil$CallbackImpl.walkJAXBElements(TraversalUtil.java:166)
2014-04-21T14:27:43.986084+00:00 app[web.1]:    at org.docx4j.TraversalUtil$CallbackImpl.walkJAXBElements(TraversalUtil.java:166)
2014-04-21T14:27:43.986201+00:00 app[web.1]:    at org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart.fontsInUse(MainDocumentPart.java:267)
2014-04-21T14:27:43.986320+00:00 app[web.1]:    at org.docx4j.openpackaging.packages.WordprocessingMLPackage.setFontMapper(WordprocessingMLPackage.java:323)
2014-04-21T14:27:43.986437+00:00 app[web.1]:    at org.docx4j.openpackaging.packages.WordprocessingMLPackage.setFontMapper(WordprocessingMLPackage.java:303)
2014-04-21T14:27:43.986553+00:00 app[web.1]:    at org.docx4j.openpackaging.packages.WordprocessingMLPackage.getFontMapper(WordprocessingMLPackage.java:354)
2014-04-21T14:27:43.986800+00:00 app[web.1]:    at org.docx4j.convert.out.common.preprocess.PartialDeepCopy.process(PartialDeepCopy.java:93)
2014-04-21T14:27:43.986926+00:00 app[web.1]:    at org.docx4j.convert.out.common.Preprocess.process(Preprocess.java:75)
2014-04-21T14:27:43.987045+00:00 app[web.1]:    at org.docx4j.convert.out.common.Preprocess.process(Preprocess.java:133)
2014-04-21T14:27:43.987162+00:00 app[web.1]:    at org.docx4j.convert.out.common.AbstractWmlExporter.preprocess(AbstractWmlExporter.java:51)
2014-04-21T14:27:43.987278+00:00 app[web.1]:    at org.docx4j.convert.out.common.AbstractWmlExporter.preprocess(AbstractWmlExporter.java:32)
2014-04-21T14:27:43.987393+00:00 app[web.1]:    at org.docx4j.convert.out.common.AbstractExporter.export(AbstractExporter.java:63)
2014-04-21T14:27:43.987509+00:00 app[web.1]:    at org.docx4j.Docx4J.toFO(Docx4J.java:475)
2014-04-21T14:27:43.987627+00:00 app[web.1]:    at closingDocument.createDocument(closingDocument.java:496)
2014-04-21T14:27:43.987746+00:00 app[web.1]:    at closingDocument.doGet(closingDocument.java:2462)
2014-04-21T14:27:43.987865+00:00 app[web.1]:    at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
2014-04-21T14:27:43.988145+00:00 app[web.1]:    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
2014-04-21T14:27:43.988274+00:00 app[web.1]:    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
2014-04-21T14:27:43.988393+00:00 app[web.1]:    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
2014-04-21T14:27:43.988509+00:00 app[web.1]:    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
2014-04-21T14:27:43.988624+00:00 app[web.1]:    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
2014-04-21T14:27:43.988740+00:00 app[web.1]:    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
2014-04-21T14:27:43.988864+00:00 app[web.1]:    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
2014-04-21T14:27:43.988982+00:00 app[web.1]:    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
2014-04-21T14:27:43.989123+00:00 app[web.1]:    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
2014-04-21T14:27:43.989242+00:00 app[web.1]:    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1008)
2014-04-21T14:27:43.989484+00:00 app[web.1]:    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
2014-04-21T14:27:43.989610+00:00 app[web.1]:    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1686)
2014-04-21T14:27:43.989727+00:00 app[web.1]:    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146)
2014-04-21T14:27:43.989842+00:00 app[web.1]:    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
2014-04-21T14:27:43.989957+00:00 app[web.1]:    at java.lang.Thread.run(Thread.java:679)
2014-04-21T14:27:44.019316+00:00 app[web.1]: org.docx4j.openpackaging.exceptions.Docx4JException: Exception exporting package
2014-04-21T14:27:44.019631+00:00 app[web.1]:    at org.docx4j.convert.out.common.AbstractExporter.export(AbstractExporter.java:97)
2014-04-21T14:27:44.019818+00:00 app[web.1]:    at org.docx4j.Docx4J.toFO(Docx4J.java:475)
2014-04-21T14:27:44.019940+00:00 app[web.1]:    at closingDocument.createDocument(closingDocument.java:496)
2014-04-21T14:27:44.020237+00:00 app[web.1]:    at closingDocument.doGet(closingDocument.java:2462)
2014-04-21T14:27:44.020369+00:00 app[web.1]:    at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
2014-04-21T14:27:44.020489+00:00 app[web.1]:    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
2014-04-21T14:27:44.020608+00:00 app[web.1]:    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
2014-04-21T14:27:44.020724+00:00 app[web.1]:    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
2014-04-21T14:27:44.020840+00:00 app[web.1]:    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
2014-04-21T14:27:44.020955+00:00 app[web.1]:    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
2014-04-21T14:27:44.021071+00:00 app[web.1]:    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
2014-04-21T14:27:44.021190+00:00 app[web.1]:    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
2014-04-21T14:27:44.021306+00:00 app[web.1]:    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
2014-04-21T14:27:44.021553+00:00 app[web.1]:    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
2014-04-21T14:27:44.021682+00:00 app[web.1]:    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1008)
2014-04-21T14:27:44.021798+00:00 app[web.1]:    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
2014-04-21T14:27:44.021913+00:00 app[web.1]:    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1686)
2014-04-21T14:27:44.022028+00:00 app[web.1]:    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146)
2014-04-21T14:27:44.022144+00:00 app[web.1]:    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
2014-04-21T14:27:44.022258+00:00 app[web.1]:    at java.lang.Thread.run(Thread.java:679)
2014-04-21T14:27:44.022565+00:00 app[web.1]: Caused by: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
2014-04-21T14:27:44.022721+00:00 app[web.1]:    at java.util.ArrayList.rangeCheck(ArrayList.java:571)
2014-04-21T14:27:44.022844+00:00 app[web.1]:    at java.util.ArrayList.get(ArrayList.java:349)
2014-04-21T14:27:44.037798+00:00 heroku[router]: at=info method=GET path=/closingDocument/closingDocument/?resId=a0mG0000003rpEpIAI&serverURL=https%3A%2F%2Fc.na11.visual.force.com%2Fservices%2FSoap%2Fc%2F27.0%2F00DG0000000jsdw&sId=00DG0000000jsdw%21AREAQEmMx3mcseGrmymjS8zkAb4_Rt65g3VEYkw88mDqghauQzmIaDse5FvaqnnUy8L7zEsnZkBZ4ybaAZw7FBG0eUc1sbTu&userID=005G0000003IRDYIA4 host=closingdocument.herokuapp.com request_id=f3b15997-e4f3-40ec-8b88-38491cab3f4a fwd="67.99.163.24" dyno=web.1 connect=1ms service=19756ms status=302 bytes=172
2014-04-21T14:27:44.023098+00:00 app[web.1]:    at org.docx4j.convert.out.common.preprocess.CoverPageSectPrMover.moveSectPr(CoverPageSectPrMover.java:55)
2014-04-21T14:27:44.023227+00:00 app[web.1]:    at org.docx4j.convert.out.common.preprocess.CoverPageSectPrMover.process(CoverPageSectPrMover.java:50)
2014-04-21T14:27:44.023345+00:00 app[web.1]:    at org.docx4j.convert.out.common.Preprocess.process(Preprocess.java:154)
2014-04-21T14:27:44.023464+00:00 app[web.1]:    at org.docx4j.convert.out.common.AbstractWmlExporter.preprocess(AbstractWmlExporter.java:51)
2014-04-21T14:27:44.023580+00:00 app[web.1]:    at org.docx4j.convert.out.common.AbstractWmlExporter.preprocess(AbstractWmlExporter.java:32)
2014-04-21T14:27:44.023697+00:00 app[web.1]:    at org.docx4j.convert.out.common.AbstractExporter.export(AbstractExporter.java:63)
2014-04-21T14:27:44.023820+00:00 app[web.1]:    ... 19 more

Re: Not able to convert some .docx files to .pdf

PostPosted: Tue Apr 22, 2014 6:12 am
by rich
I looked through the source code here: https://github.com/plutext/docx4j/blob/ ... ector.java

And saw that it may be helpful to you to see how I create my runs. I do it using a utility method I wrote, which I use every time I'm creating a run. If it helps, here is the code:

Code: Select all
   private static R createRun(String title, Boolean bold,
         Boolean underlined, Boolean italic, double fontSize, boolean lineBreakAtEnd) {
      R run = factory.createR();
          
         // Edit the styling of the text and use custom fields
         RPr runProperties = new RPr();
         RFonts runFont = new RFonts();
         runFont.setAscii("Cambria");
         runFont.setHAnsi("Cambria");
         runFont.setCs("Arial");
         
         // Make the text bold or not
         if (bold) {
            BooleanDefaultTrue b = new BooleanDefaultTrue();
            b.setVal(bold);
            runProperties.setB(b);
         }
         
         // Make the text underlined or not
         if (underlined) {
            U underline = new U();
            underline.setVal(UnderlineEnumeration.SINGLE);
            runProperties.setU(underline);
         }
         
         // Make the text italicized or not
         if (italic) {
            BooleanDefaultTrue it = new BooleanDefaultTrue();
            it.setVal(italic);
            runProperties.setI(it);
         }
         
         // Set the size of the font
         HpsMeasure size = new HpsMeasure();
         // Actual value size accepts is double the actual font size
         size.setVal(new BigInteger(String.valueOf(Math.round(fontSize * 2))));
         runProperties.setSz(size);
         runProperties.setSzCs(size);
         
         runProperties.setRFonts(runFont);
         run.setRPr(runProperties);
         
         // Add the custom text to the run
         Text text = new Text();
         text.setValue(title);
         text.setSpace("preserve"); // preserve whitespace
         run.getContent().add(text);
         
         // Optional: add a line break at end
         if (lineBreakAtEnd) {
            Br xmlBreak = new Br();
            run.getContent().add(xmlBreak);
         }
         return run;
   }

Re: Not able to convert some .docx files to .pdf

PostPosted: Tue Apr 22, 2014 10:39 am
by jason
Could you please try it with http://www.docx4java.org/docx4j/docx4j- ... 140418.jar and if it still happens, post the stack trace, so we can see line numbers which correspond to current source code.

Re: Not able to convert some .docx files to .pdf

PostPosted: Wed Apr 23, 2014 12:46 am
by rich
I tried it with the docx4j-nightly-20140418 jar, and still no luck. Just to make sure, here's the list of all my JAXB jars I'm using as well:
jaxb-api-2.2.7
jaxb-core-2.2.7
jaxb-impl-2.2.7
jaxb-jxc-2.2.7
jaxb-xjc-2.2.7

I noticed yesterday while sifting through your source code that the NPE occurs when it's looking for the fonts in the header. It's possible I may have made the header improperly. I'll be doing some research about that and post back if I'm successful.

In the meantime, here's the stack trace:
Code: Select all
2014-04-22T13:43:36.000837+00:00 app[web.1]: java.lang.NullPointerException
2014-04-22T13:43:36.001129+00:00 app[web.1]:    at org.docx4j.fonts.RunFontSelector.unicodeRangeToFont(RunFontSelector.java:545)
2014-04-22T13:43:36.001129+00:00 app[web.1]:    at org.docx4j.fonts.RunFontSelector.fontSelector(RunFontSelector.java:519)
2014-04-22T13:43:36.001129+00:00 app[web.1]:    at org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart$FontAndStyleFinder.apply(MainDocumentPart.java:524)
2014-04-22T13:43:36.001129+00:00 app[web.1]:    at org.docx4j.TraversalUtil$CallbackImpl.walkJAXBElements(TraversalUtil.java:163)
2014-04-22T13:43:36.001129+00:00 app[web.1]:    at org.docx4j.TraversalUtil$CallbackImpl.walkJAXBElements(TraversalUtil.java:166)
2014-04-22T13:43:36.001129+00:00 app[web.1]:    at org.docx4j.TraversalUtil$CallbackImpl.walkJAXBElements(TraversalUtil.java:166)
2014-04-22T13:43:36.001269+00:00 app[web.1]:    at org.docx4j.TraversalUtil$CallbackImpl.walkJAXBElements(TraversalUtil.java:166)
2014-04-22T13:43:36.001269+00:00 app[web.1]:    at org.docx4j.TraversalUtil$CallbackImpl.walkJAXBElements(TraversalUtil.java:166)
2014-04-22T13:43:36.001269+00:00 app[web.1]:    at org.docx4j.TraversalUtil$CallbackImpl.walkJAXBElements(TraversalUtil.java:166)
2014-04-22T13:43:36.001269+00:00 app[web.1]:    at org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart.fontsInUse(MainDocumentPart.java:267)
2014-04-22T13:43:36.001373+00:00 app[web.1]:    at org.docx4j.openpackaging.packages.WordprocessingMLPackage.setFontMapper(WordprocessingMLPackage.java:323)
2014-04-22T13:43:36.001373+00:00 app[web.1]:    at org.docx4j.openpackaging.packages.WordprocessingMLPackage.setFontMapper(WordprocessingMLPackage.java:303)
2014-04-22T13:43:36.001666+00:00 app[web.1]:    at closingDocument.createDocument(closingDocument.java:493)
2014-04-22T13:43:36.001666+00:00 app[web.1]:    at closingDocument.doGet(closingDocument.java:2469)
2014-04-22T13:43:36.001666+00:00 app[web.1]:    at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
2014-04-22T13:43:36.001666+00:00 app[web.1]:    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
2014-04-22T13:43:36.001666+00:00 app[web.1]:    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
2014-04-22T13:43:36.001666+00:00 app[web.1]:    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
2014-04-22T13:43:36.001666+00:00 app[web.1]:    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
2014-04-22T13:43:36.001666+00:00 app[web.1]:    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
2014-04-22T13:43:36.001666+00:00 app[web.1]:    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
2014-04-22T13:43:36.001666+00:00 app[web.1]:    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
2014-04-22T13:43:36.001910+00:00 app[web.1]:    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
2014-04-22T13:43:36.001910+00:00 app[web.1]:    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
2014-04-22T13:43:36.001910+00:00 app[web.1]:    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1008)
2014-04-22T13:43:36.001910+00:00 app[web.1]:    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
2014-04-22T13:43:36.001910+00:00 app[web.1]:    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1686)
2014-04-22T13:43:36.001910+00:00 app[web.1]:    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146)
2014-04-22T13:43:36.001910+00:00 app[web.1]:    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
2014-04-22T13:43:36.001910+00:00 app[web.1]:    at java.lang.Thread.run(Thread.java:679)

Re: Not able to convert some .docx files to .pdf

PostPosted: Wed Apr 23, 2014 3:57 am
by rich
I turned on the log4j properly, and the problem is a little bit clearer. It must be a problem with my JAXB. Here's the relevant portion at the start of the logs:

Code: Select all
2014-04-22T16:08:55.827528+00:00 app[web.1]: 43 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - java.vendor=Sun Microsystems Inc.
2014-04-22T16:08:55.827588+00:00 app[web.1]: 43 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - java.version=1.6.0_27
2014-04-22T16:08:55.840839+00:00 app[web.1]: 56 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  -
2014-04-22T16:08:55.840839+00:00 app[web.1]: jar:file:/app/target/tomcat.15865/work/Tomcat/localhost/_/WEB-INF/lib/jaxb-core.jar!/META-INF/MANIFEST.MF
2014-04-22T16:08:55.841318+00:00 app[web.1]: 57 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Implementation-Title : JAXB Reference Implementation
2014-04-22T16:08:55.841466+00:00 app[web.1]: 57 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Implementation-Version : 2.2.7
2014-04-22T16:08:55.841598+00:00 app[web.1]: 57 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Manifest-Version : 1.0
2014-04-22T16:08:55.841733+00:00 app[web.1]: 57 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Specification-Vendor : Oracle Corporation
2014-04-22T16:08:55.841864+00:00 app[web.1]: 57 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Class-Path : jaxb-api.jar
2014-04-22T16:08:55.841994+00:00 app[web.1]: 57 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Created-By : 1.6.0_41-b02 (Sun Microsystems Inc.)
2014-04-22T16:08:55.842136+00:00 app[web.1]: 58 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Ant-Version : Apache Ant 1.8.4
2014-04-22T16:08:55.842313+00:00 app[web.1]: 58 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Implementation-Vendor : Oracle Corporation
2014-04-22T16:08:55.842454+00:00 app[web.1]: 58 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Implementation-Vendor-Id : com.sun
2014-04-22T16:08:55.842581+00:00 app[web.1]: 58 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Specification-Title : Java Architecture for XML Binding
2014-04-22T16:08:55.842949+00:00 app[web.1]: 58 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Specification-Version : 2.2.7
2014-04-22T16:08:55.843113+00:00 app[web.1]: 59 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Extension-Name : com.sun.xml.bind.core
2014-04-22T16:08:55.843240+00:00 app[web.1]: 59 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Build-Id : 04/24/2013 06:10 PM(yaroska)
2014-04-22T16:08:55.843719+00:00 app[web.1]: 59 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  -
2014-04-22T16:08:55.843719+00:00 app[web.1]: jar:file:/app/target/tomcat.15865/work/Tomcat/localhost/_/WEB-INF/lib/jaxb-impl.jar!/META-INF/MANIFEST.MF
2014-04-22T16:08:55.843870+00:00 app[web.1]: 59 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Implementation-Title : JAXB Reference Implementation
2014-04-22T16:08:55.843996+00:00 app[web.1]: 59 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Implementation-Version : 2.2.7
2014-04-22T16:08:55.844120+00:00 app[web.1]: 60 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Manifest-Version : 1.0
2014-04-22T16:08:55.844249+00:00 app[web.1]: 60 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Specification-Vendor : Oracle Corporation
2014-04-22T16:08:55.844375+00:00 app[web.1]: 60 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Class-Path : jaxb-api.jar jaxb-core.jar
2014-04-22T16:08:55.844633+00:00 app[web.1]: 60 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Created-By : 1.6.0_41-b02 (Sun Microsystems Inc.)
2014-04-22T16:08:55.844767+00:00 app[web.1]: 60 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Ant-Version : Apache Ant 1.8.4
2014-04-22T16:08:55.844893+00:00 app[web.1]: 60 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Implementation-Vendor : Oracle Corporation
2014-04-22T16:08:55.845018+00:00 app[web.1]: 60 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Implementation-Vendor-Id : com.sun
2014-04-22T16:08:55.845144+00:00 app[web.1]: 61 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Specification-Title : Java Architecture for XML Binding
2014-04-22T16:08:55.845270+00:00 app[web.1]: 61 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Specification-Version : 2.2.7
2014-04-22T16:08:55.849086+00:00 app[web.1]: 61 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Extension-Name : com.sun.xml.bind
2014-04-22T16:08:55.849284+00:00 app[web.1]: 65 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Build-Id : 04/24/2013 06:10 PM(yaroska)
2014-04-22T16:08:55.849798+00:00 app[web.1]: 65 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  -
2014-04-22T16:08:55.849798+00:00 app[web.1]: jar:file:/app/target/tomcat.15865/work/Tomcat/localhost/_/WEB-INF/lib/jaxb-jxc.jar!/META-INF/MANIFEST.MF
2014-04-22T16:08:55.850602+00:00 app[web.1]: 66 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Implementation-Title : JAXB Reference Implementation
2014-04-22T16:08:55.850746+00:00 app[web.1]: 66 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Implementation-Version : 2.2.7
2014-04-22T16:08:55.850877+00:00 app[web.1]: 66 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Class-Path : jaxb-api.jar jaxb-core.jar jaxb-xjc.jar jaxb-impl.jar
2014-04-22T16:08:55.851005+00:00 app[web.1]: 66 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Manifest-Version : 1.0
2014-04-22T16:08:55.851136+00:00 app[web.1]: 67 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Specification-Vendor : Oracle Corporation
2014-04-22T16:08:55.851274+00:00 app[web.1]: 67 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Created-By : 1.6.0_41-b02 (Sun Microsystems Inc.)
2014-04-22T16:08:55.851418+00:00 app[web.1]: 67 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Ant-Version : Apache Ant 1.8.4
2014-04-22T16:08:55.851544+00:00 app[web.1]: 67 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Implementation-Vendor : Oracle Corporation
2014-04-22T16:08:55.851668+00:00 app[web.1]: 67 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Implementation-Vendor-Id : com.sun
2014-04-22T16:08:55.851793+00:00 app[web.1]: 67 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Specification-Title : Java Architecture for XML Binding
2014-04-22T16:08:55.852047+00:00 app[web.1]: 67 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Specification-Version : 2.2.7
2014-04-22T16:08:55.852183+00:00 app[web.1]: 68 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Extension-Name : com.sun.tools.jxc
2014-04-22T16:08:55.852387+00:00 app[web.1]: 68 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Main-Class : com.sun.tools.jxc.SchemaGeneratorFacade
2014-04-22T16:08:55.852529+00:00 app[web.1]: 68 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Build-Id : 04/24/2013 06:10 PM(yaroska)
2014-04-22T16:08:55.853122+00:00 app[web.1]: 69 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  -
2014-04-22T16:08:55.853122+00:00 app[web.1]: jar:file:/app/target/tomcat.15865/work/Tomcat/localhost/_/WEB-INF/lib/jaxb-xjc.jar!/META-INF/MANIFEST.MF
2014-04-22T16:08:55.853304+00:00 app[web.1]: 69 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Implementation-Title : JAXB Reference Implementation
2014-04-22T16:08:55.853503+00:00 app[web.1]: 69 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Implementation-Version : 2.2.7
2014-04-22T16:08:55.853629+00:00 app[web.1]: 69 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Class-Path : jaxb-api.jar jaxb-core.jar
2014-04-22T16:08:55.853754+00:00 app[web.1]: 69 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Manifest-Version : 1.0
2014-04-22T16:08:55.854010+00:00 app[web.1]: 69 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Specification-Vendor : Oracle Corporation
2014-04-22T16:08:55.854146+00:00 app[web.1]: 70 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Created-By : 1.6.0_41-b02 (Sun Microsystems Inc.)
2014-04-22T16:08:55.854271+00:00 app[web.1]: 70 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Ant-Version : Apache Ant 1.8.4
2014-04-22T16:08:55.854396+00:00 app[web.1]: 70 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Implementation-Vendor : Oracle Corporation
2014-04-22T16:08:55.854520+00:00 app[web.1]: 70 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Implementation-Vendor-Id : com.sun
2014-04-22T16:08:55.854645+00:00 app[web.1]: 70 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Specification-Title : Java Architecture for XML Binding
2014-04-22T16:08:55.854770+00:00 app[web.1]: 70 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Specification-Version : 2.2.7
2014-04-22T16:08:55.854895+00:00 app[web.1]: 70 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Extension-Name : com.sun.tools.xjc
2014-04-22T16:08:55.855020+00:00 app[web.1]: 70 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Main-Class : com.sun.tools.xjc.XJCFacade
2014-04-22T16:08:55.855145+00:00 app[web.1]: 71 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Build-Id : 04/24/2013 06:10 PM(yaroska)
2014-04-22T16:08:55.859297+00:00 app[web.1]: 75 [http-nio-15865-exec-4] DEBUG org.docx4j.utils.ResourceUtils  - Not using MOXy, since no resource: org/docx4j/wml/jaxb.properties
2014-04-22T16:08:55.859398+00:00 app[web.1]: 75 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - No MOXy JAXB config found; assume not intended..
2014-04-22T16:08:55.859487+00:00 app[web.1]: 75 [http-nio-15865-exec-4] DEBUG org.docx4j.jaxb.Context  - org/docx4j/wml/jaxb.properties not found via classloader.
2014-04-22T16:08:56.453533+00:00 app[web.1]: 669 [http-nio-15865-exec-4] WARN org.docx4j.jaxb.NamespacePrefixMapperUtils  - name: com.sun.xml.internal.bind.namespacePrefixMapper value: org.docx4j.jaxb.NamespacePrefixMapperSunInternal@349319d9 .. trying RI.
2014-04-22T16:08:56.454340+00:00 app[web.1]: 670 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.NamespacePrefixMapperUtils  - Using NamespacePrefixMapper, which is suitable for the JAXB RI
2014-04-22T16:08:56.454416+00:00 app[web.1]: 670 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Using JAXB Reference Implementation
2014-04-22T16:09:00.820300+00:00 app[web.1]: 5036 [http-nio-15865-exec-4] INFO org.docx4j.jaxb.Context  - Not using MOXy; using com.sun.xml.bind.v2.runtime.JAXBContextImpl
2014-04-22T16:09:00.978403+00:00 app[web.1]: 5192 [http-nio-15865-exec-4] ERROR org.docx4j.jaxb.Context  - Cannot initialize context
2014-04-22T16:09:00.978403+00:00 app[web.1]: javax.xml.bind.JAXBException: "org.plutext.jaxb.xmldsig" doesnt contain ObjectFactory.class or jaxb.index
2014-04-22T16:09:00.978403+00:00 app[web.1]:    at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:281)
2014-04-22T16:09:00.978403+00:00 app[web.1]:    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2014-04-22T16:09:00.978403+00:00 app[web.1]:    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
2014-04-22T16:09:00.978403+00:00 app[web.1]:    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
2014-04-22T16:09:00.978403+00:00 app[web.1]:    at java.lang.reflect.Method.invoke(Method.java:616)
2014-04-22T16:09:00.978403+00:00 app[web.1]:    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:148)
2014-04-22T16:09:00.978403+00:00 app[web.1]:    at javax.xml.bind.ContextFinder.find(ContextFinder.java:297)
2014-04-22T16:09:00.978403+00:00 app[web.1]:    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:392)
2014-04-22T16:09:00.978662+00:00 app[web.1]:    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:357)
2014-04-22T16:09:00.978662+00:00 app[web.1]:    at org.docx4j.jaxb.Context.<clinit>(Context.java:158)
2014-04-22T16:09:00.978662+00:00 app[web.1]:    at org.docx4j.openpackaging.parts.JaxbXmlPart.<init>(JaxbXmlPart.java:85)
2014-04-22T16:09:00.978662+00:00 app[web.1]:    at org.docx4j.openpackaging.parts.JaxbXmlPartXPathAware.<init>(JaxbXmlPartXPathAware.java:56)
2014-04-22T16:09:00.978662+00:00 app[web.1]:    at org.docx4j.openpackaging.parts.JaxbXmlPartAltChunkHost.<init>(JaxbXmlPartAltChunkHost.java:72)
2014-04-22T16:09:00.978662+00:00 app[web.1]:    at org.docx4j.openpackaging.parts.WordprocessingML.DocumentPart.<init>(DocumentPart.java:158)
2014-04-22T16:09:00.978662+00:00 app[web.1]:    at org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart.<init>(MainDocumentPart.java:93)
2014-04-22T16:09:00.978662+00:00 app[web.1]:    at org.docx4j.openpackaging.packages.WordprocessingMLPackage.createPackage(WordprocessingMLPackage.java:392)
2014-04-22T16:09:00.978662+00:00 app[web.1]:    at org.docx4j.openpackaging.packages.WordprocessingMLPackage.createPackage(WordprocessingMLPackage.java:381)
2014-04-22T16:09:00.978662+00:00 app[web.1]:    at closingDocument.createDocument(closingDocument.java:433)
2014-04-22T16:09:00.978856+00:00 app[web.1]:    at closingDocument.doGet(closingDocument.java:2493)
2014-04-22T16:09:00.978856+00:00 app[web.1]:    at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
2014-04-22T16:09:00.978856+00:00 app[web.1]:    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
2014-04-22T16:09:00.978856+00:00 app[web.1]:    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
2014-04-22T16:09:00.978856+00:00 app[web.1]:    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
2014-04-22T16:09:00.978856+00:00 app[web.1]:    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
2014-04-22T16:09:00.978856+00:00 app[web.1]:    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
2014-04-22T16:09:00.978856+00:00 app[web.1]:    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
2014-04-22T16:09:00.978856+00:00 app[web.1]:    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
2014-04-22T16:09:00.978856+00:00 app[web.1]:    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
2014-04-22T16:09:00.979458+00:00 app[web.1]:    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
2014-04-22T16:09:00.979458+00:00 app[web.1]:    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1008)
2014-04-22T16:09:00.979458+00:00 app[web.1]:    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
2014-04-22T16:09:00.979458+00:00 app[web.1]:    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1686)
2014-04-22T16:09:00.979458+00:00 app[web.1]:    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146)
2014-04-22T16:09:00.979458+00:00 app[web.1]:    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
2014-04-22T16:09:00.979458+00:00 app[web.1]:    at java.lang.Thread.run(Thread.java:679)

Re: Not able to convert some .docx files to .pdf

PostPosted: Wed Apr 23, 2014 11:36 am
by jason
rich wrote:java.lang.NullPointerException
at org.docx4j.fonts.RunFontSelector.unicodeRangeToFont(RunFontSelector.java:545)


I've not been able to reproduce this because invoking unicodeRangeToFont depends on more than just the content of your rPr. I guess the value of w:t if you have <w:r><w:t/></w:r> could be null (rather than empty string) depending on the JAXB implementation?

In any case, the next nightly will guard against this NPE. https://github.com/plutext/docx4j/commi ... 9965bb0586

rich wrote:javax.xml.bind.JAXBException: "org.plutext.jaxb.xmldsig" doesnt contain ObjectFactory.class or jaxb.index


Add http://www.docx4java.org/docx4j/docx4j- ... -1.0.0.jar to your class path. Same for any other docx4j dependencies you are missing.

Re: Not able to convert some .docx files to .pdf

PostPosted: Thu Apr 24, 2014 2:25 am
by rich
Hi Jason,
Your patch fixed the problem I was having. The pdf generation still fails, but it's a different issue that I'll be opening a new thread for.
Thank you again for your patience and help with these issues. I'm very impressed with the docx4j API, and will be using it extensively in the future once I get all the kinks worked out.