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 Ji...@orcz.cz on 2002/11/05 16:17:25 UTC

How to show PDF file in jsp page II.

Yesterday, after a few good advices there from fop users I successfuly used
this code to show pdf content in browser. It works in my JDeveloper 9i.

File inputFile = new File(pdfFile);
FileReader fr = new FileReader(inputFile);

ByteArrayOutputStream baos = new ByteArrayOutputStream();
int ch;
while((ch = fr.read()) != -1) {
  baos.write(ch);
}

byte[] content = baos.toByteArray();
response.setContentType("application/pdf");
response.setContentLength(content.length);
response.getOutputStream().write(content);
response.getOutputStream().flush();

---

But when I deploy my application to Tomcat (4.0.3, on same PC as browser),
browser shows dialog, asking whether to open or save the data. I can only
save it, open doesn't work. I use IE 6.0. I tried both GET and POST methods
with the same result.

Any ideas ?





Re: xsl loop

Posted by Oleg Tkachenko <ol...@multiconn.com>.
xavier gibouin wrote:

> I would like to know if is it possible to realise à loop like :
>
> for(index=0, index++, index<100) {
>
>
> }
>
> in xsl language 

Sure. As in any functional language you can do it using recursion,
e.g. see http://www.dpawson.co.uk/xsl/sect2/repetition.html

-- 
Oleg Tkachenko
eXperanto team
Multiconn Technologies, Israel


Re:xsl loop

Posted by xavier gibouin <xa...@axonie.com>.
Hi 

I would like to know if is it possible to realise à loop like :

for(index=0, index++, index<100) {


}

in xsl language

thanks a lot


Xavier Gibouin
Axonie
Espace Mercoeur
8, rue Mercoeur
44000 Nantes
02.40.48.53.23
xavier.gibouin@axonie.com

Re: variable and svg

Posted by "J.Pietschmann" <j3...@yahoo.de>.
xavier gibouin wrote:
>       <rect height="50" width="1.5" x="$x" y="0.0"/>
...
> but fop doesn't want assign the value of $x in "rec" tag

It's not FOP, its the XSLT processor.
Use
  <rect height="50" width="1.5" x="{$x}" y="0.0"/>

This is called "attribute value template", look up details in
an XSLT book, a tutorial or the XSL FAQ.

XSLT questions like this are better asked on the XSL list:
  http://www.mulberrytech.com/xsl/xsl-list/

J.Pietschmann


Re: variable and svg

Posted by xavier gibouin <xa...@axonie.com>.
Hi

this is my code for genrate code barre from a  number

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:svg="http://www.w3.org/Graphics/SVG/SVG-19990812.dtd">
 <xsl:template name="codebarre">
  <xsl:variable name="index" select="string-length(codebarre)"/>
  <xsl:variable name="x"/>

  <xsl:param name="i" select="0"/>

  <xsl:if test="$i &lt; $index">
   <xsl:choose>
    <xsl:when test="substring(codebarre,$i+1,1)='1'">
     <svg xmlns="http://www.w3.org/2000/svg">
      <rect height="50" width="4.0" x="$x" y="0.0"/>
     </svg>
     <xsl:variable name="x" select="$x+4"/>
     <fo:block>large noir</fo:block>
    </xsl:when>
    <xsl:when test="substring(codebarre,$i+1,1)='2'">
     <svg xmlns="http://www.w3.org/2000/svg">
      <rect height="50" width="1.5" x="$x" y="0.0"/>
     </svg>
     <xsl:variable name="x" select="$x+1.5"/>
    </xsl:when>
    <xsl:when test="substring(codebarre,$i+1,1)='3'">
     <xsl:variable name="x" select="$x+3"/>
    </xsl:when>
    <xsl:when test="substring(codebarre,$i+1,1)='4'">
     <xsl:variable name="x" select="$x+1.5"/>
    </xsl:when>
   </xsl:choose>

   <xsl:call-template name="codebarre">
    <xsl:with-param name="i" select="$i+1"/>
   </xsl:call-template>

  </xsl:if>
 </xsl:template>
</xsl:stylesheet>

but fop doesn't want assign the value of $x in "rec" tag

any ideas ??

thanks a lot

Xavier Gibouin
Axonie
Espace Mercoeur
8, rue Mercoeur
44000 Nantes
02.40.48.53.23
xavier.gibouin@axonie.com

Re: How to show PDF file in jsp page II.

Posted by Oleg Tkachenko <ol...@multiconn.com>.
Jiri_Nejedly@orcz.cz wrote:

> Yesterday, after a few good advices there from fop users I successfuly used
> this code to show pdf content in browser. It works in my JDeveloper 9i.
>
> File inputFile = new File(pdfFile);
> FileReader fr = new FileReader(inputFile);
>
> ByteArrayOutputStream baos = new ByteArrayOutputStream();
> int ch;
> while((ch = fr.read()) != -1) {
>   baos.write(ch);
> }
>
> byte[] content = baos.toByteArray();
> response.setContentType("application/pdf");
> response.setContentLength(content.length);
> response.getOutputStream().write(content);
> response.getOutputStream().flush();

Looks too convolute to me. If you have already created pdf file on a disk, why 
  do you process it by hands instead of rely on a web server? Just redirect 
browser to the file, that will emulate reading static pdf, which works okay 
even in IE (well, at least if extension is pdf).
I mean
response.sendRedirect("/foo/bar.pdf");

-- 
Oleg Tkachenko
eXperanto team
Multiconn Technologies, Israel