【问题标题】:how to add page break on jspdf html如何在jspdf html上添加分页符
【发布时间】:2022-12-12 03:56:05
【问题描述】:

我想添加一个分页符 在jspdf,如何在打印页面时自动添加分页符,我在vue 3中使用jspdf插件,是否可以使用这些插件添加分页符?

我的代码:

<template>
  <div class="parent">
    <div
      class="pdf"
      id="pdf"
      style="
        display: block;
        width: 450px;
        padding: 70px;
        padding-top: 18px;
        padding-left: 16px;
      "
    >
      <div
        v-for="(index, arr) of Array(30)"
        style="
          display: inline-block;
          margin: 15px 0;
          margin-left: 7px;
          text-align: center;
        "
      >
        <div style="font-size: 8.25px">SCS111022021235</div>
        <div style="padding: 4.5px; border: 1px dashed black">
          <img :src="qrCodeUrl" style="width: calc(100px * 0.55)" />
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { onMounted, ref } from "vue";
import QRCode from "qrcode";
import { jsPDF } from "jspdf";

const qrCodeUrl = ref("");

const doc = new jsPDF("portrait", "px", "a4");

QRCode.toDataURL("asdasd", { margin: 0 }).then(url => {
  qrCodeUrl.value = url;
});
onMounted(() => {
  doc.html(document.getElementById("pdf")!, {
    callback: doc => {
      // doc.save();
      window.open(doc.output("bloburl"), "_blank");
    },
    x: 10,
    y: 10
  });
});
</script>

【问题讨论】:

  • 我会使用html2pdf,他们对分页符有更好的支持。
  • 你找到解决办法了吗?

标签: javascript vue.js jspdf


【解决方案1】:

您需要在 .html 方法中将 autoPaging 设置为“文本”

例子:

  doc.html(document.getElementById("pdf")!, {
    callback: doc => {
      // doc.save();
      window.open(doc.output("bloburl"), "_blank");
    },
    x: 10,
    y: 10,
    autoPaging: 'text'
  });

它帮助了我。我在这里找到了解决方案:https://stackoverflow.com/a/70211059/7027059

【讨论】:

    猜你喜欢
    • 2022-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多