Report Application Server XI Release 2 Java SDK

Export a report to PDF

This sample shows you how to export a Crystal Report to PDF format. RAS enables you to export reports to a specific format, such as Excel, PDF, or RTF.

This sample does the following:

Preconditions
Managed RAS environment
Unmanaged RAS environment
Example

<%@

   page import="com.crystaldecisions.sdk.occa.report.application.*,

  com.crystaldecisions.sdk.occa.report.data.*,

  com.crystaldecisions.sdk.occa.report.lib.*,

  com.crystaldecisions.sdk.occa.report.exportoptions.*,

  com.crystaldecisions.sdk.occa.report.reportsource.IReportSource,

  java.util.*,

  java.io.*"

%>

<html>

<head>

<title>Export a Report to PDF</title>

</head>

<body>

<%

/* Include the file AlwaysRequiredSteps.jsp, which contains the code to:

   - Create a new Report Application Session

   - Create a RAS service

   - Set the RAS server to be used for the service

   - Initialize the RAS service

   - Create the ReportClientDocument object

   - Set the RAS Server to be used for the report

   - Open the report, and set the open type to Read Only

*/

%>

<%@ include file="AlwaysRequiredSteps.jsp"%>

<%

//Use the report document's PrintOutputController to export the report to a ByteArrayInputStream

ByteArrayInputStream byteIS = (ByteArrayInputStream) clientDoc.getPrintOutputController().export(ReportExportFormat.PDF);

//Create a byte[] that is the same size as the exported ByteArrayInputStream

byte[] buf = new byte[2000 * 1024];

int nRead = 0;

//Set response headers

response.reset();

response.setHeader("content-disposition", "inline;filename=untitled.pdf");

response.setContentType("application/pdf");

//Send the Byte Array to the Client

while ((nRead = byteIS.read(buf)) != -1) {

  response.getOutputStream().write(buf, 0, nRead);

}

//Flush the output stream

response.getOutputStream().flush();

//Close the output stream

response.getOutputStream().close();

%>



Business Objects
http://www.businessobjects.com/
Support services
http://www.businessobjects.com/services/support/
Product Documentation on the Web
http://support.businessobjects.com/documentation/