Page 1 of 1

How to print in background

Posted: Wed Oct 17, 2012 6:27 am
by lyai
Hello everyone
I'm using mvc product, I would like to directly call report printing function without the need to pass the first preview, please tell me whether this method is feasible, and if possible how to encode
Thank you

Re: How to print in background

Posted: Wed Oct 17, 2012 12:52 pm
by HighAley
Hello.

You could use one of the next examples of printing to PDF or HTML. In both cases the report will be rendered and sent to print 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();
}


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

MemoryStream stream = new MemoryStream();

StiHtmlExportSettings settings = new StiHtmlExportSettings();
StiHtmlExportService service = new StiHtmlExportService();
service.ExportHtml(report, stream, settings);

StreamReader reader = new StreamReader(stream);
stream.Position = 0;
string html = reader.ReadToEnd();
html = html.Replace("", "");

this.Response.Buffer = true;
this.Response.ClearContent();
this.Response.ClearHeaders();
this.Response.ContentType = "text/html";
//this.Response.AddHeader("Content-Disposition", "attachment; filename=\"report.html\"");
this.Response.ContentEncoding = Encoding.UTF8;
this.Response.AddHeader("Content-Length", html.Length.ToString());
this.Response.Write(html);
this.Response.End();

return View();
}
Thank you.

Re: How to print in background

Posted: Tue Jan 08, 2013 10:54 am
by Buknoy Palaboy
Hi Aleksey,

Is it possible that after saving to PDF, the document will have the same behavior as the "Open After Export" but on the same browser instead of a new window?

Regards and Thanks,
Buknoy

Re: How to print in background

Posted: Wed Jan 09, 2013 11:09 am
by HighAley
Hello.

We have added OpenExportedReportTarget option. It could have "_blank" or "_self" value.
This feature will be available in our next prerelease build.

Thank you.