1 | |
---|
2 | var __PDF_DOC, |
---|
3 | __CURRENT_PAGE, |
---|
4 | __TOTAL_PAGES, |
---|
5 | __PAGE_RENDERING_IN_PROGRESS = 0, |
---|
6 | __CANVAS = $('#pdf-canvas3').get(0), |
---|
7 | __CANVAS_CTX = __CANVAS.getContext('2d'), |
---|
8 | __idd = "", |
---|
9 | __NUMBER = 0, |
---|
10 | __CLICKK = 0; |
---|
11 | |
---|
12 | $("#pdf-canvas3").hide(); |
---|
13 | |
---|
14 | function showPDF3(pdf_url) { |
---|
15 | $("#pdf-loader3").show(); |
---|
16 | |
---|
17 | PDFJS.getDocument({ url: pdf_url }).then(function(pdf_doc) { |
---|
18 | __PDF_DOC = pdf_doc; |
---|
19 | __TOTAL_PAGES = __PDF_DOC.numPages; |
---|
20 | |
---|
21 | // Hide the pdf loader and show pdf container in HTML |
---|
22 | $("#pdf-loader3").hide(); |
---|
23 | $("#pdf-contents3").show(); |
---|
24 | $("#pdf-total-pages3").text(__TOTAL_PAGES); |
---|
25 | |
---|
26 | // Show the |
---|
27 | showPage3(1); |
---|
28 | |
---|
29 | }).catch(function(error) { |
---|
30 | // If error re-show the upload button |
---|
31 | $("#pdf-loadere").hide(); |
---|
32 | $("#upload-buttone").show(); |
---|
33 | |
---|
34 | alert(error.message); |
---|
35 | });; |
---|
36 | } |
---|
37 | |
---|
38 | function showPage3(page_no) { |
---|
39 | __PAGE_RENDERING_IN_PROGRESS = 1; |
---|
40 | __CURRENT_PAGE = page_no; |
---|
41 | |
---|
42 | // Disable Prev & Next buttons while page is being loaded |
---|
43 | $("#pdf-next3, #pdf-prev3").attr('disabled', 'disabled'); |
---|
44 | |
---|
45 | // While page is being rendered hide the canvas and show a loading message |
---|
46 | $("#pdf-canvas3").hide(); |
---|
47 | $("#page-loader3").show(); |
---|
48 | |
---|
49 | // Update current page in HTML |
---|
50 | $("#pdf-current-page3").text(page_no); |
---|
51 | |
---|
52 | |
---|
53 | // Fetch the page |
---|
54 | __PDF_DOC.getPage(page_no).then(function(page) { |
---|
55 | // As the canvas is of a fixed width we need to set the scale of the viewport accordingly |
---|
56 | |
---|
57 | |
---|
58 | var scale_required = __CANVAS.width / page.getViewport(1).width; |
---|
59 | |
---|
60 | // Get viewport of the page at required scale |
---|
61 | var viewport = page.getViewport(scale_required); |
---|
62 | |
---|
63 | // Set canvas height |
---|
64 | |
---|
65 | __CANVAS.height = viewport.height; |
---|
66 | |
---|
67 | |
---|
68 | var renderContext = { |
---|
69 | canvasContext: __CANVAS_CTX, |
---|
70 | viewport: viewport |
---|
71 | }; |
---|
72 | |
---|
73 | |
---|
74 | // Render the page contents in the canvas |
---|
75 | page.render(renderContext).then(function() { |
---|
76 | __PAGE_RENDERING_IN_PROGRESS = 0; |
---|
77 | |
---|
78 | // Re-enable Prev & Next buttons |
---|
79 | $("#pdf-next3, #pdf-prev3").removeAttr('disabled'); |
---|
80 | |
---|
81 | // Show the canvas and hide the page loader |
---|
82 | $("#page-loader3").hide(); |
---|
83 | |
---|
84 | __idd = __CANVAS.toDataURL() |
---|
85 | |
---|
86 | var viewdimen = page.getViewport(1); |
---|
87 | console.log( "Width: " + viewdimen.width + ", Height: " + viewdimen.height); |
---|
88 | |
---|
89 | $("#container2").attr("style", "background-image: url('"+__idd+"');background-size: cover; background-repeat: no-repeat; height:"+viewdimen.height+"px; width:"+viewdimen.width+"px"); |
---|
90 | |
---|
91 | }); |
---|
92 | }); |
---|
93 | |
---|
94 | } |
---|
95 | |
---|
96 | |
---|
97 | // Previous page of the PDF |
---|
98 | $("#pdf-prev3").on('click', function() { |
---|
99 | if(__CURRENT_PAGE != 1) |
---|
100 | showPage3(--__CURRENT_PAGE); |
---|
101 | }); |
---|
102 | |
---|
103 | // Next page of the PDF |
---|
104 | $("#pdf-next3").on('click', function() { |
---|
105 | |
---|
106 | if(__CURRENT_PAGE != __TOTAL_PAGES) |
---|
107 | |
---|
108 | showPage3(++__CURRENT_PAGE); |
---|
109 | |
---|
110 | }); |
---|
111 | |
---|
112 | |
---|
113 | |
---|
114 | $("#upload-Normal").on('click', function() { |
---|
115 | $("#pdf-main-container").hide(); |
---|
116 | $("#pdf-main-container2").show(); |
---|
117 | |
---|
118 | $("#file-to-normal").trigger('click'); |
---|
119 | |
---|
120 | }); |
---|
121 | |
---|
122 | |
---|
123 | $("#file-to-normal").on('change', function() { |
---|
124 | |
---|
125 | // Validate whether PDF |
---|
126 | if(['application/pdf'].indexOf($("#file-to-normal").get(0).files[0].type) == -1) { |
---|
127 | alert('Error : Not a PDF'); |
---|
128 | return; |
---|
129 | } |
---|
130 | |
---|
131 | showPDF3(URL.createObjectURL($("#file-to-normal").get(0).files[0])); |
---|
132 | |
---|
133 | if (__CLICKK == 0){ |
---|
134 | $('#firmar-doc-noVisible').show(); |
---|
135 | __CLICKK += 1; |
---|
136 | } |
---|
137 | }); |
---|