Exemple #1
0
        protected override ExportBase CreateExporter()
        {
            var res = new FastReport.Export.Image.ImageExport();

            res.ImageFormat   = FastReport.Export.Image.ImageExportFormat.Bmp;
            res.SeparateFiles = false;
            return(res);
        }
Exemple #2
0
        protected override ExportBase CreateExporter()
        {
            var res = new FastReport.Export.Image.ImageExport
            {
                ImageFormat   = FastReport.Export.Image.ImageExportFormat.Tiff,
                SeparateFiles = false
            };

            return(res);
        }
Exemple #3
0
        public IActionResult ReporteImg(string NombreReporte, IList <RepParametro> parametros)
        {
            FastReport.Utils.Config.WebMode = true;
            var rep      = new WebReport();
            var savePath = System.IO.Path.Combine(Startup.entorno.WebRootPath, "Reportes");
            var path     = $"{savePath}\\{NombreReporte}.frx";//guarda el frm del reporte creado de fast repor

            rep.Report.Load(path);

            var str = Resources.JsonStringProvider.GetJson(CultureInfo.CurrentCulture.Name); //idioma

            rep.Report.Dictionary.Connections[0].ConnectionString = StringProvider.StringGE;
            rep.Report.Dictionary.Connections[1].ConnectionString = StringProvider.StringEmpresas;// primera conexion
            rep.Report.Dictionary.Connections[2].ConnectionString = str;


            foreach (var item in parametros)
            {
                rep.Report.SetParameterValue(item.Nombre, item.Valor);// envia por parametro el idempresa a fast report
            }


            if (rep.Report.Prepare())
            {
                FastReport.Export.Image.ImageExport imgExport = new FastReport.Export.Image.ImageExport();
                //imgExport.ShowProgress = false;
                imgExport.ImageFormat   = FastReport.Export.Image.ImageExportFormat.Jpeg;
                imgExport.SeparateFiles = false;
                imgExport.Resolution    = 300;


                MemoryStream strm = new MemoryStream();
                rep.Report.Export(imgExport, strm);
                rep.Report.Dispose();
                imgExport.Dispose();
                strm.Position = 0;

                return(File(strm, "image/jpeg", $"{NombreReporte}.pdf"));
            }
            else
            {
                return(null);
            }
        }
        public IActionResult Get(int i = 0)
        {
            List <string> l = new System.Collections.Generic.List <string>();

            foreach (string s in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
            {
                l.Add(s);
            }
            //return this.Ok();
            string mime = "application/html";

            using (MemoryStream stream = new MemoryStream()) // Create a stream for the report
            {
                Report WebReport = new Report();
                WebReport.Load("SimpleList.frx");
                FastReport.Export.Image.ImageExport image = new FastReport.Export.Image.ImageExport();
                image.ImageFormat = FastReport.Export.Image.ImageExportFormat.Tiff;

                WebReport.Prepare();
                WebReport.Export(image, stream);
                System.Drawing.Printing.PrintDocument document = new System.Drawing.Printing.PrintDocument();
                // document.DocumentName ="SimpleList.frx" ;

                document.PrinterSettings = new System.Drawing.Printing.PrinterSettings()
                {
                    PrinterName = l.Single(s => s == "PDF")
                };
                // document.DefaultPageSettings.PrinterResolution =document.PrinterSettings.PrinterResolutions[i];
                document.DefaultPageSettings.Margins = new System.Drawing.Printing.Margins(1, 1, 1, 1);
                var paperSize = document.PrinterSettings.PaperSizes.Cast <System.Drawing.Printing.PaperSize>().FirstOrDefault(e => e.PaperName == "A5");
                document.DefaultPageSettings.PaperSize = paperSize;
                document.PrintPage += new System.Drawing.Printing.PrintPageEventHandler((o, e) => {
                    // string s = System.Text.Encoding.ASCII.GetString(stream.ToArray());
                    e.Graphics.DrawImage(Image.FromStream(stream), new Point(0, 0));
                });
                document.Print();
                return(this.Ok());

                //return File(stream.ToArray(), mime);
            }
        }
        private ExportBase Format(FRDataForm form)
        {
            switch (form.format)
            {
            case "PDF":  return(new FastReport.Export.Pdf.PDFExport());

            case "ODT":  return(new FastReport.Export.Odf.ODTExport());

            case "ODS":  return(new FastReport.Export.Odf.ODSExport());

            case "XLSX": return(new FastReport.Export.OoXML.Excel2007Export());

            case "DOCX": return(new FastReport.Export.OoXML.Word2007Export());

            case "BMP":
            case "JPG":
            case "JPEG":
            case "PNG":
            case "TIFF":
            {
                FastReport.Export.Image.ImageExport image_export = new FastReport.Export.Image.ImageExport();
                switch (form.format)
                {
                case "BMP":  image_export.ImageFormat = FastReport.Export.Image.ImageExportFormat.Bmp; break;

                case "JPG":
                case "JPEG": image_export.ImageFormat = FastReport.Export.Image.ImageExportFormat.Jpeg; break;

                case "PNG":  image_export.ImageFormat = FastReport.Export.Image.ImageExportFormat.Png; break;

                case "TIFF": image_export.ImageFormat = FastReport.Export.Image.ImageExportFormat.Tiff; break;

                default: image_export.ImageFormat = FastReport.Export.Image.ImageExportFormat.Jpeg; break;
                }
                return((ExportBase)image_export);
            }

            default: return(new FastReport.Export.Pdf.PDFExport());
            }
        }
Exemple #6
0
        private string ExportToJpg()
        {
            DirectoryInfo dir = new DirectoryInfo(@"C:\EmailJPG");

            if (!dir.Exists)
            {
                dir.Create();
            }

            Random rnd = new Random();

            rnd.Next(10000);
            string   fileName = dir + "\\tmpMail" + rnd.Next(10000).ToString().PadLeft(4, '0') + ".Jpg";
            FileInfo fi       = new FileInfo(fileName);
            Stream   sr       = fi.Create();

            FastReport.Export.Image.ImageExport imgExp = new FastReport.Export.Image.ImageExport();
            imgExp.Export(previewControl1.Report, sr);

            sr.Close();
            return(fileName);
        }
Exemple #7
0
        public static Stream GetReportStream(string reportFilePath, string dataSetName, DataSet data, string exportFormat)
        {
            FastReport.Report report = new FastReport.Report();
            MemoryStream      result = new MemoryStream();

            if (FileHelper.IsExistFile(reportFilePath))
            {
                try
                {
                    report.Load(reportFilePath);            // Download the report
                    report.RegisterData(data, dataSetName); // Register data in the report
                }
                catch
                {
                    //var log = LogFactory.GetLogger("FastReportHelper");
                    return(result);
                }
                using (MemoryStream stream = new MemoryStream())
                {
                    if (exportFormat.Equals("pdf", StringComparison.InvariantCultureIgnoreCase))
                    {
                        //FastReport.Export.Pdf.PDFExport pdf = new FastReport.Export.Pdf.PDFExport();
                        //report.Export(pdf, stream);
                    }
                    else if (exportFormat.Equals("Jpeg", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FastReport.Export.Image.ImageExport image = new FastReport.Export.Image.ImageExport();
                        image.ImageFormat = FastReport.Export.Image.ImageExportFormat.Jpeg;
                        report.Export(image, stream);
                    }
                    else if (exportFormat.Equals("Bmp", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FastReport.Export.Image.ImageExport image = new FastReport.Export.Image.ImageExport();
                        image.ImageFormat = FastReport.Export.Image.ImageExportFormat.Bmp;
                        report.Export(image, stream);
                    }
                    else if (exportFormat.Equals("Gif", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FastReport.Export.Image.ImageExport image = new FastReport.Export.Image.ImageExport();
                        image.ImageFormat = FastReport.Export.Image.ImageExportFormat.Gif;
                        report.Export(image, stream);
                    }
                    else if (exportFormat.Equals("Png", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FastReport.Export.Image.ImageExport image = new FastReport.Export.Image.ImageExport();
                        image.ImageFormat = FastReport.Export.Image.ImageExportFormat.Png;
                        report.Export(image, stream);
                    }
                    else if (exportFormat.Equals("Tiff", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FastReport.Export.Image.ImageExport image = new FastReport.Export.Image.ImageExport
                        {
                            ImageFormat = FastReport.Export.Image.ImageExportFormat.Tiff
                        };
                        report.Export(image, stream);
                    }
                    result = stream;
                }
            }
            else
            {
                //var log = LogFactory.GetLogger("FastReportHelper");
                //log.Error(reportFilePath + ",目录不存在!");
            }
            return(result);
        }
Exemple #8
0
        public static string GetReportString(string reportFilePath, string dataSetName, IEnumerable <object> data, string exportFormat)
        {
            FastReport.Report report = new FastReport.Report();
            string            result = string.Empty;

            if (FileHelper.IsExistFile(reportFilePath))
            {
                try
                {
                    report.Load(reportFilePath);            // Download the report
                    report.RegisterData(data, dataSetName); // Register data in the report
                }
                catch
                {
                    //var log = LogFactory.GetLogger("FastReportHelper");
                    //log.Error(ex.Message);
                    return(result);
                }
                using (MemoryStream stream = new MemoryStream())
                {
                    if (exportFormat.Equals("pdf", StringComparison.InvariantCultureIgnoreCase))
                    {
                        //FastReport.Export.Pdf.PDFExport pdf = new FastReport.Export.Pdf.PDFExport {
                        //    Producer = "",
                        //    AllowPrint=true,
                        //    AllowModify=true,
                        //    PrintScaling=true,

                        //    RichTextQuality=100,
                        //    Compressed=false
                        //};
                        //report.Export(pdf, stream);

                        //FileHelper.CreateFile("\\log\\PDF" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".jpg", stream.ToArray());
                    }
                    else if (exportFormat.Equals("Jpeg", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FastReport.Export.Image.ImageExport image = new FastReport.Export.Image.ImageExport
                        {
                            ImageFormat   = FastReport.Export.Image.ImageExportFormat.Jpeg,
                            SeparateFiles = false,
                            JpegQuality   = 100
                        };
                        report.Prepare();
                        report.Export(image, stream);
                        FileHelper.CreateFile("\\log\\JPG" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".jpg", stream.ToArray());

                        //foreach (var item in image.GeneratedFiles)
                        //{
                        //    var temp = item;
                        //    var log = LogFactory.GetLogger("FastReportHelper");
                        //    log.Info(temp);
                        //}
                        //return report.SaveToStringBase64();
                    }
                    else if (exportFormat.Equals("Bmp", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FastReport.Export.Image.ImageExport image = new FastReport.Export.Image.ImageExport
                        {
                            ImageFormat = FastReport.Export.Image.ImageExportFormat.Bmp
                        };
                        report.Prepare();
                        report.Export(image, stream);
                    }
                    else if (exportFormat.Equals("Gif", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FastReport.Export.Image.ImageExport image = new FastReport.Export.Image.ImageExport
                        {
                            ImageFormat = FastReport.Export.Image.ImageExportFormat.Gif
                        };
                        report.Prepare();
                        report.Export(image, stream);
                    }
                    else if (exportFormat.Equals("Png", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FastReport.Export.Image.ImageExport image = new FastReport.Export.Image.ImageExport
                        {
                            ImageFormat   = FastReport.Export.Image.ImageExportFormat.Png,
                            SeparateFiles = false
                        };
                        report.Prepare();
                        report.Export(image, stream);
                    }
                    else if (exportFormat.Equals("Tiff", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FastReport.Export.Image.ImageExport image = new FastReport.Export.Image.ImageExport
                        {
                            ImageFormat = FastReport.Export.Image.ImageExportFormat.Tiff
                        };
                        report.Prepare();
                        report.Export(image, stream);
                    }
                    else if (exportFormat.Equals("html", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FastReport.Export.Html.HTMLExport image = new FastReport.Export.Html.HTMLExport
                        {
                            EnableMargins = false,
                            Pictures      = true,
                            EmbedPictures = true,
                            ImageFormat   = ImageFormat.Png
                        };
                        report.Prepare();
                        report.Export(image, stream);
                        return(System.Text.Encoding.UTF8.GetString(stream.ToArray()));
                    }


                    result = Convert.ToBase64String(stream.ToArray());
                }
            }
            else
            {
                //var log = LogFactory.GetLogger("FastReportHelper");
                //log.Error(reportFilePath + ",目录不存在!");
            }
            return(result);
        }