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 Jan 13, 2025 11:58 am

Hello,

I have tested the demo provided in the sample section for HTML to PDF conversion with the QT plugin, but unfortunately, it is not working. Could you please confirm if Spire.PDF is compatible with Linux Docker containers?

e-iceblue.com/Tutorials/Spire.PDF/Spire.PDF-Program-Guide/Convert-HTML-to-PDF-Customize-HTML-to-PDF-Conversion-by-Yourself.html

For your reference, I have attached a basic sample project to illustrate the issue.

drive.google.com/file/d/11Gu-Q2ietk2AVF94mN3onXcXClmtnuGi/view?usp=sharing

Thank you for your assistance!

Best regards,
Daniel

bogdandanielb
 
Posts: 4
Joined: Mon Jan 13, 2025 7:57 am

Tue Jan 14, 2025 3:21 am

Hello,

Thanks for your letter.
1.The Qt plugin used third-party HtmlConverter.QT, which has some dependencies for system. For the Docker environment on Linux (without UI), first, please make sure that all files in the plugin folder have been granted the highest execution permissions. Also, try to install Xvfb and use the command (xvfb-run dotnet HtmlToPdf ) to run it. Additionally, navigate to the Qt plugin folder and use (echo "<p>test text</p>" | xvfb-run ./Html2Pdf "" "output.pdf" 800 600 0 0 0 0 1) to check if any dependencies are missing. If so, you need to install the missing dependencies before proceeding with further testing.

2.Our latest version(Spire.PDF Pack(Hot Fix) Version:11.1.0) currently supports using ChromeHtmlConverter to convert, you also can refer to the guidance for testing.

If you have any other questions, just feel free to write back.

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1371
Joined: Wed Apr 25, 2018 3:20 am

Tue Jan 14, 2025 11:53 am

This is the Dockerfile after adding the missing libraries found by running xvfb:

Code: Select all
# See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.

# This stage is used when running from VS in fast mode (Default for Debug configuration)
FROM mcr.microsoft.com/dotnet/runtime:8.0 AS base

# Spire.PDF dependencies
RUN apt-get update \
    && apt-get install -y --no-install-recommends \
   # libfontconfig1 \
    libgdiplus \
    xvfb \
    x11-utils \
    xfonts-base \
    xfonts-75dpi \
    xauth \
    curl \
    libnss3-dev \
    libasound2 \
    libegl1 \
    && rm -rf /var/lib/apt/lists/*

# https://github.com/dotnet/dotnet-docker/discussions/4938#discussioncomment-7892892
RUN ln -s /usr/lib/x86_64-linux-gnu/libdl.so.2 /usr/lib/x86_64-linux-gnu/libdl.so


USER $APP_UID
WORKDIR /app


# This stage is used to build the service project
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["ConsoleAppSpirePDF.csproj", "."]
RUN dotnet restore "./ConsoleAppSpirePDF.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "./ConsoleAppSpirePDF.csproj" -c $BUILD_CONFIGURATION -o /app/build

# This stage is used to publish the service project to be copied to the final stage
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./ConsoleAppSpirePDF.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

# This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration)
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "ConsoleAppSpirePDF.dll"]


The output from Html2Pdf is now:

Code: Select all
$ cd /app/plugins && echo "<p>test text</p>" | xvfb-run ./Html2Pdf "" "output.pdf" 800 600 0 0 0 0 1
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-app'
process 130: D-Bus library appears to be incorrectly set up; failed to read machine uuid: Failed to open "/etc/machine-id": No such file or directory
See the manual page for dbus-uuidgen to correct this issue.


Could you please run the attached project on your side and provide a working Dockerfile? I believe this would greatly benefit everyone attempting to use Spire.PDF in a Docker container.

Including this information in the official documentation would be even more helpful and appreciated.

Thank you for your support!

Best regards,
Daniel

bogdandanielb
 
Posts: 4
Joined: Mon Jan 13, 2025 7:57 am

Tue Jan 14, 2025 12:07 pm

Code: Select all
# See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.

# This stage is used when running from VS in fast mode (Default for Debug configuration)
FROM mcr.microsoft.com/dotnet/runtime:8.0 AS base

# Spire.PDF dependencies
RUN apt-get update \
    && apt-get install -y --no-install-recommends \
   # libfontconfig1 \
    libgdiplus \
    xvfb \
    x11-utils \
    xfonts-base \
    xfonts-75dpi \
    xauth \
    curl \
    libnss3-dev \
    libasound2 \
    libegl1 \
    dbus \
    && rm -rf /var/lib/apt/lists/*

RUN dbus-uuidgen > /etc/machine-id

# https://github.com/dotnet/dotnet-docker/discussions/4938#discussioncomment-7892892
RUN ln -s /usr/lib/x86_64-linux-gnu/libdl.so.2 /usr/lib/x86_64-linux-gnu/libdl.so

ENV XDG_RUNTIME_DIR=/tmp/runtime-app
RUN mkdir -p /tmp/runtime-app && \
    chown 1654:1654 /tmp/runtime-app && \
    chmod 700 /tmp/runtime-app


USER $APP_UID
WORKDIR /app


# This stage is used to build the service project
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["ConsoleAppSpirePDF.csproj", "."]
RUN dotnet restore "./ConsoleAppSpirePDF.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "./ConsoleAppSpirePDF.csproj" -c $BUILD_CONFIGURATION -o /app/build

# This stage is used to publish the service project to be copied to the final stage
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./ConsoleAppSpirePDF.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

# This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration)
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "ConsoleAppSpirePDF.dll"]


It seems to be hanging now:

Code: Select all
$ cd /app/plugins && echo "<p>test text</p>" | xvfb-run ./Html2Pdf "" "output.pdf" 800 600 0 0 0 0 1


Thanks!

bogdandanielb
 
Posts: 4
Joined: Mon Jan 13, 2025 7:57 am

Wed Jan 15, 2025 10:16 am

Hello,

Thank you for your feedback. As the QT plugin is highly related to the underlying system environment. In our previous tests, we also found that some special environments did not generate result document, which is due to the lack of some dependencies. The ChromeHtmlConverter method will be our main usage method in the future. I will provide you with a project using ChromeHtmlConverter.

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1371
Joined: Wed Apr 25, 2018 3:20 am

Fri Jan 17, 2025 3:46 am

Hello,

Thank you for your patience.
Please download the project to convert HTML to PDF using "ChromeHtmlConverter" from the following link.
https://www.e-iceblue.com/downloads/demo/Html2PDFWithChromeHtmlConverter.zip
Installing Google Chrome step may take some time, please be patient and wait for the installation to complete. If you have any other questions during testing, please feel free to contact us.

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1371
Joined: Wed Apr 25, 2018 3:20 am

Return to Spire.PDF