taron133
2020-10-26 aa8d874c8a3287d41d26566ae32b6ed8d4557ff9
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<script src="//mozilla.github.io/pdf.js/build/pdf.js"></script>
 
<div class = "container">
    <form action="index.php?state=0&confirmGDPR=1" method="post" class="form-signin">
        {if $logo}<div><img src="images/{$logo}" alt="logo" title="logo" class="logo"></div>{/if}
        {if $flags_view}
            <div>
                <a href="index.php?lng=3" title="German" style="margin-left:5px;padding:0px;"><img src="images/flag_DEU.png" style="width:25px;" alt="German" /></a>
                <a href="index.php?lng=2" title="English"><img src="images/flag_ENG.png" style="width:25px;" alt="English" /></a>
                <a href="index.php?lng=1" title="Russian"><img src="images/flag_RUS.png" style="width:25px;" alt="Russian" /></a>
                <a href="index.php?lng=4" title="French"><img src="images/flag_FRA.png" style="width:25px;" alt="French" /></a>
                <!--a href="index.php?lng=5" title="Italian"><img src="images/flag_ITA.png" style="width:25px;" alt="Italian" /></a-->
                <a href="index.php?lng=5" title="Poland"><img src="images/flag_POL.png" style="width:25px;" alt="Poland" /></a>
                <!--a href="index.php?lng=6" title="Spanish"><img src="images/flag_SPA.png" style="width:25px;" alt="Spanish" /></a-->
                <a href="index.php?lng=6" title="עברית"><img src="images/flag_ISR.png" style="width:25px;" alt="עברית" /></a>
            </div>
        {/if}
 
        <hr class="colorgraph"><br>
        <table>
            <tr>
                <td>
                    <div style="border: 1px solid black;direction: ltr; overflow: scroll; height: 350px; width: 350px" id='pdf-viewer'></div>
                </td>
            </tr>
            <tr>
                <td><input class="btn btn-lg btn-primary btn-block" type="submit" style="float: right;width:100px;" value="Schließen" /></td>
            </tr>
        </table>
    </form>
</div>
 
 
{literal}
    <script>
        // If absolute URL from the remote server is provided, configure the CORS
        // header on that server.
        var url = 'getfile.php?ppolicy=1&id=9999';
 
        // Loaded via <script> tag, create shortcut to access PDF.js exports.
        var pdfjsLib = window['pdfjs-dist/build/pdf'];
 
        // The workerSrc property shall be specified.
        pdfjsLib.GlobalWorkerOptions.workerSrc = '//mozilla.github.io/pdf.js/build/pdf.worker.js';
 
        var pdfDoc = null,
            pageNum = 1,
            pageRendering = false,
            pageNumPending = null,
            scale = 2,
            //canvas = document.getElementById('the-canvas'),
            canvas = document.getElementById('pdf-viewer')/*,
        ctx = canvas.getContext('2d')*/;
 
        //canvas.style.width = (getClientWidth()-10)+'px';
        //canvas.style.height = (getClientHeight()-120)+'px';
 
        /**
         * Get page info from document, resize canvas accordingly, and render page.
         * @param num Page number.
         */
        function renderPage(num, canvas) {
            pageRendering = true;
            // Using promise to fetch the page
            pdfDoc.getPage(num).then(function(page) {
                var viewport = page.getViewport({scale: scale});
                canvas.height = viewport.height;
                canvas.width = viewport.width;
 
                page.render({canvasContext: canvas.getContext('2d'), viewport: viewport});
 
                // Render PDF page into canvas context
                /*var renderContext = {
                    canvasContext: ctx,
                    viewport: viewport
                };
                var renderTask = page.render(renderContext);
 
                // Wait for rendering to finish
                renderTask.promise.then(function() {
                    pageRendering = false;
                    if (pageNumPending !== null) {
                        // New page rendering is pending
                        renderPage(pageNumPending);
                        pageNumPending = null;
                    }
                });*/
            });
 
            // Update page counters
            //document.getElementById('page_num').textContent = num;
        }
 
        /**
         * If another page rendering in progress, waits until the rendering is
         * finised. Otherwise, executes rendering immediately.
         */
        function queueRenderPage(num) {
            if (pageRendering) {
                pageNumPending = num;
            } else {
                renderPage(num);
            }
        }
 
        /**
         * Displays previous page.
         */
        function onPrevPage() {
            if (pageNum <= 1) {
                //return;
                pageNum = pageNum;
            } else
                pageNum--;
            queueRenderPage(pageNum);
        }
        //document.getElementById('prev').addEventListener('click', onPrevPage);
 
        /**
         * Displays next page.
         */
        function onNextPage() {
            if (pageNum >= pdfDoc.numPages) {
                //return;
                pageNum = pageNum;
            } else
                pageNum++;
            queueRenderPage(pageNum);
        }
        //document.getElementById('next').addEventListener('click', onNextPage);
 
        function onChangeOrientation() {
            //debugger;
            canvas.style.width = (getClientWidth()-10)+'px';
            canvas.style.height = (getClientHeight()-120)+'px';
        }
        //window.addEventListener("orientationchange", onChangeOrientation, false);
 
        /**
         * Asynchronously downloads PDF.
         */
        pdfjsLib.getDocument(url).promise.then(function(pdfDoc_) {
            pdfDoc = pdfDoc_;
            //document.getElementById('page_count').textContent = pdfDoc.numPages;
 
            // Initial/first page rendering
            //renderPage(pageNum);
 
            viewer = document.getElementById('pdf-viewer');
 
            for(page = 1; page <= pdfDoc.numPages; page++) {
                canvas = document.createElement("canvas");
                canvas.className = 'pdf-page-canvas';
                viewer.appendChild(canvas);
                renderPage(page, canvas);
            }
 
            /*for(page = 1; page <= pdfDoc.numPages; page++) {
                canvas = document.createElement("canvas");
                canvas.className = 'pdf-page-canvas';
                canvas.appendChild(canvas);
                renderPage(page, canvas);
            }*/
        });
    </script>
{/literal}