dynamicweb2/static/hosting/js/html2pdf.min.js
2023-11-22 15:42:05 +05:30

6 lines
No EOL
6.3 KiB
JavaScript

/**
* html2pdf.js v0.8.2
* Copyright (c) 2017 Erik Koopmans
* Released under the MIT License.
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("es6-promise/auto"),require("jspdf"),require("html2canvas")):"function"==typeof define&&define.amd?define(["es6-promise/auto","jspdf","html2canvas"],t):e.html2pdf=t(null,e.jsPDF,e.html2canvas)}(this,function(e,t,n){"use strict";t=t&&t.hasOwnProperty("default")?t.default:t,n=n&&n.hasOwnProperty("default")?n.default:n;var a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};t.getPageSize=function(e,t,n){if("object"===(void 0===e?"undefined":a(e))){var i=e;e=i.orientation,t=i.unit||t,n=i.format||n}t=t||"mm",n=n||"a4",e=(""+(e||"P")).toLowerCase();var r=(""+n).toLowerCase(),o={a0:[2383.94,3370.39],a1:[1683.78,2383.94],a2:[1190.55,1683.78],a3:[841.89,1190.55],a4:[595.28,841.89],a5:[419.53,595.28],a6:[297.64,419.53],a7:[209.76,297.64],a8:[147.4,209.76],a9:[104.88,147.4],a10:[73.7,104.88],b0:[2834.65,4008.19],b1:[2004.09,2834.65],b2:[1417.32,2004.09],b3:[1000.63,1417.32],b4:[708.66,1000.63],b5:[498.9,708.66],b6:[354.33,498.9],b7:[249.45,354.33],b8:[175.75,249.45],b9:[124.72,175.75],b10:[87.87,124.72],c0:[2599.37,3676.54],c1:[1836.85,2599.37],c2:[1298.27,1836.85],c3:[918.43,1298.27],c4:[649.13,918.43],c5:[459.21,649.13],c6:[323.15,459.21],c7:[229.61,323.15],c8:[161.57,229.61],c9:[113.39,161.57],c10:[79.37,113.39],dl:[311.81,623.62],letter:[612,792],"government-letter":[576,756],legal:[612,1008],"junior-legal":[576,360],ledger:[1224,792],tabloid:[792,1224],"credit-card":[153,243]};switch(t){case"pt":l=1;break;case"mm":l=72/25.4;break;case"cm":l=72/2.54;break;case"in":l=72;break;case"px":l=.75;break;case"pc":case"em":l=12;break;case"ex":var l=6;break;default:throw"Invalid unit: "+t}if(o.hasOwnProperty(r))var c=o[r][1]/l,d=o[r][0]/l;else try{var c=n[1],d=n[0]}catch(e){throw new Error("Invalid format: "+n)}if("p"===e||"portrait"===e){if(e="p",d>c){s=d;d=c,c=s}}else{if("l"!==e&&"landscape"!==e)throw"Invalid orientation: "+e;if(e="l",c>d){var s=d;d=c,c=s}}return{width:d,height:c,unit:t,k:l}};var i=function(e){var t=void 0===e?"undefined":a(e);return"undefined"===t?"undefined":"string"===t||e instanceof String?"string":"number"===t||e instanceof Number?"number":"function"===t||e instanceof Function?"function":e&&e.constructor===Array?"array":e&&1===e.nodeType?"element":"object"===t?"object":"unknown"},r=function(e,t){var n=document.createElement(e);if(t.className&&(n.className=t.className),t.innerHTML){n.innerHTML=t.innerHTML;for(var a=n.getElementsByTagName("script"),i=a.length;i-- >0;null)a[i].parentNode.removeChild(a[i])}for(var r in t.style)n.style[r]=t.style[r];return n},o=function(e,t){var n={};for(var a in e)n[a]=72*e[a]/96/t;return n},l=function e(a,r){r="object"===i(r)?r:{};var a=e.parseInput(a,r),l=t.getPageSize(r.jsPDF);l.inner={width:l.width-r.margin[1]-r.margin[3],height:l.height-r.margin[0]-r.margin[2]},l.inner.ratio=l.inner.height/l.inner.width;var c=e.makeContainer(a,l),d=c.parentElement;if(r.enableLinks){r.links=[];var s=c.querySelectorAll("a"),m=o(c.getBoundingClientRect(),l.k);Array.prototype.forEach.call(s,function(e){for(var t=e.getClientRects(),n=0;n<t.length;n++){var a=o(t[n],l.k);a.left-=m.left,a.top-=m.top,r.links.push({el:e,clientRect:a})}})}var h=r.html2canvas.onrendered||function(){};delete r.html2canvas.onrendered;n(c,r.html2canvas).then(function(t){h(t),document.body.removeChild(d),e.makePDF(t,l,r)})};return l.parseInput=function(e,t){switch(t.jsPDF=t.jsPDF||{},t.html2canvas=t.html2canvas||{},t.filename=t.filename&&"string"===i(t.filename)?t.filename:"file.pdf",t.enableLinks=!t.hasOwnProperty("enableLinks")||t.enableLinks,t.image=t.image||{},t.image.type=t.image.type||"jpeg",t.image.quality=t.image.quality||.95,i(t.margin)){case"undefined":t.margin=0;case"number":t.margin=[t.margin,t.margin,t.margin,t.margin];break;case"array":if(2===t.margin.length&&(t.margin=[t.margin[0],t.margin[1],t.margin[0],t.margin[1]]),4===t.margin.length)break;default:throw"Invalid margin array."}if(!e)throw"Missing source element or string.";if("string"===i(e))e=r("div",{innerHTML:e});else{if("element"!==i(e))throw"Invalid source - please specify an HTML Element or string.";e=function e(t,n){for(var a=3===t.nodeType?document.createTextNode(t.nodeValue):t.cloneNode(!1),i=t.firstChild;i;i=i.nextSibling)!0!==n&&1===i.nodeType&&"SCRIPT"===i.nodeName||a.appendChild(e(i,n));return 1===t.nodeType&&("CANVAS"===t.nodeName?(a.width=t.width,a.height=t.height,a.getContext("2d").drawImage(t,0,0)):"TEXTAREA"!==t.nodeName&&"SELECT"!==t.nodeName||(a.value=t.value),a.addEventListener("load",function(){a.scrollTop=t.scrollTop,a.scrollLeft=t.scrollLeft},!0)),a}(e,t.html2canvas.javascriptEnabled)}return e},l.makeContainer=function(e,t){var n={position:"fixed",overflow:"hidden",zIndex:1e3,left:0,right:0,bottom:0,top:0,backgroundColor:"rgba(0,0,0,0.8)"},a={position:"absolute",width:t.inner.width+t.unit,left:0,right:0,top:0,height:"auto",margin:"auto",backgroundColor:"white"};n.opacity=0;var i=r("div",{className:"html2pdf__overlay",style:n}),o=r("div",{className:"html2pdf__container",style:a});o.appendChild(e),i.appendChild(o),document.body.appendChild(i);var l=e.querySelectorAll(".html2pdf__page-break"),c=t.inner.height*t.k/72*96;return Array.prototype.forEach.call(l,function(e){e.style.display="block";var t=e.getBoundingClientRect();e.style.height=c-t.top%c+"px"},this),o},l.makePDF=function(e,n,a){e.getContext("2d");var i=e.height,r=Math.floor(e.width*n.inner.ratio),o=Math.ceil(i/r),l=document.createElement("canvas"),c=l.getContext("2d"),d=n.inner.height;l.width=e.width,l.height=r;for(var s=new t(a.jsPDF),m=0;m<o;m++){m===o-1&&(l.height=i%r,d=l.height*n.inner.width/l.width);var h=l.width,f=l.height;c.fillStyle="white",c.fillRect(0,0,h,f),c.drawImage(e,0,m*r,h,f,0,0,h,f),m&&s.addPage();var u=l.toDataURL("image/"+a.image.type,a.image.quality);if(s.addImage(u,a.image.type,a.margin[1],a.margin[0],n.inner.width,d),a.enableLinks){var g=m*n.inner.height;a.links.forEach(function(e){if(e.clientRect.top>g&&e.clientRect.top<g+n.inner.height){var t=a.margin[1]+e.clientRect.left,i=a.margin[0]+e.clientRect.top-g;s.link(t,i,e.clientRect.width,e.clientRect.height,{url:e.el.href})}})}}s.save(a.filename)},l});