Why doesn't wkhtmltopdf page-break-after have any effect?

后端 未结 6 2039
鱼传尺愫
鱼传尺愫 2021-01-30 16:34

I\'m using wkhtmltopdf 0.10.0 rc2 for Mac

I have an html like this one :



  
    

        
相关标签:
6条回答
  • 2021-01-30 17:04

    It is working fine after remove media print

    Before:

    @media print {
        .page-break { height:0;page-break-after: always; margin:0; border-top:none;}
    }
    

    above code not working in new version.

    Now

    .page-break { height:0;page-break-after: always; margin:0; border-top:none;}
    
    0 讨论(0)
  • 2021-01-30 17:12

    Update the wkhtmltopdf to version 0.12.5. Page break issue not occuring for me after updating.

    Use --disable-smart-shrinking to avoid empty white space ( If you have any)

    Use --zoom <value> to avoid page page (If entire page not showing)

    0 讨论(0)
  • 2021-01-30 17:16

    Possibly unrelated as your pdf generated ok with an earlier version of wkhtmltopdf. Either way, I had similar issues with page breaks not being applied correctly. My problem was parent elements of the page-breaked element having an overflow other than visible. This fixed my issue:

    * {
      overflow: visible !important;
    }
    

    Of course, you can be more specific about the tags this applies to ;)

    0 讨论(0)
  • 2021-01-30 17:17

    try using as follows

     <div style="page-break-before:always;">
       //your content
    </div>
    

    this should work.

    0 讨论(0)
  • 2021-01-30 17:19

    I am usinf wkhtmltopdf 0.12.3.2

    For me page-break-after works when a border is set, and when the breaker div is an immediate child of body.

    .page-breaker {
        clear: both;
        display: block;
        border :1px solid transparent;
        page-break-after: always;
    }
    

    break-break-before does not work.

    --print-media-type not needed.

    0 讨论(0)
  • 2021-01-30 17:19

    I am using version wkhtmltopdf 0.12.0

    For me, page breaks ONLY work with --print-media-type. Without it, page break protection for images works, but not page-break-after or before.

    I had to make a special css file for print media to get it work.

    Setting the paper size to 'A3' or using the 'overflow: visible' didn't make any difference.

    Also see WKHTMLTOPDF with pdfkit on Rails ignoring table page breaks

    0 讨论(0)
提交回复
热议问题