Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dealing with long images? #1160

Closed
kutetapolu opened this issue Jul 12, 2020 · 8 comments
Closed

Dealing with long images? #1160

kutetapolu opened this issue Jul 12, 2020 · 8 comments

Comments

@kutetapolu
Copy link

kutetapolu commented Jul 12, 2020

Hi. I have this html:

<h1>example</h2>

<p>text above image</p>

<img src="https://i.imgur.com/zyJBcND.png"></img>

<p>text below image</p>

It links to a long long loong image and has no CSS. It produces a 3-page PDF. First page is mostly empty (Header, "text above" and a lot of empty space), second one consist of a part of the long image, and the third one is "text below".

So the default behaviour is to cut image fo fit the page length. With some CSS I can shrink the image, but that will make the image unreadable.

Is there a way to split long image into multiple pages? Or maybe some other way of dealing with them, without losing most of the image?

@liZe
Copy link
Member

liZe commented Jul 12, 2020

Hello!

Is there a way to split long image into multiple pages? Or maybe some other way of dealing with them, without losing most of the image?

Unfortunately no. It’s another duplicate of #36, and we’ll need to implement CSS Fragmentation to have this kind of cases working.

One solution would be to use named pages to get a very high page height when you meet these images.

@kutetapolu
Copy link
Author

Is there maybe a way to make images clickable? I.e. shrink long images to the thumbnail size and click on them to get full image?

@liZe
Copy link
Member

liZe commented Jul 13, 2020

Is there maybe a way to make images clickable? I.e. shrink long images to the thumbnail size and click on them to get full image?

You can add <a> tags around images to get that.

@liZe liZe closed this as completed Oct 23, 2020
@liZe
Copy link
Member

liZe commented Oct 23, 2020

We can think about that when solving #36.

@HarshitDubey-Raik
Copy link

HarshitDubey-Raik commented May 16, 2024

@liZe I am using WeasyPrint, and facing the same problem as above so wanted to know if this issue is fixed ?

@liZe
Copy link
Member

liZe commented May 16, 2024

I am using WeasyPrint, and facing the same problem as above so wanted to know if this issue is fixed ?

Now that we follow most of CSS fragmentation, we have a better idea about what to do. Unfortunately, splitting images is explicitly not supported by the specification:

Some content is not fragmentable, for example many types of replaced elements (such as images or video), scrollable elements, or a single line of text content. Such content is considered monolithic: it contains no possible break points. Any forced breaks within such boxes therefore cannot split the box, and must therefore also be ignored by the box’s own fragmentation context.

So, unless there’s a new specification to handle this kind of cases, there’s nothing we can do 😒. But there are other solutions: you can for example use page names to change the size of pages that have long images.

@HarshitDubey-Raik
Copy link

HarshitDubey-Raik commented May 16, 2024

@liZe Is there any other way which exists that I can make use of to manually perform this function of Splitting big size images across multiple pages in the PDF?

@liZe
Copy link
Member

liZe commented May 16, 2024

Is there any other CSS property which exists that I can make use of to manually perform this function of Splitting big size images across multiple pages in the PDF?

I don’t think that there’s a magic CSS property for that. The easiest way is probably to set the image as background of a multiple divs, and change the position of the background to cover different parts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants