FastReport Exporting to html

https://fastreports.github.io/FastReport.Documentation/Exporting.html

FastReport Open Source can save documents in HTML, BMP, PNG, JPEG, GIF, TIFF, EMF.

The following is an example of exporting a report in Jpeg file.

复制代码
using FastReport;
using FastReport.Utils;
using FastReport.Export.Image;
            ...
            // Create new Report 
            Report report = new Report();
            // Load report from file
            report.Load("report.frx");
            // Set the parameter
            report.SetParameterValue("MYPARAMETER", 1024);
            // Prepare the report
            report.Prepare();
            // Export in Jpeg
            ImageExport image = new ImageExport();
            image.ImageFormat = ImageExportFormat.Jpeg;
            // Set up the quality
            image.JpegQuality = 90;
            // Decrease a resolution
            image.Resolution = 72;
            // We need all pages in one big single file
            image.SeparateFiles = false;
            report.Export(image, "report.jpg");
复制代码

The following is an example of exporting a report in PNG file.

1  // Export in PNG
2             ImageExport image = new ImageExport();
3             image.ImageFormat = ImageExportFormat.Png;
4             // Increase a resolution
5             image.Resolution = 300;
6             // We need separate file for each report page, they will be numbered: report.png, report.2.png, report.3.png, etc.
7             image.SeparateFiles = true;
8             report.Export(image, "report.png");

The following is an example of exporting a report in HTML file.

复制代码
 1 using FastReport;
 2 using FastReport.Utils;
 3 using FastReport.Export.Html;
 4             ...
 5             // Export in HTML
 6             HTMLExport html = new HTMLExport();
 7             // We need embedded pictures inside html
 8             html.EmbedPictures = true;
 9             // Enable all report pages in one html file
10             html.SinglePage = true;
11             // We don't need a subfolder for pictures and additional files
12             html.SubFolder = false;
13             // Enable layered HTML
14             html.Layers = true;
15             // Turn off the toolbar with navigation
16             html.Navigator = false;
17             // Save the report in html
18             report.Export(html, "report.html");
View Code
复制代码

The following is an example of exporting a report in multiple streams.

复制代码
 1 // Creatint the Report object
 2             using (Report report = new Report())
 3             {
 4                 // Loading a report
 5                 report.Load("report.frx");
 6                 // Preparing a report
 7                 report.Prepare();
 8 
 9                 // Creating the HTML export
10                 using (HTMLExport html = new HTMLExport())
11                 {
12                     // Choose the Jpeg pictures
13                     html.ImageFormat = ImageFormat.Jpeg;
14                     // We need the saving in multiple streams
15                     html.SaveStreams = true;
16                     // Exporting with fake null stream object, html export will keep all files inside
17                     report.Export(html, (Stream)null);
18                     // Checking for the exporting
19                     if (html.GeneratedFiles.Count > 0)
20                     {
21                         // Loop for generated files 
22                         for (int i = 0; i < html.GeneratedFiles.Count; i++)
23                         {
24                             // We have several streams, let's save it in files
25                             using (FileStream file = new FileStream("export_path/" + html.GeneratedFiles[i], FileMode.Create))
26                             {
27                                 // You need reset the internal stream position
28                                 html.GeneratedStreams[i].Position = 0;
29                                 // Saving a stream in the file
30                                 html.GeneratedStreams[i].CopyTo(file);
31                             }                             
32                         }
33                     }
34                 }
35             }
View Code
复制代码

 

posted @   dear6  阅读(49)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· C#/.NET/.NET Core技术前沿周刊 | 第 29 期(2025年3.1-3.9)
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
点击右上角即可分享
微信分享提示