Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Won't work inside Linux docker container #6

Open
skivsoft opened this issue Jan 25, 2019 · 5 comments
Open

Won't work inside Linux docker container #6

skivsoft opened this issue Jan 25, 2019 · 5 comments

Comments

@skivsoft
Copy link

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"]
@NickMckloski
Copy link

Has this been addressed yet? I am trying to run this in a Linux container as well and am hitting the same issue.

@ststeiger
Copy link
Owner

@NickMckloski: No, currently busy working overtime until 21 o'clock, doesn't leave much space for other things. But you have the source, grep for user32.dll, and you'll see where it's used.

@NickMckloski
Copy link

@ststeiger I actually realized that I should have been using PdfSharpCore and it works great inside my linux containers and also on my local windows dev machine. Thanks for your work man!

@Siddharthagrahari978
Copy link

Siddharthagrahari978 commented Jun 28, 2021

Did anyone find a solution for this problem?

@ieosahon
Copy link

@ststeiger I actually realized that I should have been using PdfSharpCore and it works great inside my linux containers and also on my local windows dev machine. Thanks for your work man!

@ststeiger , apart from using PdfSharpCore, is there any other thing you did? I am using .net 7, and I am unable to generate pdf in a docker environment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants