1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
toPdf = function ( t, e, options ) { var i = this; var dtd = $.Deferred(); var isDownload = true; if ( this.printPanels.length ) { const canvas = document.createElement( 'canvas' ) var scale = 2 var r = o.a.mm.toPt( this.printPanels[0].width ), a = o.a.mm.toPt( this.printPanels[0].height ); var w = o.a.pt.toPx( r ); canvas.width = w * scale canvas.style.width = `${w}px` document.body.appendChild( canvas ) var p = $.extend( { scale: scale, width: o.a.pt.toPx( r ), x: 0, y: 0, useCORS: !0, canvas: canvas, }, options || {} ), s = new jsPDF( { orientation: 1 == this.getOrient( 0 ) ? "portrait" : "landscape", unit: "pt", format: this.printPanels[0].paperType ? this.printPanels[0].paperType.toLocaleLowerCase() : [r, a] } ), l = this.getHtml( t, options ); if ( options && undefined != options.isDownload ) { isDownload = options.isDownload } this.createTempContainer(); var u = this.getTempContainer(); this.svg2canvas( l ), u.html( l[0] ); canvas.height = l[0].offsetHeight * scale canvas.style.height = `${l[0].offsetHeight}px` var d = u.find( ".hiprint-printPanel .hiprint-printPaper" ).length; $( l ).css( "position:fixed" ), html2canvas( l[0], p ).then( function ( t ) { var n = t.getContext( "2d" ); n.mozImageSmoothingEnabled = !1, n.webkitImageSmoothingEnabled = !1, n.msImageSmoothingEnabled = !1, n.imageSmoothingEnabled = !1; canvas.remove();
for ( var o = t.toDataURL( "image/jpeg" ), p = 0; p < d; p++ ) { s.addImage( o, "JPEG", 0, 0 - p * a, r, d * a ), p < d - 1 && s.addPage(); } if ( isDownload ) { i.removeTempContainer(), e.indexOf( ".pdf" ) > -1 ? s.save( e ) : s.save( e + ".pdf" ); } else { i.removeTempContainer(); let type = options.type || 'blob'; var pdfFile = s.output( type ); dtd.resolve( pdfFile ); } } ); } return dtd.promise(); }
|