To export a report to PDF

  1. Use the PrintOutputController object to export the report to a ByteArrayInputStream object.
    ByteArrayInputStream byteIS = (ByteArrayInputStream)rcd.getPrintOutputController().export(ReportExportFormat.PDF); 
  2. Create a byte array the same size as the exported ByteArrayInputStream object.
    byte[] buf = new byte[2000 *1024];
  3. Create a file output stream.
    FileOutputStream fos = new FileOutputStream("C:\\MyReport.pdf");
  4. Copy the contents of the byte stream to the file output stream.
    int nRead = 0;
    while ((nRead = byteIS.read(buf)) != -1)
    {
      fos.write(buf, 0, nRead);
    }
  5. Close the file output stream.
    fos.close();
Example: 
void exportToPDF(ReportClientDocument rcd) throws ReportSDKException, IOException
{
  ByteArrayInputStream byteIS = (ByteArrayInputStream)rcd.getPrintOutputController().export(ReportExportFormat.PDF);
  byte[] buf = new byte[2000 *1024];
              
  FileOutputStream fos = new FileOutputStream("C:\\MyReport.pdf");
        
  int nRead = 0;
  while ((nRead = byteIS.read(buf)) != -1)
  {
    fos.write(buf, 0, nRead);
  }
  fos.close();
}
This list includes the classes used by the sample code:
  • com.crystaldecisions.sdk.occa.report.application.ReportClientDocument
  • com.crystaldecisions.sdk.occa.report.exportoptions.ReportExportFormat
  • com.crystaldecisions.sdk.occa.report.lib.ReportSDKException
  • java.io.ByteArrayInputStream
  • java.io.FileOutputStream
  • java.io.IOException