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

docker aspnet:6.0-alpine image not rendered in pdf file #89

Open
stefanodesimone opened this issue Sep 21, 2022 · 8 comments
Open

docker aspnet:6.0-alpine image not rendered in pdf file #89

stefanodesimone opened this issue Sep 21, 2022 · 8 comments

Comments

@stefanodesimone
Copy link

Hi all,
in this thread https://github.com/HakanL/WkHtmlToPdf-DotNet/issues/88 we can create pdf using aspnet:6.0-alpine as image base.
If in the html file we have an image in base 64
<img src='data:image/jpeg;base64,iVBORw0KGg.......
The image is not rendered.

docker file:

`RUN apk update &&
apk add --no-cache
bash
icu-libs
krb5-libs
libgcc
libintl
libssl1.1
libstdc++
zlib
libstdc++
libx11
libxrender
libxext
libssl1.1
libjpeg
gcompat
ca-certificates
fontconfig
freetype
ttf-dejavu
ttf-droid
ttf-freefont
ttf-liberation &&
apk add --no-cache libgdiplus --repository http://dl-3.alpinelinux.org/alpine/edge/testing/ &&
ln -s /usr/lib/libjpeg.so.8 /usr/lib/libjpeg.so.62

FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine AS build
WORKDIR /src
......
`

Any suggestions?
Thanks in advance
Stefano

@HakanL
Copy link
Owner

HakanL commented Sep 21, 2022

Test it in the non-Alpine docker sample first to determine if it's related to Alpine, or wkhtmltopdf. If it doesn't work in either docker container then test it with the native wkhtmltopdf to make sure your HTML is correct and is supported by the parent library (wkhtmltopdf).

@stefanodesimone
Copy link
Author

Test it in the non-Alpine docker sample first to determine if it's related to Alpine, or wkhtmltopdf. If it doesn't work in either docker container then test it with the native wkhtmltopdf to make sure your HTML is correct and is supported by the parent library (wkhtmltopdf).

Hi HakanL,
i've tried using this image
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 443

Install dependencies

RUN apt-get update
&& apt-get install -y --no-install-recommends
zlib1g
libgdiplus
libc6-dev
ca-certificates
fontconfig
fontconfig-config
fonts-dejavu-core
libbsd0
libexpat1
libfontconfig1
libfontenc1
libfreetype6
libjpeg62-turbo
libpng16-16
libssl1.1
libx11-6
libx11-data
libxau6
libxcb1
libxdmcp6
libxext6
libxrender1
ucf
x11-common
xfonts-75dpi
xfonts-base
xfonts-encodings
xfonts-utils
&& rm -rf /var/lib/apt/lists/*

The image in base64 render fine, I think is a package add problem...
Stefano

@HakanL
Copy link
Owner

HakanL commented Sep 21, 2022

Ok, good you tested that. So then it's a matter of figuring out which packages are required, or it may be that the libjpeg8 library we had to use in alpine with a soft link isn't handling base64 images (I'm assuming). It's always tricky with native libraries. Please post back if you figure it out, I don't think I can be of much more help here.

@ivicaned
Copy link

@stefanodesimone Did you figured out issue and what packages you need to include? If you did, it would be helpful if you can share Docker file sections related to wkhtmltopdf installation/setup, because I run into some issues too.

@HakanL It might be useful to provide instructions for installation on Alpine Linux, as it is the most widely used image for .net/C# projects and running them in production.

@HakanL
Copy link
Owner

HakanL commented Oct 13, 2022

It's quite involved, you have to re-compile wkthtmltopdf from source to make it compatible with Alpine so images work. It may be possible, but I'm not sure it's worth it just to support Alpine. Feel free to look into a PR if you want. Here's a good starting point: https://github.com/madnight/docker-alpine-wkhtmltopdf

@ivicaned
Copy link

It's quite involved, you have to re-compile wkthtmltopdf from source to make it compatible with Alpine so images work. It may be possible, but I'm not sure it's worth it just to support Alpine. Feel free to look into a PR if you want. Here's a good starting point: https://github.com/madnight/docker-alpine-wkhtmltopdf

Thank you for fast response, we decided to temporary switch to Debian base image. I agree that there is much work! Good work anyway!

@Rvanmech
Copy link

Rvanmech commented Nov 2, 2023

Hi there, thanks very much for raising this issue and HakanL for maintaining this! I wanted to share my experience and logs in case it helps. I tried switching to Alpine following the example here (https://github.com/HakanL/WkHtmlToPdf-DotNet/blob/master/src/TestConsoleAppDockerAlpine/Dockerfile#L32C20-L32C20), and while it generates a PDF, we also were seeing images not loading and it seems fonts not displaying properly compared to the Debian distribution.

The logs generated by wkhtmltopdf say "Wrong JPEG library version: library is 80, caller expects 62". From my limited research, the sym link that we are doing in the Dockerfile helps for the jpeg library, but doesn't overcome library incompatibilities.

@HakanL
Copy link
Owner

HakanL commented Nov 2, 2023

The logs generated by wkhtmltopdf say "Wrong JPEG library version: library is 80, caller expects 62". From my limited research, the sym link that we are doing in the Dockerfile helps for the jpeg library, but doesn't overcome library incompatibilities.

Yeah, the symlink isn't a complete solution.

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

4 participants