0

i am using the code at for creating pdf using Apache FOP

but i am getting these exceptions when i run the code

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)

can any one help me to solve these issues. thanks in advance

Carlos Landeras
  • 11,025
  • 11
  • 56
  • 82
preeth
  • 365
  • 3
  • 7
  • 20

1 Answers1

0

The problem can be sloved .. Please make following changes to "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();
    }

And generated pdf will be placed in this location (in windows 7 os ) "C:\Users\narendar.g\AppData\Local\Temp" like 13891730308241855417914089056114.pdf

Naren
  • 1,447
  • 1
  • 10
  • 11
  • mine is windows xp.... program successfully executed but i dont know where to look out for pdf file?? – preeth Jan 08 '14 at 09:55
  • then changecode like this in "PDFHAndler.java" public String createPDFFile(ByteArrayOutputStream xmlSource, String templateFilePath) throws IOException { File file = new File("abcd"+EXTENSION); Then pdf will be generated in ur working project folder only. search in that folder "abcd.pdf". – Naren Jan 08 '14 at 10:29
  • yah its working thank you so much bro... but now my requirement changed a little... that is i will give a list of list of string values then the pdf should be generate with those values. i.e LIST>, can you please help me in doing what are all changes i need to do now. – preeth Jan 08 '14 at 12:06