最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - vue3-html2pdf generates blank pdf - Stack Overflow

programmeradmin0浏览0评论

this generates blank pdf for me:

  <vue3-html2pdf
      :show-layout="false"
      :float-layout="true"
      :enable-download="true"
      :preview-modal="true"
      :paginate-elements-by-height="1400"
      filename="invoice"
      :pdf-quality="2"
      :manual-pagination="false"
      pdf-format="a4"
      :pdf-margin="10"
      pdf-orientation="portrait"
      pdf-content-width="800px"
      @progress="onProgress($event)"
      ref="html2Pdf"
    >
      <section slot="pdf-content"><div>hii</div></section>
    </vue3-html2pdf>

Function:

 <img
  :style="{ cursor: 'pointer' }"
   src="../assets/images/download-arrow.png"
   alt="&laquo;"
   @click="generatePDF()"
 />

  generatePDF() {
      this.$refs.html2Pdf.generatePdf();
    },

Please help me as soon as possible. I have a strict deadline. I will try all possible solutions, can anyone help me.

this generates blank pdf for me:

  <vue3-html2pdf
      :show-layout="false"
      :float-layout="true"
      :enable-download="true"
      :preview-modal="true"
      :paginate-elements-by-height="1400"
      filename="invoice"
      :pdf-quality="2"
      :manual-pagination="false"
      pdf-format="a4"
      :pdf-margin="10"
      pdf-orientation="portrait"
      pdf-content-width="800px"
      @progress="onProgress($event)"
      ref="html2Pdf"
    >
      <section slot="pdf-content"><div>hii</div></section>
    </vue3-html2pdf>

Function:

 <img
  :style="{ cursor: 'pointer' }"
   src="../assets/images/download-arrow.png"
   alt="&laquo;"
   @click="generatePDF()"
 />

  generatePDF() {
      this.$refs.html2Pdf.generatePdf();
    },

Please help me as soon as possible. I have a strict deadline. I will try all possible solutions, can anyone help me.

Share Improve this question asked Mar 23, 2022 at 5:27 Joyal ShahJoyal Shah 833 silver badges7 bronze badges 1
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Bot Commented Mar 23, 2022 at 7:19
Add a ment  | 

2 Answers 2

Reset to default 5

I try this library too. And, with vue3 I have a blank page too...

After some search, I find this solution:

<VueHtml2pdf
        :show-layout="false"
        :float-layout="true"
        :enable-download="false"
        :preview-modal="true"
        :paginate-elements-by-height="1400"
        filename="nightprogrammerpdf"
        :pdf-quality="2"
        :manual-pagination="false"
        pdf-format="a4"
        :pdf-margin="10"
        pdf-orientation="portrait"
        pdf-content-width="800px"
        @progress="onProgress($event)"
        ref="html2Pdf"
      >
        <template  v-slot:pdf-content>
          <p>your content here</p>
        </template>
</VueHtml2pdf>        

you can check vue docs for more information about slots https://vuejs/guide/ponents/slots.html#scoped-slots

i try this librairy to after your message. And, with vue3 i have blank page too...

After some hour of work, i try html2pdf.js directly (your library is just a fork for vuejs) and it's work perfectly with vuejs 3 ;)

 - doc canvas options : https://html2canvas.hertzen./configuration
 - doc jspdf options : https://rawgit./MrRio/jsPDF/master/docs/jsPDF.html
 - doc html2pdf.js : https://ekoopmans.github.io/html2pdf.js/
    generateReport () {
      html2pdf(this.$refs.document, {
        margin: 0.2,
        filename: this.options.title + ".pdf",
        pagebreak:  { after: '.sautDePage' },
        image: { 
          type: "jpeg", 
          quality: 2
        },
        html2canvas: { 
          scale: 2, 
          letterRendering: true
        },
        jsPDF: { 
          unit: "in", 
          format: "a4", 
          orientation: "portrait"
        },
      });
    }
<section class="pdf-content  q-pa-md bg-white" ref="document">
          <section class="pdf-item" style="background-image: url('fixture/bg.PNG'); background-repeat: no-repeat; background-position: 50% 0; background-size: cover;">
            <h4 style="font-family: cursive;" class="text-primary">Dolore culpa eiusmod aute labore labore eu nulla.</h4>
            <span>Lorem Lorem incididunt qui in aute aliquip incididunt anim veniam in reprehenderit eiusmod qui minim. Do officia elit duis culpa non excepteur. Ut quis reprehenderit cupidatat exercitation.</span>
            <br>
            <br>
            <img src="fixture/unicorn.png" />

            <div class="sautDePage"></div>
            <h2 style="background: white">HTML Table</h2>
...

gl !

发布评论

评论列表(0)

  1. 暂无评论