source: prototipo_portal_2018/prototipo/static/js/docFirmaNormal.js @ e3349ca

Last change on this file since e3349ca was e3349ca, checked in by José Sulbarán <jsulbaran@…>, 7 years ago

Se agrego firma visible y normal

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