I have some code that builds up a word document, and is supposed to save it as a pdf file. I have the following code that does the saving:
- Code: Select all
// Refresh the values of DOCPROPERTY fields
FieldUpdater updater = new FieldUpdater(docxPackage);
updater.update(true);
// .. the FOSettings object
FOSettings foSettings = Docx4J.createFOSettings();
foSettings.setWmlPackage(docxPackage);
OutputStream os = new java.io.FileOutputStream(name);
// Don't care what type of exporter you use
// Docx4J.toFO(foSettings, os, Docx4J.FLAG_EXPORT_PREFER_XSL);
Docx4J.toPDF(docxPackage, os);
// Clean up, so any ObfuscatedFontPart temp files can be deleted
if (docxPackage.getMainDocumentPart().getFontTablePart() != null)
{
docxPackage.getMainDocumentPart().getFontTablePart().deleteEmbeddedFontTempFiles();
}
This works fine for smaller pdf files (~170 pages), but gives the following exception for large pdf files:
org.docx4j.openpackaging.exceptions.Docx4JException: Exception exporting package
at org.docx4j.convert.out.common.AbstractExporter.export(AbstractExporter.java:109)
at org.docx4j.Docx4J.toFO(Docx4J.java:466)
at org.docx4j.Docx4J.toPDF(Docx4J.java:480)
at com.secdec.meercat.ui.reporting.AlertPDFTemplate$CreatePdf.run(AlertPDFTemplate.java:103)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.docx4j.openpackaging.exceptions.Docx4JException: Cannot perform the transformation
at org.docx4j.XmlUtils.transform(XmlUtils.java:1043)
at org.docx4j.XmlUtils.transform(XmlUtils.java:932)
at org.docx4j.convert.out.common.AbstractXsltExporterDelegate.process(AbstractXsltExporterDelegate.java:66)
at org.docx4j.convert.out.common.AbstractWmlExporter.process(AbstractWmlExporter.java:63)
at org.docx4j.convert.out.common.AbstractWmlExporter.process(AbstractWmlExporter.java:32)
at org.docx4j.convert.out.common.AbstractExporter.export(AbstractExporter.java:79)
... 4 more
Caused by: javax.xml.transform.TransformerException: No more DTM IDs are available
at org.apache.xpath.XPath.execute(XPath.java:365)
at org.apache.xalan.templates.ElemCopyOf.execute(ElemCopyOf.java:134)
at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:395)
at org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:178)
at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
at org.apache.xalan.transformer.TransformerImpl.transformToRTF(TransformerImpl.java:1988)
at org.apache.xalan.transformer.TransformerImpl.transformToRTF(TransformerImpl.java:1910)
at org.apache.xalan.templates.ElemVariable.getValue(ElemVariable.java:312)
at org.apache.xalan.templates.ElemVariable.execute(ElemVariable.java:248)
at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
at org.apache.xalan.templates.ElemChoose.execute(ElemChoose.java:128)
at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
at org.apache.xalan.templates.ElemChoose.execute(ElemChoose.java:141)
at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:395)
at org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:178)
at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
at org.apache.xalan.transformer.TransformerImpl.transformToRTF(TransformerImpl.java:1988)
at org.apache.xalan.transformer.TransformerImpl.transformToRTF(TransformerImpl.java:1910)
at org.apache.xalan.templates.ElemVariable.getValue(ElemVariable.java:312)
at org.apache.xalan.templates.ElemVariable.execute(ElemVariable.java:248)
at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:395)
at org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:178)
at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
at org.apache.xalan.templates.ElemCopy.execute(ElemCopy.java:116)
at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:395)
at org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:178)
at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
at org.apache.xalan.templates.ElemCopy.execute(ElemCopy.java:116)
at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:395)
at org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:178)
at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
at org.apache.xalan.transformer.TransformerImpl.transformToRTF(TransformerImpl.java:1988)
at org.apache.xalan.transformer.TransformerImpl.transformToRTF(TransformerImpl.java:1910)
at org.apache.xalan.templates.ElemVariable.getValue(ElemVariable.java:312)
at org.apache.xalan.templates.ElemVariable.execute(ElemVariable.java:248)
at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:395)
at org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:178)
at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
at org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:1376)
at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
at org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:1376)
at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:395)
at org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:178)
at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
at org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:1376)
at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:395)
at org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:178)
at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
at org.apache.xalan.transformer.TransformerImpl.applyTemplateToNode(TransformerImpl.java:2270)
at org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.java:1356)
at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:709)
at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1273)
at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1251)
at org.docx4j.XmlUtils.transform(XmlUtils.java:1041)
... 9 more
Caused by: org.apache.xml.dtm.DTMException: No more DTM IDs are available
at org.apache.xml.dtm.ref.DTMManagerDefault.addDTM(DTMManagerDefault.java:148)
at org.apache.xml.dtm.ref.DTMManagerDefault.getDTM(DTMManagerDefault.java:256)
at org.apache.xml.dtm.ref.DTMManagerDefault.getDTMHandleFromNode(DTMManagerDefault.java:559)
at org.apache.xpath.XPathContext.getDTMHandleFromNode(XPathContext.java:184)
at org.apache.xpath.objects.XNodeSetForDOM.<init>(XNodeSetForDOM.java:44)
at org.apache.xpath.objects.XObjectFactory.create(XObjectFactory.java:142)
at org.apache.xpath.objects.XObject.create(XObject.java:180)
at org.apache.xpath.functions.FuncExtFunction.execute(FuncExtFunction.java:212)
at org.apache.xpath.XPath.execute(XPath.java:337)
... 62 more
Not sure how to fix this. It seems that this exception was common in older versions of xalan, but the one in my docx4j plugin is version 2.7.1. Heelp!
Thanks in advance.