- Code: Select all
Docx4J.toPDF(wordMLPackage, outputstream);
Here is the link to the original post:
link
Upon Jason's advice I am trying xsl-fo:
- Code: Select all
public void saveToPdfFile(String name){
//saveToWordFile(name); ///works!!!
try {
PdfSettings s = new PdfSettings();
PdfConversion c = new Conversion(this.getWordMLPackage());
OutputStream out = new FileOutputStream(new File(name));
c.output(out, s);
} catch (Exception e) {
e.printStackTrace();
}
}
However, I am getting the same error as in previously when I was using Docx4J.toPDF() function call:
- Code: Select all
[main] ERROR org.docx4j.utils.XmlSerializerUtil - begin 0, end 9, length 8
java.lang.StringIndexOutOfBoundsException: begin 0, end 9, length 8
at java.base/java.lang.String.checkBoundsBeginEnd(String.java:3410)
at java.base/java.lang.String.substring(String.java:1883)
at org.apache.fop.fo.expr.PropertyTokenizer.nextColor(PropertyTokenizer.java:239)
at org.apache.fop.fo.expr.PropertyTokenizer.next(PropertyTokenizer.java:175)
at org.apache.fop.fo.expr.PropertyParser.parseProperty(PropertyParser.java:119)
at org.apache.fop.fo.expr.PropertyParser.parse(PropertyParser.java:92)
at org.apache.fop.fo.properties.PropertyMaker.make(PropertyMaker.java:438)
at org.apache.fop.fo.PropertyList.convertAttributeToProperty(PropertyList.java:499)
at org.apache.fop.fo.PropertyList.addAttributesToList(PropertyList.java:386)
at org.apache.fop.fo.FObj.processNode(FObj.java:127)
at org.apache.fop.fo.flow.table.TableFObj.processNode(TableFObj.java:232)
at org.apache.fop.fo.FOTreeBuilder$MainFOHandler.startElement(FOTreeBuilder.java:293)
at org.apache.fop.fo.FOTreeBuilder.startElement(FOTreeBuilder.java:179)
at org.docx4j.org.apache.xalan.transformer.TransformerIdentityImpl.startElement(TransformerIdentityImpl.java:1119)
at java.xml/com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:510)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:374)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2710)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:605)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:112)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:534)
at java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:888)
at java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:824)
at java.xml/com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at java.xml/com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1216)
at org.docx4j.org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:518)
at org.docx4j.utils.XmlSerializerUtil.serialize(XmlSerializerUtil.java:51)
at org.docx4j.utils.XmlSerializerUtil.serialize(XmlSerializerUtil.java:18)
at org.docx4j.convert.out.fo.renderers.FORendererApacheFOP.render(FORendererApacheFOP.java:247)
at org.docx4j.convert.out.fo.renderers.FORendererApacheFOP.render(FORendererApacheFOP.java:181)
at org.docx4j.convert.out.fo.AbstractFOExporter.postprocess(AbstractFOExporter.java:168)
at org.docx4j.convert.out.fo.AbstractFOExporter.postprocess(AbstractFOExporter.java:47)
at org.docx4j.convert.out.common.AbstractExporter.export(AbstractExporter.java:81)
at org.docx4j.Docx4J.toFO(Docx4J.java:712)
at org.docx4j.Docx4J.toPDF(Docx4J.java:741)
at org.docx4j.convert.out.pdf.viaXSLFO.Conversion.output(Conversion.java:70)
at book.word.WordDocument.saveToPdfFile(WordDocument.java:86)
at book.assemble.AssembleOrganizer.compileNsaveToPdf(AssembleOrganizer.java:67)
at book.assemble.AssembleOrganizer.main(AssembleOrganizer.java:76)
org.docx4j.openpackaging.exceptions.Docx4JException: Exception exporting package
at org.docx4j.convert.out.common.AbstractExporter.export(AbstractExporter.java:106)
at org.docx4j.Docx4J.toFO(Docx4J.java:712)
at org.docx4j.Docx4J.toPDF(Docx4J.java:741)
at org.docx4j.convert.out.pdf.viaXSLFO.Conversion.output(Conversion.java:70)
at book.word.WordDocument.saveToPdfFile(WordDocument.java:86)
at book.assemble.AssembleOrganizer.compileNsaveToPdf(AssembleOrganizer.java:67)
at book.assemble.AssembleOrganizer.main(AssembleOrganizer.java:76)
Caused by: org.docx4j.openpackaging.exceptions.Docx4JException: Exception writing Document to OutputStream: begin 0, end 9, length 8
at org.docx4j.utils.XmlSerializerUtil.serialize(XmlSerializerUtil.java:56)
at org.docx4j.utils.XmlSerializerUtil.serialize(XmlSerializerUtil.java:18)
at org.docx4j.convert.out.fo.renderers.FORendererApacheFOP.render(FORendererApacheFOP.java:247)
at org.docx4j.convert.out.fo.renderers.FORendererApacheFOP.render(FORendererApacheFOP.java:181)
at org.docx4j.convert.out.fo.AbstractFOExporter.postprocess(AbstractFOExporter.java:168)
at org.docx4j.convert.out.fo.AbstractFOExporter.postprocess(AbstractFOExporter.java:47)
at org.docx4j.convert.out.common.AbstractExporter.export(AbstractExporter.java:81)
... 6 more
Caused by: java.lang.StringIndexOutOfBoundsException: begin 0, end 9, length 8
at java.base/java.lang.String.checkBoundsBeginEnd(String.java:3410)
at java.base/java.lang.String.substring(String.java:1883)
at org.apache.fop.fo.expr.PropertyTokenizer.nextColor(PropertyTokenizer.java:239)
at org.apache.fop.fo.expr.PropertyTokenizer.next(PropertyTokenizer.java:175)
at org.apache.fop.fo.expr.PropertyParser.parseProperty(PropertyParser.java:119)
at org.apache.fop.fo.expr.PropertyParser.parse(PropertyParser.java:92)
at org.apache.fop.fo.properties.PropertyMaker.make(PropertyMaker.java:438)
at org.apache.fop.fo.PropertyList.convertAttributeToProperty(PropertyList.java:499)
at org.apache.fop.fo.PropertyList.addAttributesToList(PropertyList.java:386)
at org.apache.fop.fo.FObj.processNode(FObj.java:127)
at org.apache.fop.fo.flow.table.TableFObj.processNode(TableFObj.java:232)
at org.apache.fop.fo.FOTreeBuilder$MainFOHandler.startElement(FOTreeBuilder.java:293)
at org.apache.fop.fo.FOTreeBuilder.startElement(FOTreeBuilder.java:179)
at org.docx4j.org.apache.xalan.transformer.TransformerIdentityImpl.startElement(TransformerIdentityImpl.java:1119)
at java.xml/com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:510)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:374)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2710)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:605)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:112)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:534)
at java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:888)
at java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:824)
at java.xml/com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at java.xml/com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1216)
at org.docx4j.org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:518)
at org.docx4j.utils.XmlSerializerUtil.serialize(XmlSerializerUtil.java:51)
... 12 more
Any help, tutorials, blogs etc. would be appreciated.