C# SSRS - Thermal Printing - 3 Inch Printing Configuration to print directly without preview

  //Report Printing Section
        private int m_currentPageIndex;
        private IList<Stream> m_streams;

        private Stream CreateStream(string name, string fileNameExtension, System.Text.Encoding encoding,
            string mimeType, bool willSeek)
        {
            Stream stream = new MemoryStream();
            m_streams.Add(stream);
            return stream;
        }

        private void Export(LocalReport report)
        {
            string deviceInfo = @"<DeviceInfo><OutputFormat>EMF</OutputFormat><PageWidth>3.5in</PageWidth><MarginTop>0.01in</MarginTop><MarginLeft>0.01in</MarginLeft><MarginRight>0.1in</MarginRight><MarginBottom>0.01in</MarginBottom></DeviceInfo>";
            Microsoft.Reporting.WinForms.Warning[] warnings;
            m_streams = new List<Stream>();
            report.Render("Image", deviceInfo, CreateStream, out warnings);
            foreach (Stream stream in m_streams) stream.Position = 0;
        }

        private void Print()
        {
            if (m_streams == null || m_streams.Count == 0) throw new Exception("Error: no stream to print.");
            PrintDocument printDoc = new PrintDocument();
            if (!printDoc.PrinterSettings.IsValid)
            {
                throw new Exception("Error: cannot find the default printer.");
            }
            else
            {
                printDoc.PrintPage += new PrintPageEventHandler(PrintPage);
                m_currentPageIndex = 0;
                PaperSize pkCustomSize1 = new PaperSize("First custom size", 350, 700);
                printDoc.DefaultPageSettings.PaperSize = pkCustomSize1;

                printDoc.Print();
            }
        }

        private void PrintPage(object sender, PrintPageEventArgs ev)
        {
            System.Drawing.Imaging.Metafile pageImage =
                new System.Drawing.Imaging.Metafile(m_streams[m_currentPageIndex]);

            // Adjust rectangular area with printer margins.
            System.Drawing.Rectangle adjustedRect = new System.Drawing.Rectangle(
                ev.PageBounds.Left - (int) ev.PageSettings.HardMarginX,
                ev.PageBounds.Top - (int) ev.PageSettings.HardMarginY, ev.PageBounds.Width, ev.PageBounds.Height);

            // Draw a white background for the report
            ev.Graphics.FillRectangle(System.Drawing.Brushes.White, adjustedRect);

            // Draw the report content
            ev.Graphics.DrawImage(pageImage, adjustedRect);

            // Prepare for the next page. Make sure we haven't hit the end.
            m_currentPageIndex++;
            ev.HasMorePages = (m_currentPageIndex < m_streams.Count);
        }

//Report Printing Section
//SalePrintReport - a local report loaded with required data source and parameters
 Export(SalePrintReport);
 Print();

//etc
//RDLC size in Design Time - 3.5 Inches of Width, and Avg Height of 7 Inches.


Comments