myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sertic Mirko, Bedag" <Mirko.Ser...@bedag.ch>
Subject AW: PDF+JSF question
Date Wed, 05 Mar 2008 14:43:34 GMT
Hi

 

If you want to send a text as a download file to the browser, so something like this. You
can also

Send a binary file the same way by modifying this method a little bit :

 

    public void sentFileToBrowser(FacesContext aContext, String aFileName, String aContent,
boolean aAttachment) {

 

        try {

            HttpServletResponse theResponse = (HttpServletResponse) aContext.getExternalContext().getResponse();

            theResponse.setCharacterEncoding("UTF-8");

 

            MimeTypeGuesser theMimeTypeGuesser = MimeTypeGuesser.getInstance();

            String theContentType = theMimeTypeGuesser.guessMimeTypeFromFileName(aFileName);

 

            LOGGER.logDebug("Content type is " + theContentType);

 

            String theContentDisposition = aAttachment ? "attachment" : "inline";

 

            theResponse.setContentType(theContentType);

            theResponse.setHeader("Content-disposition", theContentDisposition + "; filename=\""
+ aFileName + "\"");

 

            // Make sure it is running with SSL smooth.....

            theResponse.setHeader("Pragma", "private");

 

            PrintWriter theWriter = new PrintWriter(new OutputStreamWriter(theResponse.getOutputStream(),
"UTF-8"));

            theWriter.print(aContent);

            theWriter.flush();

 

            theWriter.close();

 

            aContext.responseComplete();

 

        } catch (Exception e) {

            throw new FacesException("Error sending file", e);

        }

    }

 

Regards

Mirko

 

Von: daniel ccss [mailto:danielccss2@gmail.com] 
Gesendet: Dienstag, 4. März 2008 20:20
An: users@myfaces.apache.org
Betreff: Re: PDF+JSF question

 

Anybody??

On Tue, Mar 4, 2008 at 11:05 AM, daniel ccss <danielccss2@gmail.com> wrote:

In Struts I do this for join 2 jasperreport pdfs:

PdfReader reader1 = new PdfReader(bytes);
PdfReader reader2 = new PdfReader(bytes2);
 
PdfCopyFields copy = 
new PdfCopyFields(new FileOutputStream( context.getRealPath("/reportes/Calificación de Derechos
por Beneficio 
Familiar - Resolución Nº " + 
beneficioForm.getNumeroResolucionBeneficio() + ".pdf")));
 
copy.addDocument(reader1);
copy.addDocument(reader2);
copy.close();


How can I do this en JSF??

Someone told me that use PdfCopyFields 

Have you tried passing the OutputStream from the response to the
PdfCopyFields instead of a FileOutputStream?

Can anyone give me an example of this?

Thanks!!

 


Mime
View raw message