You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by Bruno Rondepierre <br...@mdeo.fr> on 2002/06/03 07:59:20 UTC
Re: Problem with FOP outline extension
By saying "it doesn't" work, I mean that the PDF is created but it contains
no bookmark.
----- Original Message -----
From: "J.Pietschmann" <j3...@yahoo.de>
To: <fo...@xml.apache.org>
Sent: Friday, May 31, 2002 11:27 PM
Subject: Re: Problem with FOP outline extension
> Bruno Rondepierre wrote:
> > I tried to used FOP outline extension while generating pdf.
> >
> > When I proceed in to steps:
> > 1) I used an XSLT parser to generate xslfo's file from xml and xslt
files,
> > 2) I generate the PDF file from this xslfo file,
> > It works fine.
> >
> > When I tried to generate PDF file directly from and XSL file, it doesn't
> > work.
> >
> > Is there a way to make it works while generating PDF directly from XSL
> > file ?
>
> Probably. Did you use disable-output-escaping="yes" somewhere?
> Other than that: What does "doesn't work" mean? No PDF bookmarks,
> no PDF content, no PDF at all? Exceptions?
>
> J.PIetschmann
>
>
>
>
>
Re: Problem with FOP outline extension
Posted by Bruno Rondepierre <br...@mdeo.fr>.
Problem solved: I've add the declaration in the xsl:stylesheet tag. and
then, the bookmarks are correctly generated in the PDF file.
Thanks.
----- Original Message -----
From: "J.Pietschmann" <j3...@yahoo.de>
To: <fo...@xml.apache.org>
Sent: Thursday, June 06, 2002 12:56 AM
Subject: Re: Problem with FOP outline extension
> Bruno Rondepierre wrote:
> > THE XSL FILE (tstBookmark.xslfo)
> Problem solved. You hit a Xalan bug.
> If you've looked into the log (hopefully, there *is* a log),
> you'd have seen FOP error messages containing:
> "...unknown...null^outline..."
>
> > -----------------Begin
> > <?xml version="1.0" encoding="ISO-8859-1"?>
> > <xsl:stylesheet version="1.0"
> > xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> > xmlns:fo="http://www.w3.org/1999/XSL/Format">
> ...
> > <xsl:template match="/">
> > <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"
> > xmlns:fox="http://xml.apache.org/fop/extensions">
> ...
> > </fo:root>
> > </xsl:template>
> >
> > <!-- Bookmark: book's type -->
> > <xsl:template match="booktype" mode="toc">
> > <fox:outline internal-destination="toc{@id}">
> > <fox:label><xsl:value-of select="label"/></fox:label>
> At this point, the fox: namespace prefix is undeclared.
> The declaration above in the fo:root element has gone out of
> scope. The processor should have complained about this.
>
> Move the declaration for the fox: prefix to the xsl:stylesheet
> element. BTW the fo: declaration on fo:root is redundant.
>
> J.Pietschmann
>
>
Re: Problem with FOP outline extension
Posted by "J.Pietschmann" <j3...@yahoo.de>.
Bruno Rondepierre wrote:
> THE XSL FILE (tstBookmark.xslfo)
Problem solved. You hit a Xalan bug.
If you've looked into the log (hopefully, there *is* a log),
you'd have seen FOP error messages containing:
"...unknown...null^outline..."
> -----------------Begin
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> xmlns:fo="http://www.w3.org/1999/XSL/Format">
...
> <xsl:template match="/">
> <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"
> xmlns:fox="http://xml.apache.org/fop/extensions">
...
> </fo:root>
> </xsl:template>
>
> <!-- Bookmark: book's type -->
> <xsl:template match="booktype" mode="toc">
> <fox:outline internal-destination="toc{@id}">
> <fox:label><xsl:value-of select="label"/></fox:label>
At this point, the fox: namespace prefix is undeclared.
The declaration above in the fo:root element has gone out of
scope. The processor should have complained about this.
Move the declaration for the fox: prefix to the xsl:stylesheet
element. BTW the fo: declaration on fo:root is redundant.
J.Pietschmann
Re: Problem with FOP outline extension
Posted by Bruno Rondepierre <br...@mdeo.fr>.
First, I don't used "disable-output-escaping".
At this end of this mail, you will find:
- an extract of an XML file,
- an extract of the XSLT file,
- an sample servlet.
DESCRIPTION OF THE SAMPLE
-------------------------------------
The goal of the sample is to create a PDF file containing book's description
(a title and a description). Books are classified using book's type (such as
Jave, Perl).
In the generated PDF:
- I force a page break foe each book's type,
- I want bookmarks both for the book's types and the books
To used the sample servlet, you first have to adapt pathname and then call:
<yourserver/servlet/tstBookmark?mode=direct> to generate PDF directly from
xml and xsl files.
<yourserver/servlet/tstBookmark?mode=fo> to create a fo file from xml and
xsl files and then generate the PDF from fo File.
THE XML FILE (tstBookmark.xml)
-----------------Begin
<?xml version="1.0" encoding="ISO-8859-1"?>
<page>
<content>
<booktypes>
<booktype id="1">
<label>Java</label>
<books>
<book id="4">
<title>Java and SOAP</title>
<abstract>
Java and SOAP provides Java developers with an in-depth look at SOAP
(the Simple Object Access Protocol). Of course, it covers the basics: what
SOAP is, why it's soared to a spot on the Buzzwords' Top Ten list, and what
its features and capabilities are. And it shows you how to work with some of
the more common Java APIs in the SOAP world: Apache SOAP and GLUE. Java and
SOAP also discusses interoperability between the major SOAP platforms,
including Microsoft's .NET, SOAP messaging, SOAP attachments, message
routing, and a preview of the forthcoming AXIS APIs and server. If you're a
Java developer who would like to start working with SOAP, this is the book
you need to get going.
</abstract>
</book>
<book id="2">
<title>Java and XML</title>
<abstract>
New chapters on Advanced SAX, Advanced DOM, SOAP, and data binding,
as well as new examples throughout, bring the second edition of Java &
XML thoroughly up to date. Except for a concise introduction to XML basics,
the book focuses entirely on using XML from Java applications. It's a worthy
companion for Java developers working with XML or involved in messaging, web
services, or the new peer-to-peer movement.
</abstract>
</book>
<book id="1">
<title>Java and XSLT</title>
<abstract>
Learn how to use XSL transformations in Java programs ranging from
stand-alone applications to servlets. Java and XSLT introduces XSLT and then
shows you how to apply transformations in real-world situations, such as
developing a discussion forum, transforming documents from one form to
another, and generating content for wireless devices.
</abstract>
</book>
</books>
</booktype>
<booktype id="4">
<label>Perl</label>
<books>
<book id="5">
<title>CGI Programming with Perl</title>
<abstract>
The Common Gateway Interface (CGI) is one of the most powerful
methods of providing dynamic content on the Web. CGI is a generic interface
for calling external programs to crunch numbers, query databases, generate
customized graphics, or perform any other server-side task. Based on the
best-selling CGI Programming on the World Wide Web, this edition has been
completely rewritten to demonstrate current techniques available with the
CGI.pm module and the latest versions of Perl. Topics include incorporating
JavaScript for form validation, controlling browser caching, making CGI
scripts secure in Perl, working with databases, creating simple search
engines, maintaining state between multiple sessions, generating graphics
dynamically, and improving performance of CGI scripts.
</abstract>
</book>
</books>
</booktype>
</booktypes>
</content>
</page>
-----------------End
THE XSL FILE (tstBookmark.xslfo)
-----------------Begin
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output method="xml"/>
<!-- Document definition -->
<xsl:template match="/">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:fox="http://xml.apache.org/fop/extensions">
<fo:layout-master-set>
<fo:simple-page-master master-name="A4"
page-height="297mm" page-width="210mm"
margin-right="75pt" margin-left="75pt" margin-bottom="25pt"
margin-top="25pt"
>
<fo:region-before extent="25pt"/>
<fo:region-body margin-top="50pt" margin-bottom="50pt"/>
<fo:region-after extent="25pt"/>
</fo:simple-page-master>
</fo:layout-master-set>
<xsl:apply-templates select="page/content/booktypes/booktype"
mode="toc"/>
<xsl:apply-templates select="page/content/booktypes/booktype"
mode="content"/>
</fo:root>
</xsl:template>
<!-- Bookmark: book's type -->
<xsl:template match="booktype" mode="toc">
<fox:outline internal-destination="toc{@id}">
<fox:label><xsl:value-of select="label"/></fox:label>
<xsl:if test="descendant::books/book">
<xsl:apply-templates select="books/book" mode="toc">
<xsl:with-param name="cat" select="@id"/>
</xsl:apply-templates>
</xsl:if>
</fox:outline>
</xsl:template>
<!-- Bookmark: book -->
<xsl:template match="books/book" mode="toc">
<xsl:param name="cat"/>
<fox:outline internal-destination="toc{$cat}book{@id}">
<fox:label><xsl:value-of select="title"/></fox:label>
</fox:outline>
</xsl:template>
<!-- Booktype: new page for each book's type -->
<xsl:template match="booktype" mode="content">
<xsl:if test="books/book">
<fo:page-sequence master-reference="A4">
<fo:flow flow-name="xsl-region-body">
<fo:wrapper font-family="Times" font-size="12pt"
text-align="justify">
<fo:table>
<fo:table-column column-width="165mm"/>
<fo:table-body>
<fo:table-row background-color="#00139F">
<fo:table-cell>
<fo:block id="toc{@id}" font-family="Helvetica"
line-height="30pt" font-size="24pt" font-weight="bold" color="#FFFFFF">
<xsl:value-of select="label"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
<xsl:apply-templates select="books" mode="content">
<xsl:with-param name="cat" select="@id"/>
</xsl:apply-templates>
</fo:wrapper>
</fo:flow>
</fo:page-sequence>
</xsl:if>
</xsl:template>
<!-- the books of one book's type -->
<xsl:template match="books" mode="content">
<xsl:param name="cat"/>
<fo:table>
<fo:table-column column-width="165mm"/>
<fo:table-body>
<xsl:apply-templates select="book">
<xsl:with-param name="cat" select="$cat"/>
</xsl:apply-templates>
</fo:table-body>
</fo:table>
</xsl:template>
<!-- one book -->
<xsl:template match="book">
<xsl:param name="cat"/>
<fo:table-row>
<fo:table-cell>
<fo:block space-before.optimum="10pt">
<xsl:text>
</xsl:text>
</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell>
<fo:block id="toc{$cat}book{@id}" font-family="Helvetica"
line-height="20pt" font-size="18pt" font-weight="bold" color="#00139F">
<xsl:value-of select="title"/>
</fo:block>
<xsl:if test="abstract">
<fo:block space-before.optimum="5pt" ><xsl:value-of
select="abstract"/></fo:block>
</xsl:if>
</fo:table-cell>
</fo:table-row>
</xsl:template>
</xsl:stylesheet>
-----------------End
THE SAMPLE SERVLET
---------------------------Begin
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.log.*;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import org.apache.fop.apps.Driver;
import org.apache.fop.apps.Version;
import org.apache.fop.apps.XSLTInputHandler;
import javax.xml.transform.*;
import javax.xml.transform.stream.*;
public class tstBookmark extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException
{ ProcessRequest(request, response); }
public void doPost(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException
{ ProcessRequest(request, response); }
public void ProcessRequest(HttpServletRequest request, HttpServletResponse
response) throws ServletException
{
// Files used
String xmlFile =
"E:/web/jakarta-tomcat-3.3.1/webapps/xml/data/xml/tstBookmark.xml";
String xslFile =
"E:/web/jakarta-tomcat-3.3.1/webapps/xml/data/xslfo/tstBookmark.xslfo";
String foFile =
"E:/web/jakarta-tomcat-3.3.1/webapps/xml/data/xslfo/tstBookmark.fo";
// Get parameters
String modeOut = request.getParameter("mode");
if (modeOut == null) { modeOut = "direct"; }
// Check mode
if (modeOut.equals("direct"))
{
// Generate PDF directly from xml and xsl files
try
{
// Initialize Logger
Hierarchy hierarchy = Hierarchy.getDefaultHierarchy();
Logger log = hierarchy.getLoggerFor("fop");
log.setPriority(Priority.WARN);
// Initialier Input Handler
XSLTInputHandler input = new XSLTInputHandler(new File(xmlFile), new
File(xslFile));
// Render
ByteArrayOutputStream out = new ByteArrayOutputStream();
Driver driver = new Driver();
driver.setLogger(log);
driver.setRenderer(Driver.RENDER_PDF);
driver.setOutputStream(out);
driver.render(input.getParser(), input.getInputSource());
// show PDF
response.setContentType("application/pdf");
byte[] content = out.toByteArray();
response.setContentLength(content.length);
response.getOutputStream().write(content);
response.getOutputStream().flush();
}
catch (Exception e)
{ throw new ServletException("error while creating pdf directly: " +
e.toString()); }
}
else
{
// Generate fo File from xml and xsl file
try
{
// The XML and XSL sources
Source xmlSource = new StreamSource(xmlFile);
Source xslSource = new StreamSource(xslFile);
// The result (fo File)
Result result = new StreamResult(new PrintWriter(new
FileOutputStream(new java.io.File(foFile))));
// Process
TransformerFactory transFact = TransformerFactory.newInstance();
Transformer trans = transFact.newTransformer(xslSource);
trans.transform(xmlSource, result);
}
catch (Exception e)
{ throw new ServletException("error while creating fo file: " +
e.toString()); }
// Generate PDF from fo File
try
{
// Initialize Logger
Hierarchy hierarchy = Hierarchy.getDefaultHierarchy();
Logger log = hierarchy.getLoggerFor("fop");
log.setPriority(Priority.WARN);
// Preparing source
InputSource foSource = new InputSource(new FileReader(foFile));
// Render
ByteArrayOutputStream pdf = new ByteArrayOutputStream();
Driver driver = new Driver(foSource, pdf);
driver.setLogger(log);
driver.setRenderer(Driver.RENDER_PDF);
driver.run();
// show PDF
response.setContentType("application/pdf");
byte[] content = pdf.toByteArray();
response.setContentLength(content.length);
response.getOutputStream().write(content);
response.getOutputStream().flush();
}
catch (Exception e)
{ throw new ServletException("error while creating pdf using fo file:
" + e.toString()); }
}
}
}
-----------------End
B. Rondepierre
----- Original Message -----
From: "J.Pietschmann" <j3...@yahoo.de>
To: <fo...@xml.apache.org>
Sent: Monday, June 03, 2002 8:48 PM
Subject: Re: Problem with FOP outline extension
> Bruno Rondepierre wrote:
> > By saying "it doesn't" work, I mean that the PDF is created but it
contains
> > no bookmark.
>
> That's bad. Can you supply a short, trimmed down XML source
> and a minimal XSLT demonstrating the problem? Are you using
> disable-output-escaping somewhere?
>
> J.Pietschmann
>
>
Re: Problem with FOP outline extension
Posted by "J.Pietschmann" <j3...@yahoo.de>.
Bruno Rondepierre wrote:
> By saying "it doesn't" work, I mean that the PDF is created but it contains
> no bookmark.
That's bad. Can you supply a short, trimmed down XML source
and a minimal XSLT demonstrating the problem? Are you using
disable-output-escaping somewhere?
J.Pietschmann