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

Page break before image #117

Open
Jugen opened this issue Aug 22, 2017 · 4 comments
Open

Page break before image #117

Jugen opened this issue Aug 22, 2017 · 4 comments
Assignees

Comments

@Jugen
Copy link

Jugen commented Aug 22, 2017

Currently if there isn't enough space at the bottom of a page for an image then a page break is inserted and the image is placed on the next page. This is great and probably the expected behavior most of the time. :-)

Is there a way though from preventing this from happening ?
In certain cases I would like the image to be placed even if there isn't enough space, with the remaining part of the image either dropped, or to overflow onto the next page.

If there isn't already a way to do this could the css style overflow: hidden/visible maybe be extended to be able to accommodate this ?

@Jugen
Copy link
Author

Jugen commented Aug 28, 2017

After some debugging I've managed to modify LineBox.checkPagePosition to implement the above behavior with the following code:

if ( needsPageBreak && ! alwaysBreak && getStyle().isBlockEquivalent() )
{
    CalculatedStyle  parentStyle = getParent().getStyle();

    if ( parentStyle.isAutoHeight() && parentStyle.getIdent( CSSName.OVERFLOW ) == IdentValue.HIDDEN )
    {
	setHeight( Math.max( 0, pageBox.getBottom() - c.getExtraSpaceBottom() - getAbsY() ) );
	needsPageBreak = false;
    }
}

@Jugen
Copy link
Author

Jugen commented Sep 5, 2018

@danfickle suggested trying -fs-page-break-min-height: 100px; (Thanks dan)

Unfortunately -fs-page-break-min-height doesn't work on images, I tried:

<div style="-fs-page-break-min-height: 100px;">
   <img .... />
</div>

danfickle added a commit that referenced this issue Sep 6, 2018
Discovered that there is no way to specify that inline-block elements (including img elements by default) can split between pages.
@danfickle
Copy link
Owner

Hi @Jugen

Thanks for persevering with this issue.

I wrote some tests around this problem and discovered that the generic problem is that there is no way to specify that inline-block elements can split between pages. A possible workaround is to use block for images that you want split capable:

img {
  display: block;
}

P.S Unlike my previous suggestion I have tested that this works.

@Jugen
Copy link
Author

Jugen commented Sep 6, 2018

@danfickle Thank you very much for the time you've put into this issue, I really appreciate it !

I'm not a CSS or HTML expert but I think that using display: block on images that you don't mind overflowing across pages is acceptable. Maybe its just not intuitive (?), but then that's what we have docs for :-)

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

2 participants