How to Export a Report Directly to PDF

In order to export a report directly to PDF, without clicking the 'Export to PDF' button, use the following code:

For RSS:

PerpetuumSoft.Reporting.Export.Pdf.PdfExportFilter filter = 
new PerpetuumSoft.Reporting.Export.Pdf.PdfExportFilter();
filter.Export(fileReportSlot1.RenderDocument(), "doc1");

For RSS WebViewer ASP.net:

private void OutputAsPdf(Document doc, string docName)
{
  Page.Response.Buffer = true;
  Page.Response.ClearContent();
  Page.Response.ClearHeaders();
  Page.Response.ContentType = "application/pdf";
  PdfExportFilter pdf = new PdfExportFilter();
  SharpShooterWebViewer1.PdfExportSettings.SetExportSettings(pdf);
  Page.Response.AddHeader("Content-Disposition", 
"attachment; filename=" + docName + "." 
+ pdf.GetFilterFileExtension());
  pdf.Export(doc, Page.Response.OutputStream);
  Page.Response.End();
}

protected void ButtonExport_Click(object sender, EventArgs e)
{
  //set filepath for web viewer
  LoadTemplate();
  //initialize dataset for getting data
  InitDataSets();
  OutputAsPdf((SharpShooterWebViewer1.Source as 
ReportSlot).RenderDocument(),"doc1");
}

Related article: PDF Export.

Add Feedback