jsreport / jsreport-dotnet

jsreport .NET sdk home repository
https://jsreport.net
MIT License
63 stars 10 forks source link

Critical error while generating pdf using jsreport #33

Closed explorer855 closed 5 years ago

explorer855 commented 5 years ago

Hi,

I ran into below issues while trying to generate htmlTopdf using jsreport binaries, please refer below logs.

Exception Caught

instance has been daemonized and initialized successfully (pid: 68)A critical error occurred while trying to execute the render command: Recipe 'phantom-pdf' not found. If this is a custom recipe make sure it's properly installed from npm. (1). caused by error (1) -> meta = {"remoteStack":"Error: Recipe 'phantom-pdf' not found. If this is a custom recipe make sure it's properly installed from npm.\n at module.exports (jsreportRuntime.js:159026:13)\n at Reporter.createError (jsreportRuntime.js:157718:12)\n at invokeRender (jsreportRuntime.js:157282:20)\n at "}, stack = Error: at responseToBuffer ([eval]:72595:29) at concat ([eval]:72648:40) at ConcatStream. ([eval]:17182:43) at emitNone (events.js:111:20) at ConcatStream.emit (events.js:208:7) at finishMaybe ([eval]:97353:14) at afterWrite ([eval]:97215:3) at _combinedTickCallback (internal/process/next_tick.js:144:20) at process._tickCallback (internal/process/next_tick.js:180:9)

Code Block

        try
        {
            var rs = new LocalReporting()
                .UseBinary(jsreport.Binary.Linux.JsReportBinary.GetBinary())
                .Configure((cfg) => {
                    // explicitly set port, because azure web app sets environment variable PORT
                    // which is used also by jsreport
                    cfg.HttpPort = 1000;
                    return cfg;
                })
                .AsUtility()
                .Create();

            var report = await rs.RenderAsync(new RenderRequest()
            {
                Template = new Template()
                {
                    Recipe = Recipe.PhantomPdf,
                    Engine = Engine.None,
                    Content = tmplContent,
                    Phantom = new Phantom
                    {
                        Header = headerTmpl,
                        Footer = footerTmpl,
                        Orientation = PhantomOrientation.Portrait,
                        Format = PhantomFormat.A4,
                        HeaderHeight = headerHeight,
                        FooterHeight = footerHeight
                    }
                },
                Data = varContent
            });
        }
        catch(Exception ex) { throw; }

I'm using Docker Linux Containers with asp.net core below is the dockerfile,

FROM mcr.microsoft.com/dotnet/core/aspnet:2.2.3-stretch-slim AS base RUN apt-get update && \
apt-get install -y gnupg libgconf-2-4 wget && \ wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \ sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' && \ apt-get update && \ apt-get install -y google-chrome-unstable --no-install-recommends

ENV chrome:launchOptions:args --no-sandbox

WORKDIR /app

FROM microsoft/dotnet:2.2-sdk AS build WORKDIR /src COPY . . WORKDIR /src/pdfoncontainer RUN dotnet restore -nowarn:msb3202,nu1503 RUN dotnet build --no-restore -c Release -o /app

FROM build AS publish RUN dotnet publish --no-restore -c Release -o /app

FROM base AS final WORKDIR /app COPY --from=publish /app . ENTRYPOINT ["dotnet", "pdfoncontainer.dll"]

explorer855 commented 5 years ago

For your information, I was able to generate using "Recipe.ChromePdf", any suggestions appreciated.

Edit:-

After generating pdf from html file using ChromePdf recipe all the styles are gone. Pls comment on it.

pofider commented 5 years ago

Only the default jsreport extensions are included in the jsreport.Binary. If you for some reason need a custom extension, check the documentation for the instructions https://jsreport.net/learn/dotnet-local#custom-extensions