You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@click.apache.org by "pvmalone@netzero.net" <pv...@netzero.net> on 2013/05/16 17:24:54 UTC

How to Render PDF Reports ?

I am using DynamicReports (based on JasperReports) for creating PDF reports in Apache Click.  Some users want to display the PDF report in a web browser and other users want to display the PDF report in the PDF document viewer (e.g., Adobe Acrobat).  Using the following code the PDF report displays correctly in the browser when using IE, Chrome, and Firefox.  However, for the users that have their browsers configured to show PDFs outside of the browser, the PDF report only displays in the PDF document viewer when using IE.  Chrome and Firefox download a file with the wrong file extension (user-1.htm instead of user-1.pdf).

What is the proper code for getting the PDF report to display correctly both in a web browser or outside of the web browser depending on how the client has their browser configured to display PDFs?

///////////////////
        private static final long serialVersionUID = 1L;

        public User1Page() {
                Submit reportButton = new Submit("runReport", " Report ", this, "onReportClick");
                form1.add(reportButton);
        }

        public void renderPdf() throws ServletException, IOException {
                HttpServletResponse response = getContext().getResponse();
               
                response.setContentType("application/pdf");

                OutputStream out = response.getOutputStream();

                try {
                        report()
                        // ...

                        .toPdf(out);

                } catch (DRException e) {
                  throw new ServletException(e);
                }
                out.close();
        }

        public boolean onReportClick() {
                try {
                        renderPdf();
                } catch (Exception e) {
                        e.printStackTrace();
                }

                return true;
        }
///////////////

Thank you and keep up the good work.  Apache Click is a fantastic framework.

Thank you,
Paul 
____________________________________________________________
Woman is 60 But Looks 25
Mom publishes simple facelift trick that angered doctors...
http://thirdpartyoffers.netzero.net/TGL3231/5194fa5fc3c407a5f3a9cst03duc

Re: How to Render PDF Reports ?

Posted by Bob Schellink <sa...@gmail.com>.
Hi,

This demo might help:
http://click.avoka.com/click-examples/general/excel-export.htm

regards

Bob

On 2013/05/16 17:24, pvmalone@netzero.net wrote:
> I am using DynamicReports (based on JasperReports) for creating PDF reports in Apache Click.  Some users want to display the PDF report in a web browser and other users want to display the PDF report in the PDF document viewer (e.g., Adobe Acrobat).  Using the following code the PDF report displays correctly in the browser when using IE, Chrome, and Firefox.  However, for the users that have their browsers configured to show PDFs outside of the browser, the PDF report only displays in the PDF document viewer when using IE.  Chrome and Firefox download a file with the wrong file extension (user-1.htm instead of user-1.pdf).
>
> What is the proper code for getting the PDF report to display correctly both in a web browser or outside of the web browser depending on how the client has their browser configured to display PDFs?
>
> ///////////////////
>          private static final long serialVersionUID = 1L;
>
>          public User1Page() {
>                  Submit reportButton = new Submit("runReport", " Report ", this, "onReportClick");
>                  form1.add(reportButton);
>          }
>
>          public void renderPdf() throws ServletException, IOException {
>                  HttpServletResponse response = getContext().getResponse();
>                 
>                  response.setContentType("application/pdf");
>
>                  OutputStream out = response.getOutputStream();
>
>                  try {
>                          report()
>                          // ...
>
>                          .toPdf(out);
>
>                  } catch (DRException e) {
>                    throw new ServletException(e);
>                  }
>                  out.close();
>          }
>
>          public boolean onReportClick() {
>                  try {
>                          renderPdf();
>                  } catch (Exception e) {
>                          e.printStackTrace();
>                  }
>
>                  return true;
>          }
> ///////////////
>
> Thank you and keep up the good work.  Apache Click is a fantastic framework.
>
> Thank you,
> Paul
> ____________________________________________________________
> Woman is 60 But Looks 25
> Mom publishes simple facelift trick that angered doctors...
> http://thirdpartyoffers.netzero.net/TGL3231/5194fa5fc3c407a5f3a9cst03duc


Re: How to Render PDF Reports ?

Posted by Naoki Takezoe <ta...@gmail.com>.
Could you set the filename by Content-Disposition header?

2013/05/17 0:25 "pvmalone@netzero.net" <pv...@netzero.net>:
>
> I am using DynamicReports (based on JasperReports) for creating PDF
reports in Apache Click.  Some users want to display the PDF report in a
web browser and other users want to display the PDF report in the PDF
document viewer (e.g., Adobe Acrobat).  Using the following code the PDF
report displays correctly in the browser when using IE, Chrome, and
Firefox.  However, for the users that have their browsers configured to
show PDFs outside of the browser, the PDF report only displays in the PDF
document viewer when using IE.  Chrome and Firefox download a file with the
wrong file extension (user-1.htm instead of user-1.pdf).
>
> What is the proper code for getting the PDF report to display correctly
both in a web browser or outside of the web browser depending on how the
client has their browser configured to display PDFs?
>
> ///////////////////
>         private static final long serialVersionUID = 1L;
>
>         public User1Page() {
>                 Submit reportButton = new Submit("runReport", " Report ",
this, "onReportClick");
>                 form1.add(reportButton);
>         }
>
>         public void renderPdf() throws ServletException, IOException {
>                 HttpServletResponse response = getContext().getResponse();
>
>                 response.setContentType("application/pdf");
>
>                 OutputStream out = response.getOutputStream();
>
>                 try {
>                         report()
>                         // ...
>
>                         .toPdf(out);
>
>                 } catch (DRException e) {
>                   throw new ServletException(e);
>                 }
>                 out.close();
>         }
>
>         public boolean onReportClick() {
>                 try {
>                         renderPdf();
>                 } catch (Exception e) {
>                         e.printStackTrace();
>                 }
>
>                 return true;
>         }
> ///////////////
>
> Thank you and keep up the good work.  Apache Click is a fantastic
framework.
>
> Thank you,
> Paul
> ____________________________________________________________
> Woman is 60 But Looks 25
> Mom publishes simple facelift trick that angered doctors...
> http://thirdpartyoffers.netzero.net/TGL3231/5194fa5fc3c407a5f3a9cst03duc