我已经在Azure WebApp Linux上部署了现有的.Netcore 2.1 MVC。
我需要创建报告pdf,所以我想使用jsreport local。

var rs = new LocalReporting().UseBinary(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? JsReportBinary.GetBinary() : jsreport.Binary.Linux.JsReportBinary.GetBinary()).Configure((cfg) =>
    {
         cfg.HttpPort = 1000;
         cfg.AllowedLocalFilesAccess().BaseUrlAsWorkingDirectory();
         return cfg;
    }).AsUtility().Create();
var report = await rs.RenderAsync(new RenderRequest
    {
          Template = new Template
         {
              Recipe = Recipe.ChromePdf,
              Engine = Engine.None,
              Content = contentToPrint
          }
    });


在Windows上,此代码可以正常工作。部署到Web App(Linux)上后,出现错误:

错误的呈现报告失败:尝试执行render命令时发生严重错误:无法启动chrome!/tmp/jsreport/compile/jsreport-2.4.0-Bk_dhUp8V/chrome/chrome:加载共享库时出错:libX11.so .6:无法打开共享库文件:无此文件或目录故障排除:https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md(1)。由错误(1)-> meta = {“ remoteStack”:“错误引起的:错误:无法启动chrome!\ n / tmp / jsreport / compile / jsreport-2.4.0-Bk_dhUp8V / chrome / chrome:加载共享库时出错: libX11.so.6:无法打开共享的对象文件:没有这样的文件或目录\ n \ n \ n故障排除:onClose处的https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md \ n \ n(jsreportRuntime.js:400867:14)\ n在Interface.helper.addEventListener处(jsreportRuntime.js:400856:50)\ n在emitNone(events.js:111:20)\ n在Interface.emit(events.js:208:7)\ n在Interface.close(readline.js:370: 8)\ n在Socket.onend(readline.js:149:10)\ n在emitNone(events.js:111:20)\ n在Socket.emit(events.js:208:7)\ n在endReadableNT( _combinedTickCallback上的_stream_read.js:1064:12)\ n(process._tickCallback(internal / process / next_tick.js:180:9)“}上的_combinedTickCallback(internal / process / next_tick.js:138:11)\ n :在ConcatStream的concat([eval]:72648:40)的responseToBuffer([eval]:72595:29)处。 ([eval]:17182:43)在containStream上的ConcatStream.emit(events.js:208:7)在emitNone(events.js:111:20)在afterWrite([eval] :97215:3)在process._tickCallback(内部/process/next_tick.js:180:9)_combinedTickCallback(内部/进程/next_tick.js:144:20)

最佳答案

无头Chrome需要其他一些共享库,这些库在默认的Azure Web应用程序Linux环境中不存在。但是,您可以使用基于docker的azure Web应用程序并安装这些必需的库。

RUN apt-get update && \
    apt-get install -y gnupg  libgconf-2-4 wget && \
    wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \
    sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' && \
    apt-get update && \
    apt-get install -y google-chrome-unstable --no-install-recommends

ENV chrome:launchOptions:args --no-sandbox


请参阅说明文件
https://jsreport.net/learn/dotnet-local#docker
https://jsreport.net/learn/dotnet-local#azure-web-apps

和例子
https://github.com/jsreport/jsreport-dotnet-example-docker

关于javascript - 无法在Azure Web App Linux(.Net Core 2.1 MVC)上本地运行jsreport,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55558395/

10-11 12:22