PageSourceSearch

https://www.toscananovecento.it/wp-content/plugins/pdf-print/js/front-script.js

js toscananovecento.it collected 2026-10-02 08:07:49 UTC 7,377 bytes, 153 lines download raw bytes

1var beforeImageToPdf, afterImageToPdf;
2
3/* Image of page to PDF */
4function imageToPdf() {
5    ( function( $ ) {
6
7        var deferreds = [];
8        var fileSettings = {
9            'pageSize': pdfprnt_file_settings.page_size.toLowerCase(),
10            'marginLeft': Number( pdfprnt_file_settings.margin_left ),
11            'marginRight': Number( pdfprnt_file_settings.margin_right ),
12            'marginBottom': Number( pdfprnt_file_settings.margin_bottom ),
13            'marginTop': Number( pdfprnt_file_settings.margin_top ),
14            'fileAction': pdfprnt_file_settings.file_action,
15            'fileName': pdfprnt_file_settings.file_name
16        };
17
18        var pdf = new jsPDF( 'portrait', 'px', fileSettings['pageSize'] );
19        var width = pdf.internal.pageSize.getWidth();
20        var height = pdf.internal.pageSize.getHeight();
21        // add to page Header and Footer
22        function addImageCustom( canvas, imgWidth, imgHeight ) {
23            pdf.addImage( canvas.toDataURL('image/jpeg', 1.0 ), 'JPEG',
24                fileSettings['marginLeft'],
25                fileSettings['marginTop'],
26                imgWidth, imgHeight
27            );
28        }
29
30        window.scrollTo(0, 0);
31        if ( 'undefined' != typeof beforeImageToPdf ) {
32            beforeImageToPdf();
33        }
34        /* hide default wp panel */
35        document.getElementById("wpadminbar") ? document.getElementById("wpadminbar").style.display = "none" : '';
36
37        var deferred = $.Deferred();
38        deferreds.push( deferred.promise() );
39        var canvasTop, canvasBottom;
40        generateCanvas( 'body', pdf, deferred );
41
42        function generateCanvas( selector, pdf, deferred ) {
43            html2canvas( document.querySelector( 'body' ) ).then( canvas => {
44                var contentWidth = canvas.width;
45                var contentHeight = canvas.height;
46                var headerSize = fileSettings['marginTop'] + fileSettings['marginBottom'];
47                var imgHeaderSize = ( contentWidth / width * headerSize );
48                // The height of the canvas which one pdf page can show;
49                var pageHeight = contentWidth / width * height;
50
51                // the height of canvas that haven't render to pdf
52                var leftHeight = contentHeight;
53                var imgWidth = width - fileSettings['marginLeft'] - fileSettings['marginRight'];
54                var imgHeight =  width / contentWidth * contentHeight - headerSize;
55
56                if ( ( leftHeight + headerSize ) < pageHeight ) {
57                    addImageCustom( canvas, imgWidth, imgHeight + headerSize );
58                } else {
59                    var countPages = Math.ceil(leftHeight / pageHeight );
60                    var leftHeightAfter = ( countPages * headerSize ) + leftHeight;
61
62                    var canvasNew = document.createElement('canvas');
63                    canvasNew.width = contentWidth;
64                    //var theColorBody = $('body').css("background-color");
65                    var row = 0;
66                    for ( var i = 0; i < countPages - 1; i++ ) {
67                        canvasNew.height = pageHeight - imgHeaderSize;
68                        var context = canvasNew.getContext('2d');
69                        context.drawImage( canvas, 0, i * -pageHeight + row );
70                        imgHeight = ( width / contentWidth * pageHeight - headerSize );
71                        let n = 0;
72                        // var imgData = context.getImageData( fileSettings['marginLeft'], 0, contentWidth - fileSettings['marginRight'] - fileSettings['marginLeft'], pageHeight );
73                        // let n = 1;
74                        // let j = imgData.data.length - ( contentWidth - fileSettings['marginRight'] - fileSettings['marginLeft'] ) * 4 * n;
75                        // let rgb;
76                        // let lastPx = imgData.data.length;
77                        // while ( j != lastPx ) {
78                        //     rgb = 'rgb(' + imgData.data[j] + ', ' + imgData.data[j + 1] + ', ' + imgData.data[j + 2] + ')';
79                        //     j += 4;
80                        //     if ( rgb != theColorBody ) {
81                        //         n++;
82                        //         j = imgData.data.length - ( contentWidth - fileSettings['marginRight'] - fileSettings['marginLeft'] ) * 4 * n;
83                        //         lastPx = imgData.data.length - ( contentWidth - fileSettings['marginRight'] - fileSettings['marginLeft'] ) * 4 * ( n - 1 );
84                        //     } else if ( n == 50 ) {
85                        //         break;
86                        //     }
87                        // }
88                        canvasNew.height = pageHeight - n;
89                        context = canvasNew.getContext('2d');
90                        context.drawImage( canvas, 0, i * -pageHeight + row );
91                        addImageCustom( canvasNew, imgWidth, imgHeight );
92                        leftHeight -= pageHeight;
93                        pdf.addPage();
94                        row = row + n;
95                    }
96
97                    leftHeightAfter += row;
98                    var countPagesAfter = Math.ceil( leftHeightAfter / pageHeight );
99                    if ( countPagesAfter != countPages ) {
100
101                        canvasNew.height = pageHeight - imgHeaderSize;
102                        context = canvasNew.getContext('2d');
103                        context.drawImage( canvas, 0, i * -pageHeight + row );
104                        addImageCustom( canvasNew, imgWidth, imgHeight );
105
106                        pdf.addPage();
107                        i++;
108                        leftHeight -= pageHeight;
109                        row += imgHeaderSize;
110                    }
111
112                    canvasNew.height = leftHeight + row;
113                    context.drawImage( canvas, 0, i * -pageHeight + row );
114                    imgHeightLast = width / contentWidth * canvasNew.height;
115                    addImageCustom( canvasNew, imgWidth, imgHeightLast );
116
117                }
118                deferred.resolve();
119            });
120        }
121
122        if ( 'undefined' != typeof afterImageToPdf ) {
123            afterImageToPdf();
124        }
125        /* show default wp panel */
126        document.getElementById("wpadminbar") ? document.getElementById("wpadminbar").style.display = "block" : '';
127
128        // executes after adding all images
129        $.when.apply( $, deferreds ).then( function() {
130            if ( 'open' == fileSettings['fileAction'] ) {
131                pdf.setProperties({
132                    title: fileSettings['fileName']
133                });
134                //pdf.autoPrint();
135                window.open( pdf.output('bloburl') );
136                /*  IFRAME
137                var string = pdf.output('datauristring');
138                var iframe = "<head><style>*{margin: 0; padding: 0;}</style><title>" + fileSettings['fileName'] + "</title></head>" +
139                    "<body><iframe width='100%' height='1000px' src='" + string + "'></iframe></body>"
140
141                var x = window.open();
142                x.document.open();
143                x.document.write( iframe );
144                x.document.close();*/
145
146                //pdf.output( 'dataurlnewwindow' );
147            } else {
148                pdf.save( fileSettings['fileName'] );
149            }
150        });
151
152    } )( jQuery );
153}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.