-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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-breaks: Add modes and ability to specify elements #153
Conversation
Update link to html2canvas documentation
For page breaks to not cut my elements in half is this all I need to do?
mode:avoid-all did not do anything for me. To use css property I have to set P.S. Thanks for being active again |
I haven't tested this yet as I don't have html2pdf set up anywhere, but does this page / html break properly?: http://CampSoftware.com/labs/htmlToPDF.htm That html uses the following CSS to avoid page breaks. Thanks so much! So far, only https://wkhtmltopdf.org/ seems to support avoiding page breaks. I'd much rather use html2pdf since wkhtmltopdf is a binary... |
so far using after or before doesn't looking to be working. For my environment, I have 2 tables. The 2nd table is supposed to be on a new page. Replacing .html2pdf__page-break with after/before no longer keeps it on the 2nd page. Still doing some testing with the other page breaks, but it's at least no longer splitting text between letters? using
|
https://jsfiddle.net/y27zgowd/12/ EDIT: Confused why it's not cutting exactly like in my env, I guess the different text lengths? Regardless, forcing the page break doesn't work |
Not sure how related or it'll help, but for the css, could it also include page-break-* alongside the breaks-*? I unfortunately have a case where I need to use IE 8 :( |
Hi all, sorry I've had such limited time to devote to html2pdf lately. I'm going to be without Internet for the next two weeks or so, but I will have a chance to work on a few pieces over that time so I hope to come back with a working (and tested) pageBreak module when I return. @Greensahil @campsoftware I'll have to test that page when I return, remind me! @ZabbyCapurin thanks for the tests, sounds like I need to do some fixes. I literally didn't have time to test at all. |
Fixed issues with references and checks
Hi everyone, it should be all fixed! Thanks for your patience. A few details:
I'll merge this in soon, and create a new release in master (v0.9.1) with it included. Let me know if any issues come up! |
@eKoopmans When you merge those great PR? I can't wait for test page break feature. |
Has the I really need this and it is not working at all for me. Do I need to remove all tags for this tow work? |
Is there a way for me to specify it to only ever add a pagebreak to a specific element if necessary? Before and after are immediate and listing down elements in avoid hasn't led me to be lucky. It's a web part that I have no control over the build unfortunately. |
I've been using html2pdf for awhile now. We take html reports and send them via pdf to customers. I've recently had to start supporting multiple different style reports. I switched to format of 'A4' and since then I've been having issues with page breaks not understanding the page size. Break occurs close to where you place it (tried avoid all, legacy, etc) and it breaks but puts say the header of the next page on the bottom. I switch back to letter and this no longer occurs. I was wondering if that is a separate issue, or am i not using the new features correctly? |
@Braybrookr Hope this helps if the issue hasn't been solved yet. |
I still got a issue with one giant DIV which overlaps to multiple pages. V0.9.1 used from Master branch grabbed today. Settings used:
For the multiple divs it does not work as well, Situation what I want it to do: |
Same behavior with 3 small tables (like 4 rows), each of them split by page breaks (2 rows before and after the break), and the rest of the pages, blank. :( |
Hi all! I haven't had much time to devote to html2pdf recently, but I'll be doing what I can over the next couple weeks. For those of you who have posted in this thread, if you still have a problem please post it to a separate issue. This thread is for discussion of a specific pull request which has been merged at this point. Thanks! @cablegunmaster @AbelVM, please open an issue for the text cut-off - I was hoping to avoid the "white-line" mode (#41) but it may be necessary. @KaiOrange the solution to your problem is probably to not use 'avoid-all', and instead specify the kinds of elements you want it to break on (e.g. |
@eKoopmans I opened a ticket as of #184 The STR is... any! I have tested all the possible combinations of options related to page break and I get more or less the same result. 😞 |
I had some problems implementing html2pdf. However, most of the problems were with my HTML and not with html2pdf itself. So, be aware of the HTML adjustments that must be made for html2pdf to work correctly. onExportClick() {
Another thing, my content came out of a modal, where I had placed a height of 400px, this caused the content of my page to be cut in the PDF whenever the modal reached the limit of 400px, ignoring everything else. So I made an adjustment to my HTML, put the scroll bar before exporting the id:
My text was also being cut in half whenever I reached the last line of the PDF, I solved this problem by applying a css to the body of my content: margin-bottom: 50px. As you can see in the code above. |
I would say as a general advice; try to use as minimal CSS as possible. |
I often say that CSS can be your best friend or your worst enemy. In my case it helped a lot. Just have common sense and know how to use wisely.
|
@munnebshafiq, are you using formio? Me too using the formio. So the rendered form is to be downloaded as Pdf but I am facing issue with page breaks and text not selectable issue using this library. |
@ramesh-619 unfortunately, yes pagebreak issue still exists. |
This PR attempts to combine the features added by #41, #111, #118, and #138.
Highlights
opt.pagebreak
option with 4 fields:mode
: one (or more) of 'css', 'legacy', 'avoid-all', or 'whiteline' (descriptions below)before
,after
, andavoid
: strings or arrays of CSS selectors to explicitly set page-breaks before or after elements, or avoid page-breaks on elements.Modes
break-before
,break-after
, andbreak-inside
properties. Only recognizesalways/left/right
for before/after, andavoid
for inside.html2pdf__page-break
.Example usage
Todo
clientRect
values if container isn't at the top of the screen, and/or if things are scrolledRefactor to streamline when CSS option isn't selected(Not viable)avoid
on before/after, multiple pages for left/right)To everyone
Please test and let me know if anything needs to be added/removed/changed! To test you will need to pull this branch (
feature/pagebreaks
) then build withnpm run build
. Thanks!