Open carlosmedina-io opened 7 years ago
any solution for this error?
please can you helping solving this error.
@abhshekgithub1999 need docx exhibiting the issue or steps to reproduce
package com.strategicerp.docx4j;
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 org.docx4j.Docx4J; import org.docx4j.convert.out.FOSettings; import org.docx4j.fonts.IdentityPlusMapper; import org.docx4j.fonts.Mapper; import org.docx4j.model.fields.FieldUpdater; import org.docx4j.model.structure.PageSizePaper; import org.docx4j.openpackaging.packages.WordprocessingMLPackage; public class docxtopdf {
public static void main(String[] args) {
String inputWordPath = "/Users/apple/eclipse-workspace/docx4jtest/mksr.docx";
String outputPDFPath = "/Users/apple/eclipse-workspace/docx4jtest/abhi1.pdf";
try {
System.err.println("Word Document to PDF Convert Begins!");
InputStream is = new FileInputStream(new File(inputWordPath));
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(is);
wordMLPackage = WordprocessingMLPackage.createPackage(PageSizePaper.A5, false);
FieldUpdater updater = new FieldUpdater(wordMLPackage);
updater.update(true);
List sections = wordMLPackage.getDocumentModel().getSections();
for (int i = 0; i < sections.size(); i++) {
wordMLPackage.getDocumentModel().getSections().get(i).getPageDimensions();
}
Mapper fontMapper = new IdentityPlusMapper();
wordMLPackage.setFontMapper(fontMapper);
FOSettings foSettings = Docx4J.createFOSettings();
foSettings.setFoDumpFile(new java.io.File(inputWordPath + ".fo"));
foSettings.setWmlPackage(wordMLPackage);
OutputStream os = new java.io.FileOutputStream(outputPDFPath);
Docx4J.toFO(foSettings, os, Docx4J.FLAG_EXPORT_PREFER_XSL);
System.out.println("Your Word Document Converted to PDF Successfully!");
} catch (Exception e) {
e.printStackTrace();
}
} }
Word Document to PDF Convert Begins! SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/Users/apple/Downloads/jar_files%20(9)/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/Users/apple/Downloads/jar_files%20(10)/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/Users/apple/Downloads/docx4jtest%207.14.34%20PM/WEB-INF/lib/slf4j-simple-1.7.0.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/Users/apple/Downloads/docx4jtest%207.14.34%20PM/WEB-INF/lib/slf4j-log4j12-1.7.2.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory] log4j:WARN No appenders could be found for logger (org.docx4j.jaxb.Context). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info. org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Premature end of file. at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:204) at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:178) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:400) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:327) at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1472) at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:1042) at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:605) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:507) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:867) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:796) at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:142) at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1216) at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:644) at org.apache.avalon.framework.configuration.DefaultConfigurationBuilder.build(DefaultConfigurationBuilder.java:255) at org.apache.avalon.framework.configuration.DefaultConfigurationBuilder.build(DefaultConfigurationBuilder.java:203) at org.docx4j.convert.out.fo.renderers.FORendererApacheFOP.createFopFactory(FORendererApacheFOP.java:339) at org.docx4j.convert.out.fo.renderers.FORendererApacheFOP.getFopFactory(FORendererApacheFOP.java:253) at org.docx4j.convert.out.fo.renderers.FORendererApacheFOP.render(FORendererApacheFOP.java:119) 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:82) at org.docx4j.Docx4J.toFO(Docx4J.java:568) at com.strategicerp.docx4j.docxtopdf.main(docxtopdf.java:59) 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:568) at com.strategicerp.docx4j.docxtopdf.main(docxtopdf.java:59) Caused by: org.docx4j.openpackaging.exceptions.Docx4JException: Exception writing Document to OutputStream: org.apache.fop.fo.ValidationException: null:1:187: Error(1/187): For fo:root, fo:layout-master-set must be declared before fo:page-sequence. at org.docx4j.utils.XmlSerializerUtil.serialize(XmlSerializerUtil.java:50) at org.docx4j.utils.XmlSerializerUtil.serialize(XmlSerializerUtil.java:14) at org.docx4j.convert.out.fo.renderers.FORendererApacheFOP.render(FORendererApacheFOP.java:209) at org.docx4j.convert.out.fo.renderers.FORendererApacheFOP.render(FORendererApacheFOP.java:159) 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:82) ... 2 more
@Carlos Medina help me with this issue, please?
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:142)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1216)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:644)
at org.apache.avalon.framework.configuration.DefaultConfigurationBuilder.build(DefaultConfigurationBuilder.java:255)
looks like the XML configuration might not be parsing.
What happens when you use docx4j 8.3.1 (and -export-fo 8.3.1 of course)?
i'm using docx4j 3.3.1 and export 3.3.0 version.
???????????
Try docx4j 8.3.1 (and -export-fo 8.3.1 of course)
i'm using above version but some error show so i checked my error recommended for using docxj4j 3.3.1
so i'm correctly using docx4j 3.3.1 version small error show
Can't help you with ancient v3.3.1 I'm afraid.
If you can tell me what is happening with v8.3.1 (and provide your sample docx), we may be able to help.
you have code for docx to pdf using docx4j?
There are different ways to do it, see https://www.docx4java.org/blog/2020/09/office-pptxxlsxdocx-to-pdf-to-in-docx4j-8-2-3/
For export-fo, see https://github.com/plutext/docx4j/blob/master/docx4j-samples-docx-export-fo/src/main/java/org/docx4j/samples/ConvertOutPDFviaXSLFO.java
It is hard to assist you when your responses do not address mine!
I try to convert a docx file to pdf file but I am getting this issue. I have been checking the Issue https://github.com/plutext/docx4j/issues/99, which seems to be the same problem, I followed the recommendations mentioned there but I still have the problem. The jar files are: docx4j-3.2.1.jar fop-2.1.jar xmlgraphics-commons-2.0.jar batik-all-1.7.jar batik-bridge-1.8.jar (into batik-all-1.7.jar isn't org.apache.batik.bridge.FontFamilyResolve class, I have got a ClassNotFoundException)
Can anyone help me with this issue, please?