How i can response auto Print to PDF on browser

Stimulsoft Reports.WEB discussion
Post Reply
lightening
Posts: 9
Joined: Wed Feb 25, 2015 8:35 am

How i can response auto Print to PDF on browser

Post by lightening »

How i can auto response Print to PDF on browser
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: How i can response auto Print to PDF on browser

Post by HighAley »

Hello.

Here is a sample code for printing to PDF automatically:

Code: Select all

// Print to PDF
public ActionResult Print()
{
StiReport report = new StiReport();
report.Load("D:\\ReportXmlAir.mrt");
report.Render(false);

MemoryStream stream = new MemoryStream();

StiPdfExportSettings settings = new StiPdfExportSettings();
settings.AutoPrintMode = StiPdfAutoPrintMode.Dialog;

StiPdfExportService service = new StiPdfExportService();
service.ExportPdf(report, stream, settings);

this.Response.Buffer = true;
this.Response.ClearContent();
this.Response.ClearHeaders();
this.Response.ContentType = "application/pdf";
//this.Response.AddHeader("Content-Disposition", "attachment; filename=\"report.pdf\"");
this.Response.ContentEncoding = Encoding.UTF8;
this.Response.AddHeader("Content-Length", stream.Length.ToString());
this.Response.BinaryWrite(stream.ToArray());
this.Response.End();

return View();
}
Thank you.
Post Reply