On windows the program work perfectly, but not on a linux docker.
I use that DLL : Syncfusion.EJ2.PdfViewer.AspNet.Core.Linux
.net core 5.02
I gave write access in my docker to be sure.
And i always get that error 'Syncfusion.EJ2.PdfViewer.PdfiumNative' on that line : jsonResult = pdfviewer.Load(stream, jsonData);
Here is my docker file :
FROM mcr.microsoft.com/dotnet/aspnet:5.0-buster-slim AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim AS build
WORKDIR /src
COPY ["ServerPdfViewer/ServerPdfViewer.csproj", "ServerPdfViewer/"]
RUN dotnet restore "ServerPdfViewer/ServerPdfViewer.csproj"
COPY . .
WORKDIR "/src/ServerPdfViewer"
RUN dotnet build "ServerPdfViewer.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "ServerPdfViewer.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
Here is my function
public IActionResult Load([FromBody] Dictionary<string, string> jsonData)
{
PdfRenderer pdfviewer = new PdfRenderer(_cache);
//PdfRenderer.ReferencePath = _hostingEnvironment.ContentRootPath;
MemoryStream stream = new MemoryStream();
object jsonResult = new object();
if (jsonData != null && jsonData.ContainsKey("document"))
{
if (bool.Parse(jsonData["isFileName"]))
{
string documentPath = GetDocumentPath(jsonData["document"]);
if (!string.IsNullOrEmpty(documentPath))
{
byte[] bytes = System.IO.File.ReadAllBytes(documentPath);
stream = new MemoryStream(bytes);
}
else
{
string fileName = jsonData["document"].Split(new string[] { "://" }, StringSplitOptions.None)[0];
if (fileName == "http" || fileName == "https")
{
try
{
WebClient WebClient = new WebClient();
byte[] pdfDoc = WebClient.DownloadData(jsonData["document"]);
stream = new MemoryStream(pdfDoc);
}
catch (Exception ex)
{
var a = ex;
}
}
else
{
return this.Content(jsonData["document"] + " is not found");
}
}
}
else
{
byte[] bytes = Convert.FromBase64String(jsonData["document"]);
stream = new MemoryStream(bytes);
}
}
try
{
jsonResult = pdfviewer.Load(stream, jsonData);
}
catch (Exception ex)
{
var a = ex;
}
return Content(JsonConvert.SerializeObject(jsonResult));
}
|
services.AddMemoryCache();
services.AddDistributedRedisCache(options =>
{
options.Configuration = Configuration.GetConnectionString("Redis");
}); |
|
PdfViewerController.cs
private IDistributedCache _cache;
public PdfViewerController(IHostingEnvironment hostingEnvironment, IDistributedCache cache)
{
_hostingEnvironment = hostingEnvironment;
_cache = cache;
} |
Hi there,
Evaluating PdfViewer for huge project.
We tried this solution but still facing the same issue when deployed to linux docker.
Here's our docker file. Let me know if I missed anything.
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env
WORKDIR /var/local/app
# setup directory structure to work with VS project references
RUN mkdir /var/local/app/API
RUN mkdir /var/local/app/Shared
# Copy csproj and restore as distinct layers
# hiding project specific
# Copy everything else and build
# hiding project specific
RUN dotnet publish -c Release --self-contained false -o /var/local/app/out/content
# Set the emty directory as a mount point for K8 secrets containing TLS Certs
RUN mkdir /var/local/app/out/content/security
###################################################
### Build the final container
### https://hub.docker.com/_/microsoft-dotnet-aspnet
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim
# https://www.syncfusion.com/forums/166222/pdf-viewers-service-is-throwing-an-exception-the-type-initializer-for-syncfusion-ej2
RUN ln -s /lib/x86_64-linux-gnu/libdl-2.24.so /lib/x86_64-linux-gnu/libdl.so
# install System.Drawing native dependencies https://www.syncfusion.com/forums/162767/sfpdfviewer-component-erreur-syncfusion-ej2-pdfviewer-pdfiumnative-threw-an-exception-on
RUN apt-get update && apt-get install -y --allow-unauthenticated libgdiplus libc6-dev libx11-dev xvfb libfontconfig wkhtmltopdf openssl libssl-dev
RUN ln -s libgdiplus.so gdiplus.dll
WORKDIR /var/local/app
COPY --from=build-env /var/local/app/out/content .
ENTRYPOINT ["dotnet", "5fkdjfctApi.dll"]
|
RUN ln -s /lib/x86_64-linux-gnu/libdl-2.24.so /lib/x86_64-linux-gnu/libdl.so
# install System.Drawing native dependencies
RUN apt-get update && apt-get install -y --allow-unauthenticated libgdiplus libc6-dev libx11-dev
RUN ln -s libgdiplus.so gdiplus.dll
|