public void ReportExport() { DeleteTempFiles(); exp.ImageFormat = ImageExportFormat.Png; //Устанавливаем для изображения формат png exp.Export(Report, Directory.GetCurrentDirectory() + "/" + System.Guid.NewGuid() + ".png"); //Выполняем экспорт отчета в файл foreach (string fileName in exp.GeneratedFiles) { using (var img = File.OpenRead(fileName)) { pages.Add(Image.FromStream(img)); } } CurrentPage = 0; }
private static PrintDocument PrepareDoc(this Report report, PrinterSettings settings = null) { if (report.PreparedPages.Count < 1) { report.Prepare(); if (report.PreparedPages.Count < 1) { return(null); } } var page = 0; var exp = new ImageExport { ImageFormat = ImageExportFormat.Png, Resolution = 600 }; var doc = new PrintDocument { DocumentName = report.Name }; if (settings != null) { doc.PrinterSettings = settings; } // Ajustando o tamanho da pagina doc.QueryPageSettings += (sender, args) => { var rPage = report.PreparedPages.GetPage(page); args.PageSettings.Landscape = rPage.Landscape; args.PageSettings.Margins = new Margins((int)(scaleFactor * rPage.LeftMargin * Units.HundrethsOfInch), (int)(scaleFactor * rPage.RightMargin * Units.HundrethsOfInch), (int)(scaleFactor * rPage.TopMargin * Units.HundrethsOfInch), (int)(scaleFactor * rPage.BottomMargin * Units.HundrethsOfInch)); args.PageSettings.PaperSize = new PaperSize("Custom", (int)(ExportUtils.GetPageWidth(rPage) * scaleFactor * Units.HundrethsOfInch), (int)(ExportUtils.GetPageHeight(rPage) * scaleFactor * Units.HundrethsOfInch)); }; doc.PrintPage += (sender, args) => { using (var ms = new MemoryStream()) { exp.PageRange = PageRange.PageNumbers; exp.PageNumbers = $"{page + 1}"; exp.Export(report, ms); args.Graphics.DrawImage(Image.FromStream(ms), args.PageBounds); } page++; args.HasMorePages = page < report.PreparedPages.Count; }; doc.EndPrint += (sender, args) => page = 0; doc.Disposed += (sender, args) => exp?.Dispose(); return(doc); }
public void Export(string fileName) { if (!IsPrepared) { return; } _export.ImageFormat = ImageExportFormat.Png; _export.Resolution = 300; _export.SeparateFiles = true; _export.Export(_report, fileName); }