Surnet / docker-wkhtmltopdf

wkhtmltopdf for multiple base images
https://hub.docker.com/u/surnet/
MIT License
360 stars 65 forks source link

Rendering is gone with patched version #9

Closed tsadiq closed 5 years ago

tsadiq commented 5 years ago

Hi there, i've been trying to get wkhtmltopdf to work properly for a while now and i was struggling with package conflict while trying to get edge libraries on v3.9 to get rid of this nasty QNetworkReplyHttpImplPrivate::_q_startOperation was called more than once QUrl error message that would segfault and not generate the pdf randomly.

Somebody suggested i copy the binary from one of your Dockerfile, which i did - i built Dockerfile_3.9-0.12.5-full and got the binary and the libs out. So far it seems to work pretty well as the pdf now renders without any segfault ever and i'm really glad about it.

But there is one drawback on this: my rendered html is totally broken. Where i had one full width page display i know have several columns like design that are totally off.

Is there any known issue with using last Qt that would explain this?

Anyways, thanks for your time and your work 👌

chdanielmueller commented 5 years ago

Hi @tsadiq, Could you maybe add two examples of PDFs (one with failure + one of what you would expect)? I'm currently unaware of any issues in that regard. But maybe I can help you if I see the issue. Thanks, Daniel

tsadiq commented 5 years ago

Sure, here they are. I just noticed while uploading them that the file made with the patched version is only 25kb in weight, while the other is above 300kb. Could it be that the css file wasn't downloaded? That could explain the lack of proper rendering (and the absence of QUrl error message 🤔)

wk-patched.pdf wk-unpatched.pdf

chdanielmueller commented 5 years ago

I don't know how the HTML for your file looks, but there are some background-colors in there. Therefore I suppose the CSS gets loaded.

Maybe there is an issue with the page width or linebreaks. Does the page look okay if opened in a browser?

Maybe you could set the wkhtmltopdf setting "disable-smart-shrinking" to true. This helped with layout issues for my PDFs.

tsadiq commented 5 years ago

I did try but the result is the same, it just renders bigger than before. That was a nice try tho, thanks for the idea! :D

tsadiq commented 5 years ago

I ended up inlining all the css libs inside my html and i don't have any error with the unpatched version anymore so i guess this will close the topic for now... Until i need actual footers, then i think i'll give another try!

But for reference, the patched version still can't render my html properly, even with inlined css. That's pretty unnerving.

teohhanhui commented 5 years ago

Perhaps if you could share the HTML and CSS, others can identify what's going on?

tsadiq commented 5 years ago

I can, if you feel like having a try at it ^^ I took this out of my docker /tmp, i just renamed it to .txt because github doesn't like html attachments origin.txt

Also, here is the pdf i made using the above file by using the full docker image i built from this repo result.pdf

The image is obviously missing but i don't think this is an issue

chdanielmueller commented 5 years ago

I'm going to keep the issue open. Maybe I (or someone else) has time to take a look at it.

tsadiq commented 5 years ago

As you see fit ^^ I might come back to it sooner or later (as i said, footers 👌) but in the meantime i can't help but thinking something went wrong during the image build and my binary is somehow broken.

teohhanhui commented 5 years ago

@tsadiq Actually I don't understand why you're building the image yourself when you could just copy the binary?

teohhanhui commented 5 years ago

Anyway, I confirm that I can reproduce the problem with something like this:

$ docker run --rm -v "$HOME/Downloads/test:/root/test"  --name wkhtmltopdf surnet/alpine-wkhtmltopdf:3.9-0.12.5-small 'file:///root/test/test.html' /root/test/test.pdf
teohhanhui commented 5 years ago

FWIW, it does render correctly with athenapdf:

$ docker run --rm -v "$HOME/Downloads/test:/converted" --name athenapdf arachnysdocker/athenapdf athenapdf /converted/test.html

But that's ~100% slower.

tsadiq commented 5 years ago

@teohhanhui probably because i like to make things complicated, i guess ¯\ (ツ)

chdanielmueller commented 5 years ago

@tsadiq I was able to at least get a "better" layout by removing the legacy display:-webkit-box; and display:-webkit-inline-box; res.pdf

Maybe there are other settings like this in your css which cause the layout to be broken.

chdanielmueller commented 5 years ago

Closing this issue for now as it does not seem to be an issue with the image itself but css styles. @tsadiq Please keep in mind that wkhtmltopdf uses the webkit engine and therefore legacy tags can cause issues.

tsadiq commented 5 years ago

Oh hey i missed these answers sorry ^^ I think i'ma rework this whole html file with very basic html /css because that subcontractor did a serious pile of crap here. Thanks again for your time 👌

tsadiq commented 4 years ago

Hey, just to let you know, with clean css and reworked html, things are much better and i can use the binary of your last version with footers and pages!

Thanks for your work and your time 👍