You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Aravinda Addala <ar...@majorband.co.uk> on 2002/01/31 10:58:36 UTC

Please help. Content type: Sending pdf content to the browser

Hi,

I have read several postings about sending a different content to the
browser. I am trying to generate a pdf using FDF in my action. I get the
content displayed as plain text. I tried many ways ( I had set the content
type both in Response and RunData objects in my action. Also tried to use
data.setContentType in the template. Nothing worked). The same code works
fine if I use that in a Servlet outside turbine.
I am using turbine 3.

Please help.

Thanks in advance.
Aravinda



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Please help. Content type: Sending pdf content to the browser

Posted by Aravinda Addala <ar...@majorband.co.uk>.
It doesn't actually work in Turbine 3 .
All it output on the screen is the plain text of the FDF document(Adobe FDF
api).

Thanks for the reply.
Aravinda



-----Original Message-----
From: Fabio Daprile [mailto:fabio.daprile@wuerth.it]
Sent: Thursday, January 31, 2002 2:51 PM
To: Turbine Users List
Subject: Re: Please help. Content type: Sending pdf content to the
browser


This is how i send files to the browser.
All documents are stored in a table in MySql, in a blob field.
For pdf files the content_type is "application/pdf".
I use turbine 2.

 _attach = (Attachments)(_trans.getAttachmentss().elementAt(0));

 _contentType = _attach.getContenttype() + ";name=" + "\"" +
_attach.getFilename() + "\"";
 data.getResponse().setContentType(_contentType);
 data.getResponse().getOutputStream().write(_attach.getContent());

hope this can help you.

Greetings.

Fabio Daprile

Aravinda Addala wrote:

>Hi,
>
>I have read several postings about sending a different content to the
>browser. I am trying to generate a pdf using FDF in my action. I get the
>content displayed as plain text. I tried many ways ( I had set the content
>type both in Response and RunData objects in my action. Also tried to use
>data.setContentType in the template. Nothing worked). The same code works
>fine if I use that in a Servlet outside turbine.
>I am using turbine 3.
>
>Please help.
>
>Thanks in advance.
>Aravinda
>
>
>
>--
>To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
>For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>
>

--


Würth Phoenix Srl
Via Kravogl 4, I-39100 Bolzano
Tel: +39 0471/564111
Fax: +39 0471/564122

mailto:fabio.daprile@wuerth-phoenix.com
http://www.wuerth-phoenix.com




--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Please help. Content type: Sending pdf content to the browser

Posted by Fabio Daprile <fa...@wuerth.it>.
This is how i send files to the browser.
All documents are stored in a table in MySql, in a blob field.
For pdf files the content_type is "application/pdf".
I use turbine 2.

 _attach = (Attachments)(_trans.getAttachmentss().elementAt(0));

 _contentType = _attach.getContenttype() + ";name=" + "\"" + 
_attach.getFilename() + "\"";
 data.getResponse().setContentType(_contentType);
 data.getResponse().getOutputStream().write(_attach.getContent());

hope this can help you.

Greetings.

Fabio Daprile

Aravinda Addala wrote:

>Hi,
>
>I have read several postings about sending a different content to the
>browser. I am trying to generate a pdf using FDF in my action. I get the
>content displayed as plain text. I tried many ways ( I had set the content
>type both in Response and RunData objects in my action. Also tried to use
>data.setContentType in the template. Nothing worked). The same code works
>fine if I use that in a Servlet outside turbine.
>I am using turbine 3.
>
>Please help.
>
>Thanks in advance.
>Aravinda
>
>
>
>--
>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>
>

-- 


Würth Phoenix Srl
Via Kravogl 4, I-39100 Bolzano
Tel: +39 0471/564111
Fax: +39 0471/564122

mailto:fabio.daprile@wuerth-phoenix.com
http://www.wuerth-phoenix.com




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Please help. Content type: Sending pdf content to the browser

Posted by Steve <tu...@knology.net>.
Aravinda:

Enclosed is a class I wrote that extends Turbine's RawScreen to display pdf
files.  If you can create your pdf stream as a ByteArrayOutputStream then
the following will work "as-is" for you.  Simply extend this ADT and build
your pdf stream in a buildPDF method, returning a ByteArrayOutputStream.
Even if it doesn't work for you, maybe it will help.

Steve

public abstract class PdfScreen extends
org.apache.turbine.modules.screens.RawScreen
{
   /**
    * Set the content type to Pdf. (see RawScreen)
    *
    * @param data Turbine information.
    * @return content type.
    */
    public String getContentType(RunData data)
    {
        return "application/pdf";
    };

    /**
    * Classes that implement this ADT must override this to build the pdf
file.
    *
    * @param data RunData
    * @return ByteArrayOutputStream
    * @exception Exception, any old exception.
    */
    protected abstract ByteArrayOutputStream buildPdf (RunData data) throws
Exception;

    /**
    * Overrides & finalizes doOutput in RawScreen to serve the output stream
created in buildPDF.
    *
    * @param data RunData
    * @exception Exception, any old generic exception.
    */
    protected final void doOutput(RunData data) throws Exception
    {
        ByteArrayOutputStream baos = buildPdf(data);
        if (baos != null)
        {
            HttpServletResponse response = data.getResponse();
            //We have to set the size to workaround a bug in IE (see
com.lowagie iText FAQ)
            data.getResponse().setContentLength(baos.size());
            ServletOutputStream out = response.getOutputStream();
            baos.writeTo(out);
        }
        else
        {
            throw new Exception("output stream from buildPDF is null");
        }
    }
}

-----Original Message-----
From: Aravinda Addala [mailto:aravinda_addala@majorband.co.uk]
Sent: Thursday, January 31, 2002 3:59 AM
To: TurbineDev
Subject: Please help. Content type: Sending pdf content to the browser


Hi,

I have read several postings about sending a different content to the
browser. I am trying to generate a pdf using FDF in my action. I get the
content displayed as plain text. I tried many ways ( I had set the content
type both in Response and RunData objects in my action. Also tried to use
data.setContentType in the template. Nothing worked). The same code works
fine if I use that in a Servlet outside turbine.
I am using turbine 3.

Please help.

Thanks in advance.
Aravinda



--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>