aspose file tools*
The moose likes Java in General and the fly likes convertion of pdf Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Reply locked New topic
Author

convertion of pdf

Shyam Sunder
Greenhorn

Joined: Dec 23, 2006
Posts: 24
Hi Friends,

This is a class which is used to generate pdf. But actually it is storing in a particular hard disk location. My requirement is "it has to display on the screen" and it should store in database also. waiting for your valueable suggestions.

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.sax.SAXResult;
import javax.xml.transform.stream.StreamSource;

import org.apache.avalon.framework.logger.ConsoleLogger;
import org.apache.avalon.framework.logger.Logger;
import org.apache.fop.apps.Driver;
import org.apache.fop.apps.FOPException;
import org.apache.fop.messaging.MessageHandler;
import org.xml.sax.InputSource;

public class PDFCreator {
public PDFCreator(String strSrcXMLPath, String strSrcXSLTPath, String strTarget) {
createPDFFromXMLXSL(strSrcXMLPath, strSrcXSLTPath, strTarget);
}
public void simplePDFCreator(String strSrcPath, String strTarget) {
Driver driver = null;
Logger logger = null;
try {
driver = new Driver();
driver.setRenderer(Driver.RENDER_PDF);
logger = new ConsoleLogger(ConsoleLogger.LEVEL_INFO);
MessageHandler.setScreenLogger(logger);
driver.setLogger(logger);
driver.setInputSource(new InputSource(strSrcPath));
driver.setOutputStream(new FileOutputStream(strTarget));
driver.run();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (FOPException e) {
e.printStackTrace();
}
}
public boolean createPDFFromXMLXSL(String strSrcPathXML, String strSrcPathXSLT, String strTarget) {
boolean bCreated = false;

Driver driver = null;
Logger logger = null;
try {
driver = new Driver();
driver.setRenderer(Driver.RENDER_PDF);
logger = new ConsoleLogger(ConsoleLogger.LEVEL_INFO);
MessageHandler.setScreenLogger(logger);
driver.setLogger(logger);
driver.setOutputStream(new FileOutputStream(strTarget));

Result result = new SAXResult(driver.getContentHandler());
Source xmlSource = new StreamSource(strSrcPathXML);
Source xsltSource = new StreamSource(strSrcPathXSLT);

TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer(xsltSource);

transformer.transform(xmlSource, result);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (TransformerConfigurationException e) {
e.printStackTrace();
} catch (TransformerException e) {
e.printStackTrace();
}

return bCreated;
}
public static void main (String args[]) {
new PDFCreator("D:/EclipseProjects/com/poc/xml/files/temp.xml",
"D:/EclipseProjects/com/poc/xml/files/Sample.xsl",
"D:/EclipseProjects/com/poc/xml/pdf/sample.pdf");
}
}
Jeroen T Wenting
Ranch Hand

Joined: Apr 21, 2006
Posts: 1847
You'll need to turn it into a Swing application (maybe SWT will also work) and find a component to show PDF files (or write one).
This can be a simple wrapper around Acrobat Reader or a native PDF viewer, both are possible.


42
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31054
    
162

I see you've asked this question in another thread. In the future, please do not cross post.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: convertion of pdf