Problems running Apache FOP: org.apache.fop.fo.FOTreeBuilder fatalError

Pablo (archive)

Usenet Archive
Joined
Nov 10, 2000
Messages
26
Reaction score
0
Dear all,

I am trying to use Apache FOP to create PDF from URLs, but something is going wrong.

I am using JTidy to convert a URL to XHTML, and then FOP to transform this XHTML to PDF.

I am using a xslt file that I have downloaded here to transform xhtml to FO format: http://www.antennahouse.com/XSLsample/XSLsample.htm and http://www-128.ibm.com/developerworks/library/x-xslfo2app/

I am wondering if anyone have a working example of FOP to generate PDFs from HTML that could be shared here.

My code is bellow:

public static void main(String args) {
PDFMaker pdf = new PDFMaker;
pdf.setPdfPath("teste.pdf");
pdf.setUrl("http://validator.w3.org/"); pdf.setXmlPath("test.xml"); pdf.setXsltPath("xhtml2fo-ms.xsl"); pdf.convert2PDF; }

public void convert2PDF {
try {
// Setup directories
File baseDir = new File("e:/pdf-temp/");
File outDir = new File(baseDir, "out");
outDir.mkdirs;

// Setup input and output files
File xmlfile = this.convert2Xhtml(baseDir,
this.getXmlPath); //input xml using JTidy
File xsltfile = new File(baseDir, this.getXsltPath); // xslt style sheet File pdffile = new File(outDir, this.getPdfPath); // output pdf

// configure fopFactory as desired
FopFactory fopFactory = FopFactory.newInstance;

// configure foUserAgent as desired
FOUserAgent foUserAgent = fopFactory.newFOUserAgent;

// Setup output
OutputStream out = new java.io.FileOutputStream(pdffile); out = new java.io.BufferedOutputStream(out);

try {
// Construct fop with desired output format Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);

// Setup XSLT
TransformerFactory factory =
TransformerFactory.newInstance;
Transformer transformer = factory.newTransformer(new StreamSource(xsltfile));

// Setup input for XSLT transformation
Source src = new StreamSource(xmlfile);

// Resulting SAX events (the generated FO) must be piped through to FOP Result res = new SAXResult(fop.getDefaultHandler);

//set transformer parameters
transformer.setParameter("title-text","PDFTester"); transformer.setParameter("docid-text","JK130759"); transformer.setParameter("version-text","V0.0"); transformer.setParameter("status-text","Onbekend"); transformer.setParameter("authorizor-text","Jacques Kors"); transformer.setParameter("date-text",(new SimpleDateFormat("dd/MM/yyyy")).format(new Date)); transformer.setParameter("copytype-text","Test kopie");

// Start XSLT transformation and FOP processing transformer.transform(src, res); } finally { out.close; } } catch (Exception e) { e.printStackTrace(System.err); System.exit(-1); } }
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,049
Messages
3,104,245
Members
248,133
Latest member
DujonT

Latest Threads

Top