Is it possible to show a spinner while a pdf is created with pdfhtml5

Is it possible to show a spinner while a pdf is created with pdfhtml5

daitdait Posts: 3Questions: 1Answers: 0

Hi,

i wonder if there are some events like 'pdf.create.started' and 'pdf.create.done' to be able to show a spinner in the meantime. I have some Datatables where the creation of a PDF with pdfhtml5 of the buttons extension takes quit long. It would be nice to inform the user, that the creation is still in progress.

Thank you in advance!

Answers

  • allanallan Posts: 63,075Questions: 1Answers: 10,385 Site admin

    Currently this isn't a feature that is built into the library, but it is something I'm keen to add. I'm not sure yet when I'll get a chance to add it, but it is something that should be available in a future version.

    Allan

  • daitdait Posts: 3Questions: 1Answers: 0

    Thank you allan,

    i have tried to insert custom events in buttons.html5.js like this:

    $( document ).trigger( "dtb_createPdfStart" );
    var pdf = window.pdfMake.createPdf( doc );
    $( document ).trigger( "dtb_createPdfEnd" );
    

    However the result is not satisfying. The triggers fire at the very end of the creation process.

    As a workaround in the meantime i have found a hint(https://github.com/bpampuch/pdfmake/issues/280) to speed up the creation of larger PDFs by editing the pdfmake.js:

    function flow(stream) {
      var state = stream._readableState;
      debug('flow', state.flowing);
      if (state.flowing) {
        do {
          var chunk = stream.read(Number.MAX_SAFE_INTEGER); // grab MAX_SAFE_INTEGER bytes
        } while (null !== chunk && state.flowing);
      }
    }
    

    Hope this helps.

  • allanallan Posts: 63,075Questions: 1Answers: 10,385 Site admin

    Cool - hope that gets merged in :-)

    Allan

This discussion has been closed.