Search code examples
pdfsizejspdf

jspdf Checking pdf file size


I want to check pdf file size with jspdf.js script. I need to display this on the screen before downloading file. Are there any possibilities?

function demoFromHTML(x = false) {
                    var pdf = new jsPDF('p', 'pt', 'letter');
                    source = $('#print')[0];

                    specialElementHandlers = {
                        '#bypassme': function (element, renderer) {
                            return true
                        }
                    };
                    margins = {
                        top: 80,
                        bottom: 60,
                        left: 40,
                        width: 522
                    };
                    pdf.fromHTML(
                        source, 
                        margins.left, 
                        margins.top, { 
                            'width': margins.width,
                            'elementHandlers': specialElementHandlers
                        },

                        function (dispose) {

                            if(x){
                                pdf.output('dataurlnewwindow');
                            }else{
                                pdf.save('<?php the_title() ?>.pdf');
                            }
                        }, margins
                    );
                }

Solution

  • I've found a solution, It was pretty simple. Maybe someone will use it:

    pdf.output().length;