You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Krishna Manchikalapudi <kr...@corpus.com> on 2005/04/28 22:14:31 UTC

PDF Generation

I have to requirement to generate & load PDF with tapestry. Am generating PDF using XML + XSL-FO & able to generate using just java.

I appreicate if some one done this work then please point me an example.

thanks
   krishna

Re: PDF Generation

Posted by Konstantin Iignatyev <kg...@yahoo.com>.
This another way to generate PDF/HTML/CSV is to use JasperReports:  
http://kgionline.com/presentations/ireport/ireportDemo.jsp
I use the method above to prepare Jasper report and then use T service 
to render it into PDF/CSV and stream it to browser:

public class JasperToPDFService extends AbstractService{

  public static final String SERVICE_NAME = "JasperToPDFService";

  public String getName(){
    return SERVICE_NAME;
  }

  /**
   * parameters[page,ognlExpressionToGetSource]
   * @param iEngineServiceView
   * @param cycle
   * @param responseOutputStream
   * @throws javax.servlet.ServletException
   * @throws java.io.IOException
   */
  public void service( IEngineServiceView iEngineServiceView, 
IRequestCycle cycle, ResponseOutputStream responseOutputStream ) throws 
ServletException, IOException{
    Object[] params = getParameters( cycle ) ;
    String pageName = (String) params[0];
    String srcExpression = (String) params[1];
    responseOutputStream.setContentType( "application/pdf" );
    HttpServletResponse response = cycle.getRequestContext().getResponse();
    response.setHeader("Expires", "0");
    response.setHeader("Cache-Control", "must-revalidate, post-check=0, 
pre-check=0");
    response.setHeader("Pragma", "public");
    response.setHeader("Content-Disposition", "attachment; filename=\"" 
+ pageName +".pdf\"");
    try{
      JasperPrint p = (JasperPrint) Ognl.getValue( Ognl.parseExpression( 
srcExpression ), cycle.getPage( pageName ) );
      
ConsoleServicesFactory.getJasperReportExecutor().exportReportToPDF( p, 
response.getOutputStream());
    } catch( Exception e ){
      throw new ServletException( e );
    }
  }

  public ILink getLink( IRequestCycle iRequestCycle, IComponent 
iComponent, Object[] params ){
      return this.constructLink( iRequestCycle,getName(),null, 
params,false );
  }

Krishna Manchikalapudi wrote:

>I have to requirement to generate & load PDF with tapestry. Am generating PDF using XML + XSL-FO & able to generate using just java.
>
>I appreicate if some one done this work then please point me an example.
>
>thanks
>   krishna
>  
>


-- 
Thanks,

Konstantin Ignatyev

http://www.kgionline.com





PS: If this is a typical day on planet earth, humans will add fifteen million tons of carbon to the atmosphere, destroy 115 square miles of tropical rainforest, create seventy-two miles of desert, eliminate between forty to one hundred species, erode seventy-one million tons of topsoil, add 2.700 tons of CFCs to the stratosphere, and increase their population by 263.000

Bowers, C.A.  The Culture of Denial:  
Why the Environmental Movement Needs a Strategy for Reforming Universities and Public Schools.  
New York:  State University of New York Press, 1997: (4) (5) (p.206)


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org