private int m_currentPageIndex; private List m_streams; private Stream CreateStream (string name, string fileNameExtension,Encoding encoding, string mimeType, bool willSeek) { Stream stream = new MemoryStream (); m_streams.Add(stream); return stream; } private void run() { LocalReport _localReport = _reportviewer.LocalReport; string path = Path.GetDirectoryName(Application.StartupPath); string reportPath = Path.Combine(path, @"PlanoInspecao.rdlc"); string originalpath = reportPath.Replace("\\bin", ""); _localReport.ReportPath = originalpath; Int32 OrderID = Convert.ToInt32(dgvPlano.SelectedRows[0].Cells[0].Value); PlanoManutencaoNegocios planonegocios = new PlanoManutencaoNegocios(); DataTable dt = new DataTable(); dt = planonegocios.SelecionarporId(OrderID); ReportDataSource source = new ReportDataSource(dt.TableName , dt); _localReport.DataSources.Add(source); Export(_localReport); Print(); } private void Export(LocalReport report) { try { string deviceInfo = @" EMF 8.5in 11in 0.25in 0.25in 0.25in 0.25in "; Warning[] warnings; report.Render("Image", deviceInfo, CreateStream, out warnings); <- o erro aparece aqui Stream stream = new MemoryStream(); m_streams.Add(stream); } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void PrintPage(object sender, PrintPageEventArgs ev) { Metafile pageImage = new Metafile(m_streams[m_currentPageIndex]); // Adjust rectangular area with printer margins. Rectangle adjustedRect = new 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(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); } private void Print() { try { 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; printDoc.Print(); } } catch (Exception ex ) { MessageBox.Show(ex.Message); } }