ststeiger / PdfSharpNetStandard

PdfSharp 1.5 ported to NetStandard 2.0
https://github.com/empira/PDFsharp/
MIT License
33 stars 11 forks source link

Won't work inside Linux docker container #6

Open skivsoft opened 5 years ago

skivsoft commented 5 years ago

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 commented 5 years ago

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

ststeiger commented 5 years ago

@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 commented 5 years ago

@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 commented 3 years ago

Did anyone find a solution for this problem?

ieosahon commented 8 months ago

@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