今天的文章中,我们来看一个教你如何在Linux上使用FastReport Core的例子。
今天的文章中,我们来看一个教你如何在Linux上使用FastReport Core的例子。
首先对于Linux,我们将需要额外的库,默认情况下可能并没有安装:
- Libgdiplus;
- libx11-dev。
在服务器端Linux操作系统上通常没有安装XServer,而这是处理FastReport Core图形所必需的。所以我们必须安装它。你可以选择Xvfb、VcXsrv或任何其他服务。
我们待会儿再来讲XServer的问题,现在,我们先创建一个ASP.Net Core应用程序:

选择Web应用程序:

通过NuGet将FastReport Core添加到项目中。


设置对本地存储库或文件夹Service FastReport.2017.4.0-release.nupkg的引用:

从下拉列表中选择软件包的本地源并安装FastReport软件包。
从“Controllers”文件夹中打开“HomeController.cs”文件。我们添加几个额外的库到使用部分:
using FastReport;using FastReport.Export.Html;using System.IO;using System.Text;
public IActionResult Index() { Report report = new Report(); string report_path = ”Reports”; System.Data.DataSet dataSet = new System.Data.DataSet(); dataSet.ReadXml(report_path + "nwind.xml"); report.Report.RegisterData(dataSet, "NorthWind"); report.Report.Load(Path.Combine(report_path, "Simple List.frx")); report.Prepare(); HTMLExport export = new HTMLExport(); export.Layers = true; using (MemoryStream ms = new MemoryStream()) { export.EmbedPictures = true; export.Export(report, ms); ms.Flush(); ViewData["Report"] = Encoding.UTF8.GetString(ms.ToArray()); ViewData["ReportName"] = "Simple List.frx"; } return View();
由于WebReport对象在FastReport Core中暂时不可用,因此我们使用常规 表对象。创建一个数据源并将其注册到 表对象中。加载 表模板。使用 Prepare ()
方法准备 表。接下来,我们在HTML中创建已完成的 表的导出。我们导出为MemoryStream流(或文件)。然后,我们使用ViewData或ViewBag将 表传递给视图。
这非常简单 – 我们以HTML格式显示 表:
@{ ViewData["Title"] = "Home Page";}@if (ViewData.ContainsKey("Report")){ @Html.Raw(ViewData["Report"])}
如前所述,FRCore需要XServer,而服务器端Linux并不提供。
我们来看一个使用debian服务器配置Linux示例:
1.打开控制台;
2.更新apt-get并安装软件包:
- sudo apt-get update;
- sudo apt-get install -y xvfb x11vnc x11-xkb-utils xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic x11-apps libgdiplus libx11-dev;
3.更改环境变量,DISPLAY =: 99
。
我们在Program类中添加了两个方法。LinuxStart方法检查是否正在运行,如果是XServer,如果是的话则关闭它并创建一个新的。
StopLinux方法仅停止虚拟服务器。
public class Program { static Process xvfb; const string xvfb_pid = "pid.xvfb.fr"; public static void Main(string[] args) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) LinuxStart(); BuildWebHost(args).Run(); if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) LinuxStop(); } private static void LinuxStop() { xvfb.Kill(); if (File.Exists(xvfb_pid)) File.Delete(xvfb_pid); } public static void LinuxStart() { if (File.Exists(xvfb_pid)) { string pid = File.ReadAllText(xvfb_pid); try { xvfb = Process.GetProcessById(int.Parse(pid)); xvfb.Kill(); xvfb = null; } catch { } File.Delete(xvfb_pid); } string display = Environment.GetEnvironmentVariable("DISPLAY"); if (String.IsNullOrEmpty(display)) { Environment.SetEnvironmentVariable("DISPLAY", ":99"); display = ":99"; } ProcessStartInfo info = new ProcessStartInfo(); info.FileName = "/usr/bin/Xvfb"; info.Arguments = display + " -ac -screen 0 1024x768x16 +extension RANDR -dpi 96"; info.CreateNoWindow = true; xvfb = new Process(); xvfb.StartInfo = info; xvfb.Start(); File.WriteAllText(xvfb_pid, xvfb.Id.ToString()); } public static IWebHost BuildWebHost(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup<Startup>() .UseUrls("http://[::]:5000") .Build(); }
应用程序已准备就绪。运行查看效果:

总结一下,我们可以得出结论,和Windows一样,在Linux上运行FastReport Core非常简单。只不过需要一些操作系统的高级设置才能使用.Net Core。
产品介绍 | 下载试用 | 优惠活动 | 在线客服 | 联系Elyn
推荐阅读
- FastReport VCL 表控件开发者手册
- FastReport Online Designer中文手册
- Fastreport.Net教程2016
- Fastreport.Net用户手册
- FastReport.Net教程2017(持续更新中···)
- FastReport Online Designer教程2017(持续更新中···)
- 表教程2017(持续更新中···)
- FastReport.Net v2018.1版本更新已经发布!

标签: 表专家 表解决方案 表.NETUnix/Linux 表控件 表设计 表引擎
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!