eric wrote:i want to change "docx" fommat to "pdf",i try docx4j's samply but not work,can anybody show the example for me or has any other good suggestions?
org.docx4j.convert.out.pdf.PdfConversion c
// = new org.docx4j.convert.out.pdf.viaHTML.Conversion(wordMLPackage);
= new org.docx4j.convert.out.pdf.viaXSLFO.Conversion(wordMLPackage);
// = new org.docx4j.convert.out.pdf.viaIText.Conversion(wordMLPackage);
/*
* .. viaHTML uses docX2HTML.xslt and xhtmlrenderer,
* and supports numbering, images,
* and tables, but the XSLT is pretty hard to understand
*
* .. viaXSLFO uses docx2fo.xslt and FOP. It is
* rudimentary right now, but does support
* headers/footers, images and fairly basic tables
* (but supporting merged cells)
*
* .. viaItext - for developers who don't like xslt
* at all! Or want to use iText's features..
* Displays images, but as at 2009 03 19.
* doesn't try to scale them.
*/
org.docx4j.convert.out.pdf.PdfConversion c
// = new org.docx4j.convert.out.pdf.viaHTML.Conversion(wordMLPackage);
= new org.docx4j.convert.out.pdf.viaXSLFO.Conversion(wordMLPackage);
// = new org.docx4j.convert.out.pdf.viaIText.Conversion(wordMLPackage);
jason wrote:after i use upper code to convert docx,but the class “PdfConversion” only has the method "view",realy i want to save the pdf into local , how can i do? what methods can user?
if (save) {
OutputStream os = new java.io.FileOutputStream(inputfilepath + ".pdf");
c.output(os);
System.out.println("Saved " + inputfilepath + ".pdf");
} else {
c.view();
}
public static void main(String[] args) throws Exception {
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage
.load(new java.io.File("f:/2.docx"));
OutputStream os = new java.io.FileOutputStream("f:/2.pdf");
org.docx4j.convert.out.pdf.PdfConversion c
// = new org.docx4j.convert.out.pdf.viaHTML.Conversion(wordMLPackage);
// = new org.docx4j.convert.out.pdf.viaXSLFO.Conversion(wordMLPackage);
= new org.docx4j.convert.out.pdf.viaIText.Conversion(wordMLPackage);
c.output(os);
}
java.lang.NoClassDefFoundError: org/apache/batik/util/XMLResourceDescriptor
at org.apache.fop.fo.extensions.svg.SVGElementMapping.initialize(SVGElementMapping.java:80)
at org.apache.fop.fo.ElementMapping.getTable(ElementMapping.java:54)
at org.apache.fop.fo.ElementMappingRegistry.addElementMapping(ElementMappingRegistry.java:118)
at org.apache.fop.fo.ElementMappingRegistry.addElementMapping(ElementMappingRegistry.java:97)
at org.apache.fop.fo.ElementMappingRegistry.setupDefaultMappings(ElementMappingRegistry.java:78)
at org.apache.fop.fo.ElementMappingRegistry.<init>(ElementMappingRegistry.java:65)
at org.apache.fop.apps.FopFactory.<init>(FopFactory.java:149)
at org.apache.fop.apps.FopFactory.newInstance(FopFactory.java:172)
at org.docx4j.convert.out.pdf.viaXSLFO.Conversion.output(Conversion.java:192)
at test.TestConvertPdf.main(TestConvertPdf.java:21)
7:45:41,437 ERROR XmlUtils:678 - java.lang.NoSuchMethodException: For extension function, could not find method static org.docx4j.convert.out.pdf.viaXSLFO.Conversion.hasDefaultHeader([ExpressionContext,] #UNKNOWN (org.docx4j.openpackaging.packages.WordprocessingMLPackage)).
Users browsing this forum: Google [Bot] and 6 guests