我想使用FOP从xls文件在java中创建pdf?

时间:2014-01-08 06:56:26

标签: java apache-fop

我正在for creating pdf using Apache FOP

使用代码

但是当我运行代码

时,我得到了这些异常
Hi Testing
javax.xml.bind.MarshalException
 - with linked exception:
 [com.sun.istack.internal.SAXException2: class com.testFOP.Employee nor any of its         super class is known to this context.


  javax.xml.bind.JAXBException: class com.testFOP.Employee nor any of its super class     is known to this context.]
    at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.marshal(Unknown Source)
    at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(Unknown Source)
    at com.testFOP.PDFHandler.getXMLSource(PDFHandler.java:97)
    at com.testFOP.TestPDF.main(TestPDF.java:37)
     Caused by: com.sun.istack.internal.SAXException2: class com.testFOP.Employee nor any     of its super class is known to this context.
     javax.xml.bind.JAXBException: class com.testFOP.Employee nor any of its super class      is known to this context.
    at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.reportError(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.reportError(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsXsiType(Unknown      Source)
    at      com.sun.xml.internal.bind.v2.runtime.property.ArrayElementNodeProperty.serializeItem(Unknow     n Source)
    at com.sun.xml.internal.bind.v2.runtime.property.ArrayElementProperty.serializeListBody(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.property.ArrayERProperty.serializeBody(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsSoleContent(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsRoot(Unknown Source)
    ... 5 more
     Caused by: javax.xml.bind.JAXBException: class com.testFOP.Employee nor any of its      super class is known to this context.
    at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getBeanInfo(Unknown Source)
    ... 13 more
     Error on line 1 column 1 
       SXXP0003: Error reported by XML parser: Premature end of file.
     net.sf.saxon.trans.XPathException: org.xml.sax.SAXParseException; lineNumber: 1;           columnNumber: 1; Premature end of file.
    at net.sf.saxon.event.Sender.sendSAXSource(Sender.java:420)
    at net.sf.saxon.event.Sender.send(Sender.java:169)
    at net.sf.saxon.Controller.transform(Controller.java:1890)
    at com.testFOP.PDFHandler.createPDFFile(PDFHandler.java:64)
    at com.testFOP.TestPDF.main(TestPDF.java:39)
     Caused by: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Premature      end of file.
    at                com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown      Source)
    at                                                                                      com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(Unknown      Source)
    at      com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown      Source)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown      Source)
    at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(Unknown      Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(Unknown      Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown      Source)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown      Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown      Source)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown      Source)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown      Source)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown           Source)
    at      com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
    at net.sf.saxon.event.Sender.sendSAXSource(Sender.java:396)
    ... 4 more
org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Premature end of file.
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
    at net.sf.saxon.event.Sender.sendSAXSource(Sender.java:396)
    at net.sf.saxon.event.Sender.send(Sender.java:169)
    at net.sf.saxon.Controller.transform(Controller.java:1890)
    at com.testFOP.PDFHandler.createPDFFile(PDFHandler.java:64)
    at com.testFOP.TestPDF.main(TestPDF.java:39)

任何人都可以帮我解决这些问题。 提前谢谢

1 个答案:

答案 0 :(得分:0)

问题可以解决..请对“PDFHandler.java”进行以下更改..

    try {
        context = JAXBContext.newInstance(EmployeeData.class,Employee.class);
        Marshaller m = context.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        m.marshal(data, outStream);
    } catch (JAXBException e) {

        e.printStackTrace();
    }

生成的pdf将被放置在这个位置(在windows 7 os中) “C:\ Users \ narendar.g \ AppData \ Local \ Temp”,如13891730308241855417914089056114.pdf