I installed:
sudo apt-get update
sudo apt-get install libc6-dev
sudo apt-get install libglib2.0-0
sudo apt-get install xvfb
- Code: Select all
var htmlTemplate = @"<strong>This is a test for converting HTML string to PDF </strong>
<ul><li>Spire.PDF supports to convert HTML in URL into PDF</li>
<li>Spire.PDF supports to convert HTML string into PDF</li>
<li>With the new plugin</li></ul>";
using var memoryStream = new MemoryStream();
string pluginPath = Path.Combine(Environment.CurrentDirectory, "plugins");
HtmlConverter.PluginPath = pluginPath;
HtmlConverter.Convert(htmlTemplate, memoryStream, true, 1000, new SizeF(595, 842), new PdfMargins(0),
Spire.Pdf.HtmlConverter.LoadHtmlType.SourceCode);
var b = memoryStream.ToArray();
Console.WriteLine(b.Length); // here b.Length always = 0
memoryStream.Seek(0, SeekOrigin.Begin);
using (FileStream fileStream = new FileStream(Path.Combine(Environment.CurrentDirectory, "testpdf.pdf"), FileMode.Create, FileAccess.Write))
{
memoryStream.CopyTo(fileStream);
}
Dockerfile:
- Code: Select all
FROM mcr.microsoft.com/dotnet/runtime:7.0 AS base
WORKDIR /app
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /src
COPY ["plugins-linux-x64.tar.gz", ""]
COPY ["ConsoleApp2.csproj", "ConsoleApp2/"]
RUN dotnet restore "ConsoleApp2/ConsoleApp2.csproj"
COPY . .
RUN dotnet build "ConsoleApp2.csproj" -c Release -o /app/build
RUN apt-get update \
&& apt-get install \
-y xvfb \
&& rm -rf /var/lib/apt/lists/*
FROM build AS publish
RUN xvfb-run dotnet publish "ConsoleApp2.csproj" -c Release -o /app/publish /p:UseAppHost=false
RUN tar -xvzf /src/plugins-linux-x64.tar.gz -C /app/publish
RUN apt-get update \
&& apt-get install -y --allow-unauthenticated \
libc6-dev \
libgdiplus \
libx11-dev \
&& rm -rf /var/lib/apt/lists/*
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "ConsoleApp2.dll"]
But anyway the pdf file is always empty and I always receive error:
Failed to load PDF document.
Os - Debian GNU/Linux 11 (bullseye)
dotnet version : 7