Skip to content
This repository has been archived by the owner on Aug 28, 2023. It is now read-only.

Alpine build #2

Open
mikehaertl opened this issue Apr 29, 2018 · 41 comments
Open

Alpine build #2

mikehaertl opened this issue Apr 29, 2018 · 41 comments
Labels
help wanted Extra attention is needed
Milestone

Comments

@mikehaertl
Copy link

There's already a (docker based) build for alpine over here:

https://github.com/Surnet/docker-wkhtmltopdf

The build setup could be copied as a starting point.

It basically works - but has issues with some fonts not being rendered correctly (See Surnet/docker-wkhtmltopdf#1). We've boiled that down to:

  • fontconfig works
  • Serif fonts are available on the system and reported by fontconfig
  • The match string that fontconfig receives from wkhtmltopdf misses Serif fonts - even if used in CSS

/cc @chdanielmueller Maybe you can contribute something here? It would be awesome to have an "official" alpine build of wkhtmltopdf and you seem to already have solved most of the hurdles.

As much as I'd like to help, I have not looked into the build process at all and I'm not really an expert here.

@ashkulz
Copy link
Member

ashkulz commented May 9, 2018

I guess I'll need to incorporate the musl changes into Qt as well, as I don't want to apply patches on the fly ... will try to look into it this weekend.

@ashkulz
Copy link
Member

ashkulz commented Jun 21, 2018

@alloylab: are you planning to make a PR for this?

@alloylab
Copy link

alloylab commented Jul 5, 2018

yes I am, got behind with EOQ... just successfully compile 0.12.5 on alpine... https://git.alloylab.com/open-source/wkhtmltopdf/tags/0.12.5-070518 will submit PR on here

@ashkulz
Copy link
Member

ashkulz commented Jul 5, 2018 via email

@dcelasun
Copy link

Any progress on this?

@sir-gon
Copy link

sir-gon commented Aug 30, 2018

Oh pls! I i'm doing a lot of research for a headless solution for PDF generation and wkhtmltopdf is the best until now, but I have produced a huge docker image!

Alpine aproach would be perfect

@jtraulle
Copy link

@sir-gon See my Dockerfile for this : https://github.com/Opencomp/Dockerfiles/blob/master/wkhtmltopdf/Dockerfile

@chdanielmueller
Copy link

@sir-gon or feel free to use https://github.com/Surnet/docker-wkhtmltopdf

@mikehaertl
Copy link
Author

@chdanielmueller @sir-gon But the font issue mentioned in the issue description still isn't fixedin the Surnet images, right? This makes those images only partially useful.

@chdanielmueller
Copy link

@mikehaertl That's right that issue is still open. A workaround is to use fonts loaded from the web. e.g. Google Fonts

@jtraulle Do you have any issues in your image with false fonts?

@jtraulle
Copy link

jtraulle commented Sep 2, 2018

@chdanielmueller I don't think so. Try it a tell me ;)

@cjimti
Copy link

cjimti commented Oct 28, 2018

I have not yet experienced any font issues. It is possible I may just be using my build on such a limited set of pages that I have not noticed it. I use a binary build for alpine:3.7 from https://github.com/madnight/docker-alpine-wkhtmltopdf and add fonts. My docker file is here: https://github.com/txn2/n2pdf/blob/master/Dockerfile

https://github.com/txn2/n2pdf

I use this pretty heavily in my txPdf project: https://imti.co/webpage-to-pdf-microservice/

@enthusiasmus
Copy link

Any progress so far? May we help with the pr?

@ashkulz
Copy link
Member

ashkulz commented Apr 9, 2019 via email

@enthusiasmus
Copy link

enthusiasmus commented Apr 9, 2019

Is there a guide how to compile wkhtmltopdf for other platforms (alpine) and a testing guide to see if the build is working or not?

@ashkulz
Copy link
Member

ashkulz commented Apr 9, 2019 via email

@ashkulz
Copy link
Member

ashkulz commented Apr 10, 2019

Also, forgot about #20 by @anujith-singh -- it has the build system changes but I doubt it works because of the missing Qt patches.

@anujith-singh
Copy link

Yes @ashkulz Qt patches are missing in it

@ashkulz
Copy link
Member

ashkulz commented Jun 2, 2020

I'm planning to release 0.12.6 in a week's time -- does someone have the capacity to work with me to integrate the Qt patches required for Alpine support? @alloylab was going to do that at one point of time -- if he or @chdanielmueller can help me integrate the patches so that they don't break something else, I'd really appreciate it 😄

@co-codr
Copy link

co-codr commented Jun 17, 2020

Any updates on release 0.12.6?

@ashkulz
Copy link
Member

ashkulz commented Jun 17, 2020

0.12.6 is released already -- an alpine version will only happen for 0.12.7.

@chdanielmueller
Copy link

@ashkulz The file linked below is a Dockerfile for alpine:10 which builds 0.12.6
https://github.com/Surnet/docker-wkhtmltopdf/blob/master/archive/alpine-wkhtmltopdf/Dockerfile_3.10-0.12.6-full
I hope this is enough reference for a official alpine package for 0.12.7

With alpine:11 and up we have an issue that we are not able to build without specifically setting g++ and stdlibc++ to use the version from alpine:10.
The issue is related to gcc9.
Please see the following discussions:
Surnet/docker-wkhtmltopdf#13
Surnet/docker-wkhtmltopdf#18

@ashkulz
Copy link
Member

ashkulz commented Sep 9, 2020

@chdanielmueller that's a common problem (affecting Ubuntu 20.04 and ArchLinux as well) -- I'll be solving that with a proper fix in Qt, the Q_FOREACH fix looks to be correct.

My main concern is integrating the other patches in https://github.com/Surnet/docker-wkhtmltopdf/tree/master/conf -- I'd like to understand why each one is required, as they shouldn't cause a regression for some other platform. Do you have some script/process that you use for testing the resulting binary, so I can confirm if the patch is required at compile time or at runtime and adapt accordingly?

@chdanielmueller
Copy link

I did not include any automated tests.
You can run the following command to test a version you built without some of the patches.
docker run surnet/alpine-wkhtmltopdf:<version> google.com - > test.pdf

The patches are being applied here:
https://github.com/Surnet/docker-wkhtmltopdf/blob/a445546703648957459b9c673e9db2e637c5a4de/Dockerfile-alpine.template#L53
(or in any Dockerfile in the archive)

@darmawan01
Copy link

darmawan01 commented Nov 4, 2020

any update for this issues ?
i use image alpine and wkhtmltopdf 0.12.5

look like is not patched with qt

@ashkulz
Copy link
Member

ashkulz commented Nov 4, 2020

@darmawan01 not really, I haven't had time to integrate the musl patches into patched Qt.

@darmawan01
Copy link

i really need for this qt support in alpine. when the 12.7 will release with alpine build patched qt ?

@DennisdeBest
Copy link

Hey to get this working in the mean time I used some of the dependencies mentioned in https://github.com/RoseRocket/docker-alpine-wkhtmltopdf-patched-qt

RUN apk --update --no-cache add \
   wkhtmltopdf \
    libgcc \
    libstdc++ \
    musl \
    qt5-qtbase \
    qt5-qtbase-x11 \
    qt5-qtsvg \
    qt5-qtwebkit \
    ttf-freefont \
    ttf-dejavu \
    ttf-droid \
    ttf-liberation \
    ttf-ubuntu-font-family \
    fontconfig

# Add openssl dependencies for wkhtmltopdf
RUN echo 'http://dl-cdn.alpinelinux.org/alpine/v3.8/main' >> /etc/apk/repositories && \
    apk add --no-cache libcrypto1.0 libssl1.0

This now works for me on a base php:7.4.12-fpm-alpine image.

It took a day of wondering around the internet to get this to work but it does now :)

Thanks @ashkulz for this librairie, it is awesome :)

@maggie44
Copy link

Hey to get this working in the mean time I used some of the dependencies mentioned in https://github.com/RoseRocket/docker-alpine-wkhtmltopdf-patched-qt

RUN apk --update --no-cache add \
   wkhtmltopdf \
    libgcc \
    libstdc++ \
    musl \
    qt5-qtbase \
    qt5-qtbase-x11 \
    qt5-qtsvg \
    qt5-qtwebkit \
    ttf-freefont \
    ttf-dejavu \
    ttf-droid \
    ttf-liberation \
    ttf-ubuntu-font-family \
    fontconfig

# Add openssl dependencies for wkhtmltopdf
RUN echo 'http://dl-cdn.alpinelinux.org/alpine/v3.8/main' >> /etc/apk/repositories && \
    apk add --no-cache libcrypto1.0 libssl1.0

This now works for me on a base php:7.4.12-fpm-alpine image.

It took a day of wondering around the internet to get this to work but it does now :)

Thanks @ashkulz for this librairie, it is awesome :)

@ashkulz, would be helpful to hear your view on this approach. Am I opening a can of worms using this for a production env? Is it best to wait for .7 release?

It would be for creating a pull request on a Linux Server image to resolve this issue: linuxserver/docker-bookstack#80

@taraspos
Copy link

taraspos commented Apr 5, 2021

@Maggie0002, issue I faced that Chinese text is not being rendered without wqy-zenhei package.

Ref: https://stackoverflow.com/a/49085451/3880239

@itsyoshio
Copy link

Anyone managed to achieve QT5 Webkit compatibility?
The Arch Linux package is bundled for that, so it includes CSS3 (Flex) Support.

I'm wondering there is a docker image / guide or anything out here.

Thanks!

@reiz
Copy link

reiz commented Oct 18, 2021

Any updates on this?

@ashkulz
Copy link
Member

ashkulz commented Oct 18, 2021

Not really, haven't had the time to investigate the required Qt patches.

@huycn
Copy link

huycn commented Jun 27, 2022

I would like to share some info which may help those who are still struggling with font issues. I'm not sure where the source of problem but it seems that it depends a lot on configuration of fontconfig. I have following test file:

<html>
<head>
<style>
@font-face {
    font-family: "Arial Narrow";
    src: url("arialn.ttf") format("truetype");
}
body { font-amily: "Arial" }
.narrow { font-family: "Arial Narrow" }
</style>
</head>
<body>
This text should be using Arial font.<br/>
<span class="narrow">This text should be using Arial Narrow font.</span><br/>
</body>
</html>

With docker image from https://github.com/Surnet/docker-wkhtmltopdf, if no fonts are installed, the pdf will have both lines with "Arial Narrow", which is reasonable. But if I install Arial in OS, the pdf will have both lines in Arial. Replace Arial with other font, it will have both lines in that font, ignoring completely the font-face in css.

Now if I extract the package fonts-urw-base35 from Ubuntu repo, copy files from /etc/fonts/config.d and from /usr/share/fonts/opentype/urw-base35 over to my docker image and do fc-cache -f, it starts to work correctly, each line with expected font. I guess the fallback configuration in config.d did the trick but I cannot confirm, it's good enough for me so I move on.

I also tested with ubuntu:focal, it had the same issue without the package fonts-urw-base35, but works correctly with.

@ashkulz
Copy link
Member

ashkulz commented Jun 29, 2022

@huycn that sounds like more a fontconfig issue with the above docker image and not wkhtmltopdf? Thanks for the information, though!

@Ruesa18
Copy link

Ruesa18 commented Sep 8, 2022

Sorry for asking. But this could be very useful for what I am currently working on (alpine images with wkhtmltopdf for amd and arm processors), so... Is there any update on this? 😅

@quentincaffeino
Copy link

Sorry for asking. But this could be very useful for what I am currently working on (alpine images with wkhtmltopdf for amd and arm processors), so... Is there any update on this? 😅

If you want your pdf look pixel perfect as in browser, just use a browser and some testing framework. Here is an example how to do this with puppeteer' https://futurestud.io/tutorials/node-js-create-a-pdf-from-html-with-puppeteer-and-handlebars

@Ruesa18
Copy link

Ruesa18 commented Sep 9, 2022

I already have existing applications that are using wkhtmltopdf. The only thing is that I would like to have it inside my alpine images for easier deployment and maintenance in general. So switching to another pdf renderer isn't really an option 😅
What I'm searching is either an up-to-date alpine image (amd and arm) or - even better - binary files for both architectures that I can just download and copy into my existing images

@quentincaffeino
Copy link

quentincaffeino commented Sep 9, 2022

I already have existing applications that are using wkhtmltopdf. The only thing is that I would like to have it inside my alpine images for easier deployment and maintenance in general. So switching to another pdf renderer isn't really an option 😅
What I'm searching is either an up-to-date alpine image (amd and arm) or - even better - binary files for both architectures that I can just download and copy into my existing images

I don't think there is a up-to-date binary therefore also no image. If it would be it would be here.

But you might be able to find older versions, just search for it, I used to use one myself.

@ashkulz
Copy link
Member

ashkulz commented Sep 12, 2022

I think there's a few docker images linked above, I've yet to evaluate the patches 🤷‍♂️

@huage969030970
Copy link

I'm using this and it doesn't seem to support JavaScript

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
help wanted Extra attention is needed
Development

No branches or pull requests