Using GemBox.Spreadsheet, requested Excel files are rendered beautifully as PDFs on my Windows 11 (IIS Express) development machine; however, requesting the same PDFs from a Ubuntu/Docker/NGINX web server results in an HTTP 500 error.
The following C# snippet returns a byte array to a calling method which, subsequently, returns the byte array as a FileContentResult to a web client:
private byte[] FileToByteArray(string fileName)
{
// The following uses GemBox.Spreadsheet to convert from Excel spreadsheet to PDF.
SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");
// 1. Load XLS or XLSX file into ExcelFile object.
ExcelFile workbook = ExcelFile.Load(fileName + ".xlsx");
// 2. Iterate each worksheet in the selected workbook to fit each worksheet to a single printable page width.
foreach (var worksheet in workbook.Worksheets)
{
worksheet.PrintOptions.FitWorksheetWidthToPages = 1;
//worksheet.PrintOptions.FitWorksheetHeightToPages = 1;
}
// 3. Save ExcelFile object to PDF file.
workbook.Save(fileName + ".pdf", new PdfSaveOptions() { SelectionType = GemBox.Spreadsheet.SelectionType.EntireFile });
// 4. Read the PDF file into a byte array.
byte[] bytes = System.IO.File.ReadAllBytes(fileName + ".pdf");
// 5. Delete the Excel source file from the web server.
System.IO.File.Delete(fileName + ".xlsx");
// 6. Delete the PDF file from the web server.
System.IO.File.Delete(fileName + ".pdf");
return bytes;
}
For reference, the following provides the current contents of my “Dockerfile” script:
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1.3 AS base
WORKDIR /app
#EXPOSE 80
#EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:3.1.201 AS build
WORKDIR /src
COPY . WebApplication/
RUN dotnet restore WebApplication/WebApplication.csproj
#COPY . .
WORKDIR /src/WebApplication
RUN dotnet build WebApplication.csproj -c Release -o /app
FROM build AS publish
RUN dotnet publish WebApplication.csproj -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
#ENTRYPOINT [“dotnet”, “WebApplication.dll”]
I am of the understanding GemBox.Spreadsheet is Linux-compatible. Unfortunately, I am not very knowledgeable with regard to either Docker containerization or the NGINX web server.
I inherited my current project from another developer and this is my first attempt at utilizing GemBox.Spreadsheet as a potential replacement for EPPlus. While I am very excited about GemBox.Spreadsheet and the ease with which I am able to create Excel worksheets, I need to be able to render PDFs from both IIS and NGINX web servers.
What am I missing here? Any assistance is greatly appreciated.