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!!