Exemplo n.º 1
0
        public static void Export(Microsoft.Reporting.WinForms.LocalReport report, bool print = true)
        {
            string deviceInfo =
                @"<DeviceInfo>
                <OutputFormat>EMF</OutputFormat>
                <PageWidth>8.26in</PageWidth>
                <PageHeight>11.69in</PageHeight>
                <MarginTop>0.4in</MarginTop>
                <MarginLeft>0.2in</MarginLeft>
                <MarginRight>0.2in</MarginRight>
                <MarginBottom>0.2in</MarginBottom>
            </DeviceInfo>";

            Warning[] warnings;
            m_streams = new List <Stream>();
            report.Render("Image", deviceInfo, CreateStream,
                          out warnings);
            foreach (Stream stream in m_streams)
            {
                stream.Position = 0;
            }

            if (print)
            {
                Print();
            }
        }
Exemplo n.º 2
0
        private void RenderAllLocalReportPages(Microsoft.Reporting.WinForms.LocalReport localReport)
        {
            try
            {
                string deviceInfo = CreateEMFDeviceInfo();

                Warning[] warnings;

                localReport.Render("IMAGE", deviceInfo, LocalReportCreateStreamCallback, out warnings);
            }
            catch (Exception e)
            {
                MessageBox.Show("error :: " + e);
            }
        }
Exemplo n.º 3
0
        public static void ExportToWORD(LocalReport report, String FullPath)
        {
            string deviceInfo = "<DeviceInfo>" +
                                "  <OutputFormat>WORD</OutputFormat>" +

                                "  <EmbedFonts>None</EmbedFonts>" +
                                "</DeviceInfo>";


            //   byte[] renderedBytes = report.Render("WORD", deviceInfo, out mimeType, out encoding, out fileNameExtension, out streams, out warnings);
            // byte[] Bytes = report.Render("Excel", deviceInfo);
            byte[] Bytes = report.Render(format: "WORD", deviceInfo);
            // File.SetAttributes(savePath, FileAttributes.Normal);

            using (FileStream stream = new FileStream(FullPath, FileMode.Create))
            {
                stream.Write(Bytes, 0, Bytes.Length);
            }
        }
Exemplo n.º 4
0
        public override byte[] export(string fileType)
        {
            var rpt = new Microsoft.Reporting.WinForms.LocalReport();

            //rpt.ReportPath = "Rpt01.rdlc";
            rpt.EnableExternalImages = true;


            for (int i = 0; i < this.ds.Tables.Count; i++)
            {
                var o = new Microsoft.Reporting.WinForms.ReportDataSource(this.ds.Tables[i].TableName, this.ds.Tables[i]);
                rpt.DataSources.Add(o);
            }

            //string sReportName = Request.QueryString["ReportName"];
            System.IO.MemoryStream ms = new System.IO.MemoryStream(this.output);
            rpt.LoadReportDefinition(ms);


            Byte[] results = rpt.Render(fileType);

            return(results);
        }
Exemplo n.º 5
0
        public static void Print(this LocalReport report, PageSettings pageSettings)
        {
            string deviceInfo =
                $@"<DeviceInfo>
                    <OutputFormat>EMF</OutputFormat>
                    <PageWidth>{pageSettings.PaperSize.Width * 100}in</PageWidth>
                    <PageHeight>{pageSettings.PaperSize.Height * 100}in</PageHeight>
                    <MarginTop>{pageSettings.Margins.Top * 100}in</MarginTop>
                    <MarginLeft>{pageSettings.Margins.Left * 100}in</MarginLeft>
                    <MarginRight>{pageSettings.Margins.Right * 100}in</MarginRight>
                    <MarginBottom>{pageSettings.Margins.Bottom * 100}in</MarginBottom>
                </DeviceInfo>";

            Warning[] warnings;
            var       streams   = new List <Stream>();
            var       pageIndex = 0;

            report.Render("Image", deviceInfo,
                          (name, fileNameExtension, encoding, mimeType, willSeek) =>
            {
                MemoryStream stream = new MemoryStream();
                streams.Add(stream);
                return(stream);
            }, out warnings);
            foreach (Stream stream in streams)
            {
                stream.Position = 0;
            }
            if (streams == null || streams.Count == 0)
            {
                throw new Exception("No stream to print.");
            }
            using (PrintDocument printDocument = new PrintDocument())
            {
                printDocument.DefaultPageSettings = pageSettings;
                if (!printDocument.PrinterSettings.IsValid)
                {
                    throw new Exception("Can't find the default printer.");
                }
                else
                {
                    printDocument.PrintPage += (sender, e) =>
                    {
                        Metafile  pageImage    = new Metafile(streams[pageIndex]);
                        Rectangle adjustedRect = new Rectangle(e.PageBounds.Left - (int)e.PageSettings.HardMarginX, e.PageBounds.Top - (int)e.PageSettings.HardMarginY, e.PageBounds.Width, e.PageBounds.Height);
                        e.Graphics.FillRectangle(Brushes.White, adjustedRect);
                        e.Graphics.DrawImage(pageImage, adjustedRect);
                        pageIndex++;
                        e.HasMorePages = (pageIndex < streams.Count);
                        e.Graphics.DrawRectangle(Pens.Red, adjustedRect);
                    };
                    printDocument.EndPrint += (Sender, e) =>
                    {
                        if (streams != null)
                        {
                            foreach (Stream stream in streams)
                            {
                                stream.Close();
                            }
                            streams = null;
                        }
                    };
                    printDocument.PrinterSettings.Copies = _printCopy;
                    printDocument.Print();
                }
            }
        }
Exemplo n.º 6
0
        public static void ExportToPDF(LocalReport report, String FullPath)
        {/*
          * Warning[] warnings;
          * string[] streamIds;
          * string mimeType = string.Empty;
          * string encoding = string.Empty;
          * string extension = string.Empty;
          *
          * var bytes = report.Render("PDF", null, out mimeType, out encoding, out extension, out streamIds, out warnings);
          *
          * string fullpath = Path.Combine(DirPath, Filename);
          * using (FileStream stream = new FileStream(fullpath.ToString(), FileMode.Create))
          * {
          *     stream.Write(bytes, 0, bytes.Length);
          *     stream.Close();
          * }
          *
          */
            string deviceInfo = string.Format(
                CultureInfo.InvariantCulture,
                "<DeviceInfo>" +
                "<OutputFormat>PDF</OutputFormat>" +

                /*
                 * "<PageWidth>{5}</PageWidth>" +
                 * "<PageHeight>{4}</PageHeight>" +
                 *
                 * "<MarginTop>{0}</MarginTop>" +
                 * "<MarginLeft>{1}</MarginLeft>" +
                 * "<MarginRight>{2}</MarginRight>" +
                 * "<MarginBottom>{3}</MarginBottom>" +
                 *
                 */
                "<EmbedFonts>None</EmbedFonts>" +
                "</DeviceInfo>");

            /*
             * string mimeType;
             * string encoding;
             * string fileNameExtension;
             * Warning[] warnings;
             * string[] streams;
             */
            //  byte[] renderedBytes = report.Render("PDF", deviceInfo, out mimeType, out encoding, out fileNameExtension, out streams, out warnings);

            byte[] Bytes = report.Render(format: "PDF", deviceInfo);
            // File.SetAttributes(savePath, FileAttributes.Normal);
            try {
                using (FileStream stream = new FileStream(FullPath, FileMode.Create))
                {
                    try
                    {
                        stream.Write(Bytes, 0, Bytes.Length);
                        stream.Close();
                    }
                    catch
                    {
                    }
                    finally
                    {
                        stream.Close();
                    }
                }
            }
            catch { }
        }