From cb3c726d400e19fba8a2544e8e1decbd6e8eb368 Mon Sep 17 00:00:00 2001 From: Thomas Felber Date: Sat, 20 Jun 2015 18:17:06 -1000 Subject: Improved Signature Placement, Removed unneeded pdf.js UI elements, enabled possibility to sign with server keystore, added possibility to sign pdfs (give as url) by calling pdf.js with appropriate request parameters --- pdf-as-web/src/main/webapp/assets/css/style.css | 1 + pdf-as-web/src/main/webapp/assets/js/dragNdrop.js | 21 ++-- .../src/main/webapp/assets/js/pdf.js/web/app.js | 134 +++++++++++++++------ .../pdf.js/web/images/document_del_signature.png | Bin 0 -> 330 bytes .../web/images/document_del_signature@2x.png | Bin 0 -> 702 bytes .../js/pdf.js/web/images/document_signature.png | Bin 0 -> 417 bytes .../js/pdf.js/web/images/document_signature@2x.png | Bin 0 -> 717 bytes .../main/webapp/assets/js/pdf.js/web/viewer.css | 20 +++ .../main/webapp/assets/js/pdf.js/web/viewer.html | 52 ++++++-- .../src/main/webapp/assets/js/pdf.js/web/viewer.js | 17 ++- 10 files changed, 185 insertions(+), 60 deletions(-) create mode 100644 pdf-as-web/src/main/webapp/assets/js/pdf.js/web/images/document_del_signature.png create mode 100644 pdf-as-web/src/main/webapp/assets/js/pdf.js/web/images/document_del_signature@2x.png create mode 100644 pdf-as-web/src/main/webapp/assets/js/pdf.js/web/images/document_signature.png create mode 100644 pdf-as-web/src/main/webapp/assets/js/pdf.js/web/images/document_signature@2x.png diff --git a/pdf-as-web/src/main/webapp/assets/css/style.css b/pdf-as-web/src/main/webapp/assets/css/style.css index 570230cc..eb5d3e40 100644 --- a/pdf-as-web/src/main/webapp/assets/css/style.css +++ b/pdf-as-web/src/main/webapp/assets/css/style.css @@ -65,6 +65,7 @@ iframe { margin: 0px; height: 2em; text-align: center; + cursor: pointer; } .center { diff --git a/pdf-as-web/src/main/webapp/assets/js/dragNdrop.js b/pdf-as-web/src/main/webapp/assets/js/dragNdrop.js index 31ba841d..04257579 100644 --- a/pdf-as-web/src/main/webapp/assets/js/dragNdrop.js +++ b/pdf-as-web/src/main/webapp/assets/js/dragNdrop.js @@ -1,11 +1,11 @@ +var file = null; + $(document).ready(function() { registerEventListeners(); }); function registerEventListeners() { - - var file = null; var locale = "EN"; var connector = "mobilebku"; @@ -80,11 +80,6 @@ function registerEventListeners() { $("input[name='locale']").bind("change", function(evt) { locale = this.value; - - //REMOVE - alert("Locale"); - alert($("#iFrame").contents().find("#numPages").html()); - //REMOVE }); $("#btnSign").bind("click", function(evt) { @@ -102,13 +97,23 @@ function sign(file, connector, locale) { alert("No file selected"); return } - + var fd = new FormData(); fd.append("source", "internal"); fd.append("pdf-file", file); fd.append("connector", connector); fd.append("locale", locale); + signature_overlay = $("#iFrame").contents().find(".cl_signature"); + if(signature_overlay.length > 0) { + var sig_pos_x = $("#iFrame").contents().find(".cl_signature").attr("data-pos-x"); + var sig_pos_y = $("#iFrame").contents().find(".cl_signature").attr("data-pos-y"); + var sig_pos_p = $("#iFrame").contents().find(".cl_signature").attr("data-page"); + fd.append("sig-pos-x", sig_pos_x); + fd.append("sig-pos-y", sig_pos_y); + fd.append("sig-pos-p", sig_pos_p); + } + $.ajax({ url: "Sign", data: fd, diff --git a/pdf-as-web/src/main/webapp/assets/js/pdf.js/web/app.js b/pdf-as-web/src/main/webapp/assets/js/pdf.js/web/app.js index bb2c89d7..c2173efb 100644 --- a/pdf-as-web/src/main/webapp/assets/js/pdf.js/web/app.js +++ b/pdf-as-web/src/main/webapp/assets/js/pdf.js/web/app.js @@ -1,52 +1,114 @@ -window.addEventListener("message", function (evt) { - var goto_last_page_on_render = false; + +function setFileForParent(file) { + console.log("SettingFileFOrparent"); + if (window.self != window.parent) { + window.parent.file = file; + } +} + +window.addEventListener("message", handlePostMessage, false); + +function handlePostMessage(evt) { var file = evt.data; + console.log(file) + var signature_placed_manually = false; var fileReader = new FileReader(); - var current_page = null; - console.log("child:" + file); - - function rendered(evt) { - console.log(evt); - if(goto_last_page_on_render) { - document.getElementById("lastPage").click(); - return; - } - showSignatureBlock(); - console.log(evt); - current_page = PDFView.page; - document.removeEventListener('textlayerrendered', rendered); - document.addEventListener('textlayerrendered', showSignatureBlock); - } - window.addEventListener('pagechange', showSignatureBlock); - document.addEventListener('textlayerrendered', rendered); - fileReader.onload = function(evt) { var buffer = evt.target.result; var uint8Array = new Uint8Array(buffer); PDFView.open(uint8Array, 0); + $("#placeSignature").bind("click", placeSignature); + $("#secondaryPlaceSignature").bind("click", placeSignature); + $("#delSignature").bind("click", removeSignature); + $("#secondaryDelSignature").bind("click", removeSignature); }; - function showSignatureBlock(evt) { - console.log(evt); - if(PDFViewerApplication.pdfViewer.getPageView(PDFViewerApplication.page - 1).renderingState === RenderingStates.RUNNING) { - return; + fileReader.readAsArrayBuffer(file); +} + +function isSignaturePlaced() { + var signature = $(".cl_signature"); + if(signature.length > 0) { + return true; + } else { + return false; + } +} + +function placeSignature(evt) { + var current_scale = PDFViewerApplication.pdfViewer.currentScale; + var sig_size = Math.floor(96 * current_scale); + var current_page = PDFView.page; + + if(isSignaturePlaced()) { + removeSignature(); + } + + $("#pageContainer"+current_page).prepend("Signature"); + makeSignatureDraggable($(".cl_signature")); +} + +function makeSignatureDraggable(signature) { + var current_page = PDFView.page; + var canvas_height = $("#page" + current_page.toString()).attr("height"); + var current_scale = PDFViewerApplication.pdfViewer.currentScale; + + signature.draggable({ + drag: function() { + var $this = $(this); + var thisPos = $this.position({my: "left bottom"}); + var parentPos = $this.parent().position(); + var x = thisPos.left - parentPos.left; + var y = thisPos.top - parentPos.top; + $(this).attr("data-pos-x", (Math.floor(x / current_scale / (4.0/3.0))).toString()); //width shrink again by 4/3? + $(this).attr("data-pos-y", Math.floor((parseInt(canvas_height) + parentPos.top - (thisPos.top + parentPos.top)) / current_scale / (4.0/3.0)).toString()); //height shrink again by 4/3? + }, + containment: "parent" + }); +} + +function removeSignature() { + if(isSignaturePlaced()) { + $(".cl_signature").remove(); + } +} + +$(document).ready(function() { + //http://localhost:8080/pdf-as-web/assets/js/pdf.js/web/viewer.html?connector=jks&pdfurl=http://www.example.net/pdf.pdf + $.urlParam = function(name){ + var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href); + if(!results) { + return null; + } else { + return results[1] || 0; } - - console.log(document.readyState); - $(".img_signature").remove(); - $("#pageContainer"+PDFView.page).prepend("Signature"); - $(".cl_signature").draggable({ - drag: function() { - - }, - containment: "parent" - }); } - fileReader.readAsArrayBuffer(file); -}, false); + var connector = $.urlParam("connector"); + var pdfurl = $.urlParam("pdfurl"); + + if(!connector || !pdfurl) { + return; + } else { + var fd = new FormData(); + fd.append("source", "internal"); + fd.append("pdf-url", pdfurl); + fd.append("connector", connector); + $.ajax({ + url: "http://localhost:8080/pdf-as-web/Sign", + data: fd, + processData: false, + contentType: false, + type: "POST", + success: function(response) { + $("html").empty(); + $("html").html(response); + } + }); + } +}); diff --git a/pdf-as-web/src/main/webapp/assets/js/pdf.js/web/images/document_del_signature.png b/pdf-as-web/src/main/webapp/assets/js/pdf.js/web/images/document_del_signature.png new file mode 100644 index 00000000..36d6fada Binary files /dev/null and b/pdf-as-web/src/main/webapp/assets/js/pdf.js/web/images/document_del_signature.png differ diff --git a/pdf-as-web/src/main/webapp/assets/js/pdf.js/web/images/document_del_signature@2x.png b/pdf-as-web/src/main/webapp/assets/js/pdf.js/web/images/document_del_signature@2x.png new file mode 100644 index 00000000..e793fbcf Binary files /dev/null and b/pdf-as-web/src/main/webapp/assets/js/pdf.js/web/images/document_del_signature@2x.png differ diff --git a/pdf-as-web/src/main/webapp/assets/js/pdf.js/web/images/document_signature.png b/pdf-as-web/src/main/webapp/assets/js/pdf.js/web/images/document_signature.png new file mode 100644 index 00000000..d47bc8a0 Binary files /dev/null and b/pdf-as-web/src/main/webapp/assets/js/pdf.js/web/images/document_signature.png differ diff --git a/pdf-as-web/src/main/webapp/assets/js/pdf.js/web/images/document_signature@2x.png b/pdf-as-web/src/main/webapp/assets/js/pdf.js/web/images/document_signature@2x.png new file mode 100644 index 00000000..a116da0d Binary files /dev/null and b/pdf-as-web/src/main/webapp/assets/js/pdf.js/web/images/document_signature@2x.png differ diff --git a/pdf-as-web/src/main/webapp/assets/js/pdf.js/web/viewer.css b/pdf-as-web/src/main/webapp/assets/js/pdf.js/web/viewer.css index cee3305a..2ffe6356 100644 --- a/pdf-as-web/src/main/webapp/assets/js/pdf.js/web/viewer.css +++ b/pdf-as-web/src/main/webapp/assets/js/pdf.js/web/viewer.css @@ -1052,6 +1052,16 @@ html[dir='rtl'] .toolbarButton.pageDown::before { content: url(images/toolbarButton-openFile.png); } +.toolbarButton.placeSignature::before, +.secondaryToolbarButton.placeSignature::before { + content: url(images/document_signature.png); +} + +.toolbarButton.delSignature::before, +.secondaryToolbarButton.delSignature::before { + content: url(images/document_del_signature.png); +} + .toolbarButton.download::before, .secondaryToolbarButton.download::before { content: url(images/toolbarButton-download.png); @@ -1767,6 +1777,16 @@ html[dir='rtl'] #documentPropertiesOverlay .row > * { .secondaryToolbarButton.openFile::before { content: url(images/toolbarButton-openFile@2x.png); } + + .toolbarButton.placeSignature::before, + .secondaryToolbarButton.placeSignature::before { + content: url(images/document_signature@2x.png); + } + + .toolbarButton.delSignature::before, + .secondaryToolbarButton.delSignature::before { + content: url(images/document_del_signature@2x.png); + } .toolbarButton.download::before, .secondaryToolbarButton.download::before { diff --git a/pdf-as-web/src/main/webapp/assets/js/pdf.js/web/viewer.html b/pdf-as-web/src/main/webapp/assets/js/pdf.js/web/viewer.html index 6dae1b7b..20200881 100644 --- a/pdf-as-web/src/main/webapp/assets/js/pdf.js/web/viewer.html +++ b/pdf-as-web/src/main/webapp/assets/js/pdf.js/web/viewer.html @@ -95,20 +95,30 @@ http://sourceforge.net/adobe/cmap/wiki/License/ - - + + + + + + - - + @@ -148,7 +158,7 @@ http://sourceforge.net/adobe/cmap/wiki/License/
-
@@ -169,10 +179,20 @@ http://sourceforge.net/adobe/cmap/wiki/License/
- - + + + + + + + @@ -181,16 +201,16 @@ http://sourceforge.net/adobe/cmap/wiki/License/ Print - - + -
+ -
@@ -364,6 +384,16 @@ http://sourceforge.net/adobe/cmap/wiki/License/ } } + +#scaleSelectContainer { + display: none; +} + + +#sidebarToggle { + display: none; +} + #mozPrintCallback-shim .mozPrintCallback-dialog-box { display: inline-block; margin: -50px auto 0; diff --git a/pdf-as-web/src/main/webapp/assets/js/pdf.js/web/viewer.js b/pdf-as-web/src/main/webapp/assets/js/pdf.js/web/viewer.js index 9801be2f..c653c2bf 100644 --- a/pdf-as-web/src/main/webapp/assets/js/pdf.js/web/viewer.js +++ b/pdf-as-web/src/main/webapp/assets/js/pdf.js/web/viewer.js @@ -6667,10 +6667,13 @@ window.PDFView = PDFViewerApplication; // obsolete name, using it as an alias function webViewerLoad(evt) { //PDFViewerApplication.initialize().then(webViewerInitialized); - PDFViewerApplication.initialize().then(function() { - webViewerInitialized(); - window.parent.postMessage("asdf yooooooo","*"); - }); + PDFViewerApplication.initialize().then(function() { + webViewerInitialized(); + if (window.self !== window.parent) { + window.parent.postMessage("asdf yooooooo","*"); + } + + }); } function webViewerInitialized() { @@ -7011,7 +7014,11 @@ window.addEventListener('change', function webViewerChange(evt) { } var file = files[0]; - + + //ADDED + if(window.self !== window.parent) { + setFileForParent(file); + } if (!PDFJS.disableCreateObjectURL && typeof URL !== 'undefined' && URL.createObjectURL) { PDFViewerApplication.open(URL.createObjectURL(file), 0); -- cgit v1.2.3