wicked_pdf icon indicating copy to clipboard operation
wicked_pdf copied to clipboard

How to avoid content cutting when textarea height is greater than PDF Page size

Open PriyankaRPathak opened this issue 2 years ago • 1 comments

Hi,

I'm using wicked_pdf to generate PDF. I've footer on each page of PDF, when content of textbox is larger then PDF default page size than content splits into more than one page and all pages has footer which looks odd.

I would like to avoid header / footer when auto page break happen, or i need to combine pages. So all content fits into one page.

Can anyone assist here?

I've added sample PDF. I tried div.nobreak:before { clear:both; } div.nobreak{ page-break-inside: avoid; but it doesn't work. sample-pdf

PriyankaRPathak avatar May 30 '22 18:05 PriyankaRPathak

I think you could detect if you are on the last page and only apply the footer then with an HTML footer something like this:

<html>
  <head>
    <script>
      function get_params() {
        var params = {};
        var param_pairs = document.location.search.substring(1).split('&');
        for(var i in param_pairs) {
           var param_pair = param_pairs[i].split('=',2);
           var param_key = param_pair[0];
           var param_value = param_pair[1];
           params[param_key] = decodeURIComponent(param_value);
        }
        return params;
      }
      function add_footer_if_needed() {
        var params = get_params();
        var footer = document.getElementsByClassName('footer')
        if (params['page'] == params['topage']) { // current page is same as the last page
          footer.textContent = "Footer that only shows on last page";
        }
      }
    </script>
  </head>
  <body onload="add_footer_if_needed()">
    <span class="footer"></span>
  </body>
</html>

Please let me know how it goes.

unixmonkey avatar Jun 01 '22 17:06 unixmonkey

I'm hoping this worked for you, or at least pointed you in a workable direction. Please let me know how it went if you can.

unixmonkey avatar Sep 29 '23 13:09 unixmonkey