Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XML to PDF

 
Skyler Smith
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a project that will require a XML document to produce a PDF document. I am just starting out with java and the project that I am doing requires that I create a pdf file form XML. I have the XML file that contains all the data and elements. I am trying to get one to work that I downloaded (it is from a book Professional JSP 2nd Edition www.wrox.com), without any luck. I can't even get this to work. HELP! I am using Websphere to run it.
I start my websphere and type in http://localhost:8080/xml_2_pdf.jsp?fo=/simple.fo . This doesn't work.
The jsp page code is
-----------------------------------------------
<%@taglib uri="/WEB-INF/fop.tld" prefix="fop" %><%
%><%@page contentType="application/pdf"%><%
String xmlFile = request.getParameter("xml");
%><fop:xml2pdf xml="<%= xmlFile %>" xsl="/xml/pdfHistory.xsl"/>
------------------------------------------------
I also have a fop.tld file that looks like:
------------------------------------------------
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE taglib
PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN"
"http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
<taglib>
<tlibversion>1.0</tlibversion>
<jspversion>1.2</jspversion>
<shortname>Simple FOP Tag Library</shortname>

<info>
A tag library for turning XML into PDF documents
via XSLT. The xml2pdf tag translates XML input data
to FO XML via XSLT, and then renders that to PDF using
FOP. The fo2pdf tag renders FO XML into PDFs using FOP.
</info>
<tag>
<name>fo2pdf</name>
<tagclass>fop.FO2PDFTag</tagclass>
<bodycontent>JSP</bodycontent>
<info>
Applies the specified XSL stylesheet to the XML input,
and writes the output to the JspWriter. If no "fo" attribute
is specified, it reads the FO XML from the body of the tag.
</info>
<attribute>
<name>fo</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<tag>
<name>xml2pdf</name>
<tagclass>fop.XML2PDFTag</tagclass>
<bodycontent>JSP</bodycontent>
<info>
Applies the specified XSL stylesheet to the XML input,
and writes the output to the JspWriter. If no "xml" attribute
is specified, it reads the XML from the body of the tag.
</info>
<attribute>
<name>xml</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>xsl</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>
-------------------------------------------
the simple.fo document looks like:
-------------------------------------------
<?xml version="1.0"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="simple"
page-height="11in"
page-width="8.5in"
margin-top="1in"
margin-bottom="1in"
margin-left="1in"
margin-right="1in">
<fo:region-body/>
</fo:simple-page-master>
</fo:layout-master-set>

<fo age-sequence master-name="simple">
<fo:flow flow-name="xsl-region-body" text-align="center">
<fo:block font-size="24pt">
Welcome to XSL FO!
</fo:block>
<fo:block font-size="18pt" color="blue">
Welcome, Welcome, Welcome
</fo:block>
</fo:flow>
</fo age-sequence>
</fo:root>
----------------------------------------
the classes are located in a fop folder in the web directory and are downloaded directly from the website.
I just don't know if I have things right. Am I not running something that I should? I can get XML to got to HTML but not PDF.
 
SaiPrasad Jukalkar
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Tena
i am not sure whether you are correct or not, but i was able to solve this problem in a different way.
you can use the .fo file to generate PDF file using a java program "CommandLine.class". You can find the jar files at apache.org under FOP section. Here you got to look the source of this file and use the relevant sections as per your need.
feel free to ask further questions.
Saiprasad.
 
Skyler Smith
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My thing is that with IBM Workbench (websphere) How do I run a jsp page that uses the above information to produce a PDF page. As far as I can tell the Jsp page takes the .fo paramter to produce a pdf class. It also used an .tld & .xml & .class file to make this happen. When I open up my browser and type in http://localhost:8080/fo_2_pdf.jsp?fo=/simple.fo I get the error "Directive: Invalid attribute, prefix". This make me beleive that I am not running something or doing something that I should. I am very new to this any help would be great.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic