Hi Chil-Hoan,

 

Thank you very much for your detailed response.

My problem was with fop jar. I have updated it. Now I create PDF but it is empty...

I get following exception (I marked it).

The exception refers to FopFactory fopFactory = FopFactory.newInstance();

Below exception I also enclose code with the method that creates PDF.

Thanks in advance for help!

Regards,

Rafal

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xmlgraphics/image/loader/ImageContext

at java.lang.ClassLoader.defineClass1(

 

 

Native Method

)

at java.lang.ClassLoader.defineClass(

 

 

ClassLoader.java:621

)

at java.security.SecureClassLoader.defineClass(

 

 

SecureClassLoader.java:124

)

at java.net.URLClassLoader.defineClass(

 

 

URLClassLoader.java:260

)

at java.net.URLClassLoader.access$000(

 

 

URLClassLoader.java:56

)

at java.net.URLClassLoader$1.run(

 

 

URLClassLoader.java:195

)

at java.security.AccessController.doPrivileged(

 

 

Native Method

)

at java.net.URLClassLoader.findClass(

 

 

URLClassLoader.java:188

)

at java.lang.ClassLoader.loadClass(

 

 

ClassLoader.java:307

)

at sun.misc.Launcher$AppClassLoader.loadClass(

 

 

Launcher.java:301

)

at java.lang.ClassLoader.loadClass(

 

 

ClassLoader.java:252

)

at java.lang.ClassLoader.loadClassInternal(

 

 

ClassLoader.java:320

)

at Pdf.createReceiptPDF(

 

 

Pdf.java:232

)

at Pdf.main(

 

 

Pdf.java:124

)

Caused by:

 

 

java.lang.ClassNotFoundException

: org.apache.xmlgraphics.image.loader.ImageContext

at java.net.URLClassLoader$1.run(

 

 

URLClassLoader.java:200

)

at java.security.AccessController.doPrivileged(

 

 

Native Method

)

at java.net.URLClassLoader.findClass(

 

 

URLClassLoader.java:188

)

at java.lang.ClassLoader.loadClass(

 

 

ClassLoader.java:307

)

at sun.misc.Launcher$AppClassLoader.loadClass(

 

 

Launcher.java:301

)

at java.lang.ClassLoader.loadClass(

 

 

ClassLoader.java:252

)

at java.lang.ClassLoader.loadClassInternal(

 

 

ClassLoader.java:320

)

==================

CODE:

BufferedOutputStream out =

new BufferedOutputStream(new FileOutputStream(new File("C:/PDFfile.pdf")));

Document doc;

String employeeNr;

 

// Creating FO

ByteArrayOutputStream tmpUt =

new ByteArrayOutputStream();

tmpUt.close();

 

// Using FOP to convert temporary file to PDF

 

byte[] fo = tmpUt.toByteArray();

InputStream bais =

new ByteArrayInputStream(fo);

FopFactory fopFactory = FopFactory.newInstance();  //HERE IS THE PROBLEM NOW

 

try{

Fop fop = fopFactory.newFop(MimeConstants.

MIME_PDF,out);

TransformerFactory factory = TransformerFactory.newInstance();

Transformer transformer = factory.newTransformer();

Logger foLogger = Logger.getLogger(

"org.apache.fop");

foLogger.setLevel(Level.

SEVERE);

Source src = "">

new StreamSource(bais);

Result res =

new SAXResult(fop.getDefaultHandler());

transformer.transform(src, res);

 

}

finally{

out.close();

}

 

 

 

Dnia 18-11-2010 o godz. 14:09 Chil-Hoan Kwon napisał(a):

Hi Rafal,
Do you write XML and fo:XSL files to generate PDF format?
Why do you getDefaultHandler??
I am writing simple steps for you:
1. Create XML file and Save it at specific location.
2. Create fo:XLS fils and Save it at specific location.
3. Create Java file.
 - Set up a FOP driver
   Driver driver = new Driver();
 - Set up the logger for the driver
  Logger logger = new ConsoleLogger(ConsoleLogger.LEVEL_INFO)
  driver.setLogger(logger)
- Declare Render format
 driver.setRenderer(Driver.RENDER_PDF)
- invoke xml file and xsl file and put them into Handler
 XSLTInputHandler inputHandler = new XSLTInputHandler(xmlfile, xslFile)
- Declare ByteSteream and read them byte
 ByteArrayOutPutStream outStream = new ByteArryaOutPutStream()
 driver.setOutputStream(outStream)
 driver.render(inputHandler.getParser(),inputHandler.getInputSource())
 byte[] content = outStream.toByteArray();
- Display PDF
response.setContentLength(content.length)
response.setContentType("application/pdf")
response.setHeader("       something.....")
 
response.getoutputStream().write(content);
response.getOutputSteram().flush()
 
This is simple explanation (Web Based application) to implement PDF document using xml and fo:XSL. 
This will give you some idea how to write in Java.
 
Good Luck!!!!
 
Chil


--- On Thu, 11/18/10, Rafał Laczek <rafal_lac...@wp.pl> wrote:

From: Rafał Laczek <rafal_lac...@wp.pl>
Subject: [java ee programming] fop.getDefaultHandler());
To: "Java EE (J2EE) Programming with Passion!" <java-ee-j2ee-programming-with-passion@googlegroups.com>
Received: Thursday, November 18, 2010, 6:44 PM

Hi,
Can sobmbody advise me please why by fop.getDefaultHandler())  I get error: The method getDefaultHandler() is undefined for the type Fop.
 
Thanks for help!
Regards,
Rafal

private

 

static void createReceiptPDF() throws IOException, TransformerFactoryConfigurationError, FileNotFoundException, TransformerConfigurationException, TransformerException, FOPException {

System.

 

out.println("createReceiptPDF() is invoked");

// Creating FO ( XSL-transformering uten FOP)

 

 

 

 

 

ByteArrayOutputStream tmpUt =

newByteArrayOutputStream();

 

newStreamResult(tmpUt);

 

 

// Using FOP to convert temporary file to PDF

 

 

 

byte

[] fo = tmpUt.toByteArray();

 

new ByteArrayInputStream(fo);

MIME_PDF,out);

 

 

Transformer xformer = fact.newTransformer();

"org.apache.fop");

 

SEVERE);

 

 

 

// BufferedInputStream tmpIn = new BufferedInputStream(new FileInputStream(f));

 

Source src ="">

new

StreamSource(bais);

 

new SAXResult(fop.getDefaultHandler());

//The method getDefaultHandler() is undefined for the type Fop

xformer.transform(src, result);

 

--
You received this message because you are subscribed to the Google
Groups "Java EE (J2EE) Programming with Passion!" group.
To post to this group, send email to
java-ee-j2ee-programming-with-passion@googlegroups.com
To unsubscribe from this group, send email to
java-ee-j2ee-programming-with-passion+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en?hl=en
 

Result res =

 

foLogger.setLevel(Level.

 

Logger foLogger = Logger.getLogger(

FopFactory fopFactory = FopFactory.newInstance();

Fop fop = fopFactory.newFop(MimeConstants.

InputStream bais =

tmpUt.close();

 

 

Result result =

OutputStream out;

Document doc;

String employeeNr;

TransformerFactory fact = TransformerFactory.newInstance();

 




--
You received this message because you are subscribed to the Google
Groups "Java EE (J2EE) Programming with Passion!" group.
To post to this group, send email to
java-ee-j2ee-programming-with-passion@googlegroups.com
To unsubscribe from this group, send email to
java-ee-j2ee-programming-with-passion+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en?hl=en

Reply via email to