• html2canvas转pdf分页隔断问题处理


    //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;' + 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- 920px;
        max- 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;
      }
    handleDown() {
            this.pod = true
            this.$nextTick().then(() => {
              this.renderOverpageClum()
              htmlToPdf.downloadPDF(document.querySelector('#demo'), 'download')
              this.resetClumStyle()
            })
          },
          handlePreview() {
            this.pod = true
            this.$nextTick().then(() => {
    
              $('.table-item-first').each(function () {
                let pipHeight = $(this).height()
                $(this).nextAll().height(pipHeight).css({'line-height':pipHeight + 'px'})
              })
    
              htmlToPdf.previewImg(document.querySelector('#demo')).then(res => {
                this.previewUrl = res
              })
              this.previewImgShow = true
            })
    
          },
  • 相关阅读:
    [LeetCode 题解]: Remove Duplicates from Sorted List
    [LeetCode 题解]: Merge k Sorted Lists
    [LeetCode 题解]: Insertion Sort List
    [LeetCode 题解]:Candy
    求任意多边形面积 python实现
    C++飞机大战
    version robot
    python一段代码 感受一下
    微机原理上机第四次实验内容
    初步的百度爬虫
  • 原文地址:https://www.cnblogs.com/mk2016/p/11984517.html
Copyright © 2020-2023  润新知