Skip to content

Won't work inside Linux docker containerΒ #6

@skivsoft

Description

@skivsoft

It seems some winapi dependencies still in place.

Unhandled Exception: System.DllNotFoundException: Unable to load shared library 'user32.dll' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libuser32.dll: cannot open shared object file: No such file or directory
at PdfSharp.Internal.NativeMethods.GetDC(IntPtr hwnd)

Program.cs

using System.Text;
using PdfSharp.Drawing;
using PdfSharp.Pdf;

namespace PdfSharpApp
{
    class HelloWorld
    {
        static void Main(string[] args)
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            PdfDocument document = new PdfDocument();
            PdfPage page = document.AddPage();
            XGraphics gfx = XGraphics.FromPdfPage(page);
            XFont font = new XFont("Verdana", 20, XFontStyle.BoldItalic);
            gfx.DrawString("Hello, World!", font, XBrushes.Black, new XRect(0, 0, page.Width, page.Height), XStringFormats.Center);
            const string filename = "HelloWorld.pdf";
            document.Save(filename);
        }
    }
}

Dockerfile

FROM microsoft/dotnet:2.2-aspnetcore-runtime

# install System.Drawing native dependencies
RUN apt-get update \
    && apt-get install -y --allow-unauthenticated \
        libc6-dev \
        libgdiplus \
     && rm -rf /var/lib/apt/lists/*

# make links to libdl.so and libgdiplus.so
RUN ln -s /lib/x86_64-linux-gnu/libdl.so.2 /lib/x86_64-linux-gnu/libdl.so
RUN ln -s /usr/lib/libgdiplus.so /lib/x86_64-linux-gnu/libgdiplus.so

ARG source
WORKDIR /app
COPY ${source:-bin/Debug/netcoreapp2.2/publish} .
ENTRYPOINT ["dotnet", "PdfSharpApp.dll"]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions