Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
621 views
in Technique[技术] by (71.8m points)

wkhtmltopdf cutting images in half

I am currently using wkhtmltopdf to generate PDFs from a fairly simple HTML page. This HTML page contains 1 image. For some reason, this image is sometimes cut in a weird way!

Image cut in half

AS the above example shows, this image is cut down the middle, and merged together again.

I tried adding

page-break-inside: avoid;
page-break-after: avoid;
page-break-before: avoid;

To the div the image resides in, and the image itself. Unfortunately, no cookie. There's no pattern that can be found for the images uploaded either. It seems it's not size related, file extension related or otherwise. I'm at a loss here.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

So, what I was doing before, was using a div, and the image as background:

background:url("https://example.com/file.jpg");

On some rare occasions (can't seem to figure out why), this fails. A workaround is:

background-image:url("https://example.com/file.jpg");

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...