aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Felber <felber@student.tugraz.at>2015-06-20 18:17:06 -1000
committerAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2015-07-13 09:50:07 +0200
commitcb3c726d400e19fba8a2544e8e1decbd6e8eb368 (patch)
treeca7d121ea62e6b9cbaa11318196b8b299ca7f426
parentdd7ba18d3a134f2becc2ad53f9b3d2191798e686 (diff)
downloadpdf-as-4-cb3c726d400e19fba8a2544e8e1decbd6e8eb368.tar.gz
pdf-as-4-cb3c726d400e19fba8a2544e8e1decbd6e8eb368.tar.bz2
pdf-as-4-cb3c726d400e19fba8a2544e8e1decbd6e8eb368.zip
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
-rw-r--r--pdf-as-web/src/main/webapp/assets/css/style.css1
-rw-r--r--pdf-as-web/src/main/webapp/assets/js/dragNdrop.js21
-rw-r--r--pdf-as-web/src/main/webapp/assets/js/pdf.js/web/app.js134
-rw-r--r--pdf-as-web/src/main/webapp/assets/js/pdf.js/web/images/document_del_signature.pngbin0 -> 330 bytes
-rw-r--r--pdf-as-web/src/main/webapp/assets/js/pdf.js/web/images/document_del_signature@2x.pngbin0 -> 702 bytes
-rw-r--r--pdf-as-web/src/main/webapp/assets/js/pdf.js/web/images/document_signature.pngbin0 -> 417 bytes
-rw-r--r--pdf-as-web/src/main/webapp/assets/js/pdf.js/web/images/document_signature@2x.pngbin0 -> 717 bytes
-rw-r--r--pdf-as-web/src/main/webapp/assets/js/pdf.js/web/viewer.css20
-rw-r--r--pdf-as-web/src/main/webapp/assets/js/pdf.js/web/viewer.html52
-rw-r--r--pdf-as-web/src/main/webapp/assets/js/pdf.js/web/viewer.js17
10 files changed, 185 insertions, 60 deletions
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("<img src='http://localhost:8080/pdf-as-web/visblock?r=" + sig_size.toString() + "' data-pos-x='0' data-pos-y='0' data-page='" + current_page + "' alt='Signature' id='img_signature' class='cl_signature' draggable='true' style='position: absolute; z-index:4; cursor:move'>");
+ 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("<img src='../../../img/signature.png' alt='Signature' id='img_signature' class='cl_signature' draggable='true' style='position: absolute; z-index:4;'>");
- $(".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
--- /dev/null
+++ b/pdf-as-web/src/main/webapp/assets/js/pdf.js/web/images/document_del_signature.png
Binary files 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
--- /dev/null
+++ b/pdf-as-web/src/main/webapp/assets/js/pdf.js/web/images/document_del_signature@2x.png
Binary files 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
--- /dev/null
+++ b/pdf-as-web/src/main/webapp/assets/js/pdf.js/web/images/document_signature.png
Binary files 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
--- /dev/null
+++ b/pdf-as-web/src/main/webapp/assets/js/pdf.js/web/images/document_signature@2x.png
Binary files 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/
<button id="secondaryPresentationMode" class="secondaryToolbarButton presentationMode visibleLargeView" title="Switch to Presentation Mode" tabindex="51" data-l10n-id="presentation_mode">
<span data-l10n-id="presentation_mode_label">Presentation Mode</span>
</button>
-
- <button id="secondaryOpenFile" class="secondaryToolbarButton openFile visibleLargeView" title="Open File" tabindex="52" data-l10n-id="open_file">
+
+ <button id="secondaryOpenFile" class="secondaryToolbarButton openFile visibleLargeView" title="Open File" tabindex="50" data-l10n-id="open_file">
<span data-l10n-id="open_file_label">Open</span>
</button>
+ <!-- ADDED -->
+ <button id="secondaryPlaceSignature" class="secondaryToolbarButton placeSignature visibleLargeView" title="Place Signature" tabindex="51" data-l10n-id="place_signature">
+ <span data-l10n-id="place_signature_label">Place Signature</span>
+ </button>
+
+ <!-- ADDED -->
+ <button id="secondaryDelSignature" class="secondaryToolbarButton delSignature visibleLargeView" title="Remove Signature (If no Signature gets placed, one will be appended at the end of the document)" tabindex="52" data-l10n-id="del_signature">
+ <span data-l10n-id="place_signature_label">Remove Signature</span>
+ </button>
+
<button id="secondaryPrint" class="secondaryToolbarButton print visibleMediumView" title="Print" tabindex="53" data-l10n-id="print">
<span data-l10n-id="print_label">Print</span>
</button>
- <button id="secondaryDownload" class="secondaryToolbarButton download visibleMediumView" title="Download" tabindex="54" data-l10n-id="download">
+ <button id="secondaryDownload" style="display:none;" class="secondaryToolbarButton download visibleMediumView" title="Download" tabindex="54" data-l10n-id="download">
<span data-l10n-id="download_label">Download</span>
</button>
- <a href="#" id="secondaryViewBookmark" class="secondaryToolbarButton bookmark visibleSmallView" title="Current view (copy or open in new window)" tabindex="55" data-l10n-id="bookmark">
+ <a href="#" style="display: none;" id="secondaryViewBookmark" class="secondaryToolbarButton bookmark visibleSmallView" title="Current view (copy or open in new window)" tabindex="55" data-l10n-id="bookmark">
<span data-l10n-id="bookmark_label">Current View</span>
</a>
@@ -148,7 +158,7 @@ http://sourceforge.net/adobe/cmap/wiki/License/
<div id="toolbarContainer">
<div id="toolbarViewer">
<div id="toolbarViewerLeft">
- <button id="sidebarToggle" class="toolbarButton" title="Toggle Sidebar" tabindex="11" data-l10n-id="toggle_sidebar">
+ <button id="sidebarToggle" class="toolbarButton" style="display:none" title="Toggle Sidebar" tabindex="11" data-l10n-id="toggle_sidebar">
<span data-l10n-id="toggle_sidebar_label">Toggle Sidebar</span>
</button>
<div class="toolbarButtonSpacer"></div>
@@ -169,10 +179,20 @@ http://sourceforge.net/adobe/cmap/wiki/License/
<span id="numPages" class="toolbarLabel"></span>
</div>
<div id="toolbarViewerRight">
- <button id="presentationMode" class="toolbarButton presentationMode hiddenLargeView" title="Switch to Presentation Mode" tabindex="31" data-l10n-id="presentation_mode">
+ <button id="presentationMode" class="toolbarButton presentationMode hiddenLargeView" title="Switch to Presentation Mode" tabindex="29" data-l10n-id="presentation_mode">
<span data-l10n-id="presentation_mode_label">Presentation Mode</span>
</button>
-
+
+ <!-- ADDED -->
+ <button id="placeSignature" class="toolbarButton placeSignature hiddenLargeView" title="Place Signature on current Page" tabindex="30" data-l10n-id="place_signature">
+ <span data-l10n-id="place_signature_label">Place Signature</span>
+ </button>
+
+ <!-- ADDED -->
+ <button id="delSignature" class="toolbarButton delSignature hiddenLargeView" title="Remove Signature (If no Signature gets placed, one will be appended at the end of the document)" tabindex="31" data-l10n-id="del_signature">
+ <span data-l10n-id="place_signature_label">Remove Signature</span>
+ </button>
+
<button id="openFile" class="toolbarButton openFile hiddenLargeView" title="Open File" tabindex="32" data-l10n-id="open_file">
<span data-l10n-id="open_file_label">Open</span>
</button>
@@ -181,16 +201,16 @@ http://sourceforge.net/adobe/cmap/wiki/License/
<span data-l10n-id="print_label">Print</span>
</button>
- <button id="download" class="toolbarButton download hiddenMediumView" title="Download" tabindex="34" data-l10n-id="download">
+ <button id="download" style="display:none;" class="toolbarButton download hiddenMediumView" title="Download" tabindex="34" data-l10n-id="download">
<span data-l10n-id="download_label">Download</span>
</button>
- <a href="#" id="viewBookmark" class="toolbarButton bookmark hiddenSmallView" title="Current view (copy or open in new window)" tabindex="35" data-l10n-id="bookmark">
+ <a href="#" id="viewBookmark" style="display: none" class="toolbarButton bookmark hiddenSmallView" title="Current view (copy or open in new window)" tabindex="35" data-l10n-id="bookmark">
<span data-l10n-id="bookmark_label">Current View</span>
</a>
- <div class="verticalToolbarSeparator hiddenSmallView"></div>
+ <div class="verticalToolbarSeparator hiddenSmallView" style="display: none;"></div>
- <button id="secondaryToolbarToggle" class="toolbarButton" title="Tools" tabindex="36" data-l10n-id="tools">
+ <button id="secondaryToolbarToggle" style="display: none;" class="toolbarButton" title="Tools" tabindex="36" data-l10n-id="tools">
<span data-l10n-id="tools_label">Tools</span>
</button>
</div>
@@ -364,6 +384,16 @@ http://sourceforge.net/adobe/cmap/wiki/License/
}
}
+<!-- ADDED -->
+#scaleSelectContainer {
+ display: none;
+}
+
+<!-- ADDED -->
+#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);