kempsteven / vue-html2pdf

vue-html2pdf converts any vue component or element into PDF, vue-html2pdf is basically a vue wrapper only and uses html2pdf.js behind the scenes.
https://www.npmjs.com/package/vue-html2pdf
MIT License
432 stars 75 forks source link

Using ref as pdf-content does not print layout html report #169

Open Amkha opened 1 year ago

Amkha commented 1 year ago

Describe the bug When using ref in div tage, it print only when the data is available. Whithout data just print blank page since data_pdf is null. the data_pdf is content html from parent component referring by ref in div tag. below is my code

  1. Parent component:
    <!-- <template>
    <v-container>
    <div ref="section_trial_balance" id="tblData">
           <table>
                        <tr class="pa-2">
                            <th style="width: 500px; text-align: center;">Description</th>
                        </tr>
                        <tr class="pa-2 tr0">
                            <td class="pa-2 td0">{{0}}</td>
                        </tr>
            <table>
    </div> 
    <SideBarRight @clicked="onClickChild" :fromdate="from_date" :todate="to_date" :repno="rep_no" :data_excel="t_balance" :tableId="'tblData'" :data_pdf="this.$refs.section_trial_balance"></SideBarRight>
    </v-container>
    </template>   -->
    data: () => ({
           trial_balance: []
    })
  2. Child component(SideBar-Right):
    <template>
       <div>
        <vue-html2pdf
          :show-layout="false"
          :float-layout="false"
          :enable-download="true"
          :preview-modal="true"
          :paginate-elements-by-height="1100"
          :pdf-quality="2"
          :manual-pagination="true"
          pdf-format="a4"
          pdf-orientation="portrait"
          pdf-content-width="800px"
          @hasStartedGeneration="hasStartedGeneration()"
          @hasGenerated="hasGenerated($event)"
          ref="html2Pdf"
          filename="mcfin_filename"
          <section slot="pdf-content">
              <v-container>
                     <v-card v-html="html_doc"></v-card>
               </v-container>
          </section>
        </vue-html2pdf>
      </div>
    </template>
    import VueHtml2pdf from 'vue-html2pdf'
    export default {
    name: 'side-bar-right',
    components: {
       VueHtml2pdf
    },
    props: ['data_excel', 'tableId','data_pdf','repno', 'to_date'],
    data () {
      return {
        pdf_filename: '',
        html_doc: '',
        }
     }
    methods: {
      exportPdf(){
        console.log("PDF:", this.data_pdf)      // this gives null when no data generated and not print layout <table>
        this.html_doc = this.data_pdf.outerHTML 
        this.$refs.html2Pdf.generatePdf()
      },
    }

    jason.package: "sass": "^1.56.1", "sass-loader": "^8.0.2", "vue": "^2.6.12", "vue-loader": "^15.9.5", "vue-template-compiler": "^2.6.10" "vue-html2pdf": "^1.8.0", "vuetify": "^2.6.12", "vue-router": "^3.5.1", "vuex": "^3.6.2",

And handle event gives some errors Please help !!!!

Amkha commented 1 year ago

not visible either here....