Howto: present a Crystal Reports report as a PDF in an ASP.NET web application (without using temporary files)
By rickvdbosch
- 1 minutes read - 112 wordsThis one is actually quite simple: Crystal Reports supports exporting to a PDF. Exporting can be done to disk, or to a stream. And a stream can be written to the Repsonse property of a page. And there you go đ
// Variable declaration  CrystalTest crystalTest;  MemoryStream memoryStream;// Create a new instance of the report you want to display as a PDF  crystalTest = new CrystalTest();// TODO: Add some stuff here to fill the report with data// Export the report to a stream with the PDF format  memoryStream = (MemoryStream)crystalTest.ExportToStream(ExportFormatType.PortableDocFormat);// Set the ContentType to pdf, add a header for the length // and write the contents of the memorystream to the response  Response.ContentType = âapplication/pdfâ;  Response.AddHeader(âcontent-lengthâ, Convert.ToString(memoryStream.Length));  Response.BinaryWrite(memoryStream.ToArray());//End the response  Response.End();