Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Mon Dec 04, 2023 1:54 pm

Hello. I am trying to convert html string to pdf inside linux docker container.
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

TetianaSh
 
Posts: 2
Joined: Mon Sep 04, 2023 7:06 am

Tue Dec 05, 2023 7:52 am

Hello,

Thanks for your inquiry.
Based on the information provided, I have created a project and performed initial testing on a regular Debian system. However, I was unable to replicate the issue you mentioned. As I don't currently have a ready-made "Debian GNU/Linux 11 (bullseye)" system, I need to set up this environment. However, it is not fully set up yet, so I haven't obtained test results in an environment identical to yours. Rest assured, as soon as I have the test results in the corresponding environment, I will promptly provide you with feedback.
Additionally, I recommend checking the permissions of the plugin. It is advisable to set it to "777" by using the following code: "chmod -R 775 plugins". After adjusting the permissions, please perform the test again.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Tue Dec 05, 2023 8:19 am

Unfortunately, it did not help.

TetianaSh
 
Posts: 2
Joined: Mon Sep 04, 2023 7:06 am

Tue Dec 05, 2023 10:28 am

Hello,

Thank you for your feedback.
I apologize for the inconvenience, but I haven't been able to successfully conduct the test in the "Debian GNU/Linux 11 (bullseye)" environment yet. I will notify you promptly once I have the test results. Thank you for your understanding and support.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Mon Dec 11, 2023 9:58 am

Hello,

Thank you for your patience.
After conducting a thorough investigation and testing, I have made modifications to the Dockerfile you provided. I am pleased to inform you that it has been successfully tested in a Docker environment.
I have attached the testing project for your convenience. It includes the modified Dockerfile as well as a README.txt file outlining the testing steps. Kindly download the files and proceed with the testing on your end.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.PDF