PluginProbe
PDF & Print by BestWebSoft – WordPress Posts and Pages PDF Generator Plugin / 2.4.2
PDF & Print by BestWebSoft – WordPress Posts and Pages PDF Generator Plugin v2.4.2
trunk 1.5 1.6 1.7 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.1 All 71 releases
← All changes | js/front-script.js +22 -52 trunk2.4.2 View file →
@@ -1,22 +1,12 @@
1 1 var beforeImageToPdf, afterImageToPdf;
2 2
3 3 /* Image of page to PDF */
4 -function imageToPdf( id = 0 ) {
4 +function imageToPdf() {
5 5 ( function( $ ) {
6 6
7 7 window.scrollTo( 0, 0 );
8 8
9 - if ( '1' == pdfprnt_file_settings.count_generation ) {
10 - $.ajax( {
11 - url: pdfprnt_file_settings.ajaxurl,
12 - type: "POST",
13 - data: { action: 'pdfprnt_pdf_count', pdfprnt_ajax_nonce: pdfprnt_file_settings.ajax_nonce, id: id },
14 - success: function() {
15 - }
16 - } );
17 - }
18 -
19 9 var deferreds = [];
20 10 var fileSettings = {
21 11 'pageSize': pdfprnt_file_settings.page_size.toLowerCase(),
22 12 'marginLeft': Number( pdfprnt_file_settings.margin_left ),
@@ -29,9 +19,9 @@
29 19
30 20 var pdf = new jsPDF( 'portrait', 'px', fileSettings['pageSize'] );
31 21 var width = pdf.internal.pageSize.getWidth();
32 22 var height = pdf.internal.pageSize.getHeight();
33 - /* add to page Header and Footer */
23 + // add to page Header and Footer
34 24 function addImageCustom( canvas, imgWidth, imgHeight ) {
35 25 pdf.addImage( canvas.toDataURL('image/jpeg', 1.0 ), 'JPEG',
36 26 fileSettings['marginLeft'],
37 27 fileSettings['marginTop'],
@@ -38,23 +28,8 @@
38 28 imgWidth, imgHeight
39 29 );
40 30 }
41 31
42 - let additionalHiddenSelectors = [];
43 - if ( pdfprnt_file_settings.hide_classes ) {
44 - additionalHiddenSelectors = pdfprnt_file_settings.hide_classes.split( ',' ).map( cls => cls.trim() ).filter( cls => cls );
45 - }
46 -
47 - const elementsToHideExisting = [...additionalHiddenSelectors];
48 - const hiddenElements = [];
49 - elementsToHideExisting.forEach( selector => {
50 - const elements = document.querySelectorAll( selector );
51 - elements.forEach( el => {
52 - hiddenElements.push({ el, parent: el.parentNode, nextSibling: el.nextSibling });
53 - el.style.display = 'none';
54 - });
55 - });
56 -
57 32 window.scrollTo(0, 0);
58 33 if ( 'undefined' != typeof beforeImageToPdf ) {
59 34 beforeImageToPdf();
60 35 }
@@ -71,12 +46,12 @@
71 46 var contentWidth = canvas.width;
72 47 var contentHeight = canvas.height;
73 48 var headerSize = fileSettings['marginTop'] + fileSettings['marginBottom'];
74 49 var imgHeaderSize = ( contentWidth / width * headerSize );
75 - /* The height of the canvas which one pdf page can show; */
50 + // The height of the canvas which one pdf page can show;
76 51 var pageHeight = contentWidth / width * height;
77 52
78 - /* the height of canvas that haven't render to pdf */
53 + // the height of canvas that haven't render to pdf
79 54 var leftHeight = contentHeight;
80 55 var imgWidth = width - fileSettings['marginLeft'] - fileSettings['marginRight'];
81 56 var imgHeight = width / contentWidth * contentHeight - headerSize;
82 57
@@ -87,9 +62,9 @@
87 62 var leftHeightAfter = ( countPages * headerSize ) + leftHeight;
88 63
89 64 var canvasNew = document.createElement('canvas');
90 65 canvasNew.width = contentWidth;
91 - /* var theColorBody = $('body').css("background-color"); */
66 + //var theColorBody = $('body').css("background-color");
92 67 var row = 0;
93 68 for ( var i = 0; i < countPages - 1; i++ ) {
94 69 canvasNew.height = pageHeight - imgHeaderSize;
95 70 var context = canvasNew.getContext('2d');
@@ -95,24 +70,24 @@
95 70 var context = canvasNew.getContext('2d');
96 71 context.drawImage( canvas, 0, i * -pageHeight + row );
97 72 imgHeight = ( width / contentWidth * pageHeight - headerSize );
98 73 let n = 0;
99 - /* var imgData = context.getImageData( fileSettings['marginLeft'], 0, contentWidth - fileSettings['marginRight'] - fileSettings['marginLeft'], pageHeight );
100 - let n = 1;
101 - let j = imgData.data.length - ( contentWidth - fileSettings['marginRight'] - fileSettings['marginLeft'] ) * 4 * n;
102 - let rgb;
103 - let lastPx = imgData.data.length;
104 - while ( j != lastPx ) {
105 - rgb = 'rgb(' + imgData.data[j] + ', ' + imgData.data[j + 1] + ', ' + imgData.data[j + 2] + ')';
106 - j += 4;
107 - if ( rgb != theColorBody ) {
108 - n++;
109 - j = imgData.data.length - ( contentWidth - fileSettings['marginRight'] - fileSettings['marginLeft'] ) * 4 * n;
110 - lastPx = imgData.data.length - ( contentWidth - fileSettings['marginRight'] - fileSettings['marginLeft'] ) * 4 * ( n - 1 );
111 - } else if ( n == 50 ) {
112 - break;
113 - }
114 - } */
74 + // var imgData = context.getImageData( fileSettings['marginLeft'], 0, contentWidth - fileSettings['marginRight'] - fileSettings['marginLeft'], pageHeight );
75 + // let n = 1;
76 + // let j = imgData.data.length - ( contentWidth - fileSettings['marginRight'] - fileSettings['marginLeft'] ) * 4 * n;
77 + // let rgb;
78 + // let lastPx = imgData.data.length;
79 + // while ( j != lastPx ) {
80 + // rgb = 'rgb(' + imgData.data[j] + ', ' + imgData.data[j + 1] + ', ' + imgData.data[j + 2] + ')';
81 + // j += 4;
82 + // if ( rgb != theColorBody ) {
83 + // n++;
84 + // j = imgData.data.length - ( contentWidth - fileSettings['marginRight'] - fileSettings['marginLeft'] ) * 4 * n;
85 + // lastPx = imgData.data.length - ( contentWidth - fileSettings['marginRight'] - fileSettings['marginLeft'] ) * 4 * ( n - 1 );
86 + // } else if ( n == 50 ) {
87 + // break;
88 + // }
89 + // }
115 90 canvasNew.height = pageHeight - n;
116 91 context = canvasNew.getContext('2d');
117 92 context.drawImage( canvas, 0, i * -pageHeight + row );
118 93 addImageCustom( canvasNew, imgWidth, imgHeight );
@@ -151,13 +126,8 @@
151 126 }
152 127 /* show default wp panel */
153 128 document.getElementById("wpadminbar") ? document.getElementById("wpadminbar").style.display = "block" : '';
154 129
155 - hiddenElements.forEach( ({ el, parent, nextSibling }) => {
156 - parent.insertBefore( el, nextSibling );
157 - el.style.display = '';
158 - });
159 -
160 130 // executes after adding all images
161 131 $.when.apply( $, deferreds ).then( function() {
162 132 if ( 'open' == fileSettings['fileAction'] ) {
163 133 pdf.setProperties({
@@ -174,9 +144,9 @@
174 144 x.document.open();
175 145 x.document.write( iframe );
176 146 x.document.close();*/
177 147
178 - /* pdf.output( 'dataurlnewwindow' ); */
148 + //pdf.output( 'dataurlnewwindow' );
179 149 } else {
180 150 pdf.save( fileSettings['fileName'] );
181 151 }
182 152 });