Print Directly for the client

Stimulsoft Reports.NET discussion
Post Reply
beginner
Posts: 36
Joined: Thu Jun 18, 2015 5:01 am

Print Directly for the client

Post by beginner »

I'm using Stimulsoft in ASP.NET MVC 5 and I like to show print dialog to the user.

On the client side I only have an `id` and report is not loaded. I'd like to either show directly print dialog or show `print preview` to the user.


Please guide me with this requirement.
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Print Directly for the client

Post by Alex K. »

Hello,

Please try to use the MVCViewer for the showing report in which present several print dialog option.

Thank you.
beginner
Posts: 36
Joined: Thu Jun 18, 2015 5:01 am

Re: Print Directly for the client

Post by beginner »

Hi Aleksey,

I don't want to show him a report, a print preview in another window maybe, but not a full viewer for sure.

Thanks for your replay.
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Print Directly for the client

Post by Alex K. »

Hello,

Please try to use the export to in HTML or PDF and print.
For example:

Code: Select all

        public ActionResult PrintHTML()
        {
            StiReport report = new StiReport();
            report.Load("D:\\MyReport.mrt");
            report.Render(false);

            MemoryStream stream = new MemoryStream();

            StiHtmlExportSettings settings = new StiHtmlExportSettings();
            settings.AddPageBreaks = true;

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

            StreamReader reader = new StreamReader(stream);
            stream.Position = 0;
            string html = reader.ReadToEnd();
            html = html.Replace("<body>", "<body onload='window.print();'>");

            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();
        }

        public ActionResult PrintPDF()
        {
            StiReport report = new StiReport();
            report.Load("D:\\MyReport.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