wkhtmltopdf / packaging

Packaging of wkhtmltopdf releases
https://wkhtmltopdf.org/downloads.html#stable
306 stars 138 forks source link

Alpine build #2

Open mikehaertl opened 6 years ago

mikehaertl commented 6 years ago

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 https://github.com/Surnet/docker-wkhtmltopdf/issues/1). We've boiled that down to:

/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 commented 6 years ago

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

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

alloylab commented 6 years ago

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

Please submit PR for Qt patches first, then over here.

dcelasun commented 6 years ago

Any progress on this?

sir-gon commented 6 years ago

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

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

chdanielmueller commented 6 years ago

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

mikehaertl commented 6 years ago

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

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

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

cjimti commented 5 years ago

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

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

ashkulz commented 5 years ago

No one has worked on it, so still pending. PR would definitely be welcome!

enthusiasmus commented 5 years ago

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

See the README, it's relatively easy to do if you're comfortable with Docker.

The tougher part is to submit a PR for the qt changes required, will need to figure out which patches are relevant.

There's no test suite, so basic checking on a few URLs would be good before reviewing a PR.

Great to see interest, hope you do find to take it up!

ashkulz commented 5 years ago

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

Yes @ashkulz Qt patches are missing in it

ashkulz commented 4 years ago

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

Any updates on release 0.12.6?

ashkulz commented 4 years ago

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

chdanielmueller commented 4 years ago

@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: https://github.com/Surnet/docker-wkhtmltopdf/issues/13 https://github.com/Surnet/docker-wkhtmltopdf/pull/18

ashkulz commented 4 years ago

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

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

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

look like is not patched with qt

ashkulz commented 3 years ago

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

darmawan01 commented 3 years ago

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

DennisdeBest commented 3 years ago

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

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: https://github.com/linuxserver/docker-bookstack/issues/80

taraspos commented 3 years ago

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

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

itsyoshio commented 3 years ago

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

Any updates on this?

ashkulz commented 2 years ago

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

huycn commented 2 years ago

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

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

Ruesa18 commented 2 years ago

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

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

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 :sweat_smile: 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 commented 2 years ago

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 :sweat_smile: 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 commented 2 years ago

I think there's a few docker images linked above, I've yet to evaluate the patches :man_shrugging:

huage969030970 commented 1 year ago

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