Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
615 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 Answer

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");

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...