首页 > Web开发 > 详细

html2canvas转pdf分页隔断问题处理

时间:2019-12-04 18:41:23      阅读:844      评论:0      收藏:0      [点我收藏+]
//html代码
<div id="demo">
    <div class="jy-page">...</div>
</div>


//下载前处理的函数
renderOverpageClum () {
        let demoHeight = $(‘#demo‘).height()
        let pageWidth = $(‘#demo‘).width()
        let pageHeight = pageWidth / 595.28 * 841.89   // 计算每页的高度
        let pageNum = Math.ceil((demoHeight - 100)/(pageHeight - 100))
        $(‘.jy-page‘).attr(‘style‘, ‘height:‘+pageHeight+‘px;width:‘ + pageNum * pageWidth + ‘px;column-count: ‘+pageNum+‘‘);
        var baseDom = $(‘.jy-page‘).eq(0)
        console.log((demoHeight - 100)/(pageHeight - 100))
        console.log(pageNum)
        console.log(‘每页宽度:‘+ pageWidth)
        console.log(‘每页高度:‘+ pageHeight)
        if (pageNum > 1) {
          for (var i = 1; i < pageNum; i++) {
            $(‘#demo‘).append(baseDom.clone().css(‘left‘,‘-‘ + pageWidth * i + ‘px‘))
          }
        }
        $(‘.table-item-first‘).each(function () {
          if ($(this).text().length > 5) {
            let pipHeight = $(this).height()
            $(this).nextAll().height(pipHeight).css({‘line-height‘:pipHeight + ‘px‘})
          } else {
            let pipHeight = $(this).height()
            $(this).nextAll().height(pipHeight).css({‘line-height‘:pipHeight + ‘px‘})
          }
        })
        console.log(‘文档高度:‘+ $(‘#demo‘).height())
      }


//css样式
#demo {
    min-width: 920px;
    max-width: 1190px;
    margin: 0 auto;
    overflow: hidden;
    box-sizing: border-box;
  }
.jy-page {
    box-sizing: border-box;
    column-gap:0px;
    column-fill: auto;
    padding: 50px 0;
    position: relative;
  }

 

html2canvas转pdf分页隔断问题处理

原文:https://www.cnblogs.com/mk2016/p/11984517.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!