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 report #1894

Closed
pocomane opened this issue Jun 4, 2023 · 7 comments
Closed

Page break report #1894

pocomane opened this issue Jun 4, 2023 · 7 comments
Labels
CSS Questions about how to do something with CSS

Comments

@pocomane
Copy link

pocomane commented Jun 4, 2023

I would like to add a page break before a specific element, if both the following conditions are true:

  • It is split on multiple page without the new page break
  • The new page break prevents the element to be split

Probably this is a too specific feature, so I would ask:

  1. What is currently the most similar result I can get?
  2. Can a flag be added to support "External page break logic"?

The 2) can be also something very simple and "Passive" like a --report-breaks flag that return a list of where the page breaks will be placed. For my scenario this would be enough since I can write a script/program that call WeasyPrint multiple times, adding iteratively some page breaks until it gets the desired result.

What this "List of page breaks" actually contains is an open point; anything related to the position in the input HTML would work for me.

Currently I am experimenting with this workaround:

  • Adding a <h4>possible-break-uid</h4> before each div/p/etc
  • Using position: absolute; left: -999px; style for <h4> to effectively hide them, but keeping weasyprint to generate metadata about them
  • Searching the uid in the bookmarks of the pages returned by weasyprint.HTML().render()
  • The "List of page breaks" are simply the uids in the first <h4> of each page

but obviously an integrated solution would be a lot more usable.
.

@liZe
Copy link
Member

liZe commented Jun 4, 2023

Hi!

I would like to add a page break before a specific element, if both the following conditions are true:

  • It is split on multiple page without the new page break
  • The new page break prevents the element to be split

I think that it’s a duplicate of #1252, isn’t it?

@pocomane
Copy link
Author

pocomane commented Jun 4, 2023

The issue I described would be solved if the behaviour in #1252 were implemented. However I described a more general solution that will enable the users to control page breaking in detail (at least the programmers user). I do not know how much is complex to implement, but my tests with the H4 trick suggest to me that all what is needed is already in place.

@liZe
Copy link
Member

liZe commented Jul 12, 2023

WeasyPrint tries to follow the specifications, so we can try to add such a behaviour if it’s in the specification. Is your idea to get all the different break points with the Python API?

@liZe liZe added the CSS Questions about how to do something with CSS label Jul 12, 2023
@pocomane
Copy link
Author

WeasyPrint tries to follow the specifications

Which specification? I am proposing a way to get the list of the breaks added by WeasyPrint to a specific document, I do not think this can be covered by the html/css specification.

Is your idea to get all the different break points with the Python API?

My idea was a command line flag, but yes, a python API would be enough for me since I can write a simple command line wrap.

Is it already possible to do something like that? The most close thing I found was the one I described as workaround.

@liZe
Copy link
Member

liZe commented Jul 13, 2023

Which specification? I am proposing a way to get the list of the breaks added by WeasyPrint to a specific document, I do not think this can be covered by the html/css specification.

The specification describing break points (linked in my comment).

My idea was a command line flag, but yes, a python API would be enough for me since I can write a simple command line wrap.

If it’s a workaround to solve your original problem, then it would be better to solve #1252.

For a more general case, and as a workaround for now, if you want to know where your document was split with the API then you can add ids to your HTML document and use the Page.anchors information to know where the pages are split. Would that be OK for you?

@pocomane
Copy link
Author

If I understand correctly, the page.anchor trick is similar to the one presented on my first post. I can continue to use it, sure. And yes, fixing #1252 would be helpfull in a lot of situation, but with 2) I was proposing a general way to handle page breaks programmatically.

I understand the confusion, so please close this issue. I will open a new one in case I found another situation in which I need a more powerful control on page breaks.

@liZe
Copy link
Member

liZe commented Jul 13, 2023

If I understand correctly, the page.anchor trick is similar to the one presented on my first post.

Yes, it is.

I understand the confusion, so please close this issue. I will open a new one in case I found another situation in which I need a more powerful control on page breaks.

OK!

@liZe liZe closed this as not planned Won't fix, can't repro, duplicate, stale Jul 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CSS Questions about how to do something with CSS
Projects
None yet
Development

No branches or pull requests

2 participants