diff options
author | Thomas Felber <felber@student.tugraz.at> | 2015-05-11 00:54:45 -0700 |
---|---|---|
committer | Andreas Fitzek <andreas.fitzek@iaik.tugraz.at> | 2015-07-13 09:48:47 +0200 |
commit | dd7ba18d3a134f2becc2ad53f9b3d2191798e686 (patch) | |
tree | 775018ff0034f1f4e91b03a6b7cd9982f0f653ac /pdf-as-web/src/main/webapp/assets/js | |
parent | 02d8f5c31877def18db70f72fdb54fe53b2c9f52 (diff) | |
download | pdf-as-4-dd7ba18d3a134f2becc2ad53f9b3d2191798e686.tar.gz pdf-as-4-dd7ba18d3a134f2becc2ad53f9b3d2191798e686.tar.bz2 pdf-as-4-dd7ba18d3a134f2becc2ad53f9b3d2191798e686.zip |
switched to jspdf with pdf.js, added movable signatureblock prototype, updated js in order to make pdf.js work
Diffstat (limited to 'pdf-as-web/src/main/webapp/assets/js')
4 files changed, 94 insertions, 63 deletions
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 e1a3424a..31ba841d 100644 --- a/pdf-as-web/src/main/webapp/assets/js/dragNdrop.js +++ b/pdf-as-web/src/main/webapp/assets/js/dragNdrop.js @@ -5,10 +5,19 @@ $(document).ready(function() { function registerEventListeners() { - var file; + var file = null; var locale = "EN"; var connector = "mobilebku"; + window.addEventListener("message", function receiveMessage(evt) { + console.log("parent: message received"); + console.log(evt.data); + var iframewindow = document.getElementById("iFrame"); + console.log(file); + iframewindow.contentWindow.postMessage(file, "*"); + console.log("postmessage to child sent"); + }, false); + $(document).bind("dragover", function(evt) { evt.preventDefault(); }); @@ -51,10 +60,11 @@ function registerEventListeners() { } file = files[0]; - previewFile(file); + previewFile(); }); $("#pdf-file").bind("change", function(evt) { + file_event = evt; var files = evt.target.files; if(files == null || files.length === 0) { return; @@ -70,25 +80,21 @@ 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) { sign(file, connector, locale); }); - } -function previewFile(file) { - var fr = new FileReader(); - - fr.onload = function(file) { - var buffer = fr.result; - var uint8array = new Uint8Array(buffer); - displaypdf(uint8array); - }; - +function previewFile() { clearContentDiv(); - fr.readAsArrayBuffer(file); + createIframe(); } function sign(file, connector, locale) { @@ -128,39 +134,6 @@ function clearContentDiv() { $("#content").empty(); } -function displaypdf(uint8array) { - $("#content").append("<img src='assets/img/signature.png' alt='Signature' id='signature' draggable='true' style='position: absolute'>"); - $("#content").append("<canvas id='pdf-preview'></canvas>"); - - - PDFJS.getDocument(uint8array).then(function(__pdf) { - var pdf = __pdf; - var last_page = pdf.numPages; - - pdf.getPage(last_page).then(renderPage); - - }); - - $("#signature").draggable({ - drag: function() { - - }, - containment: "parent" - }); -} - -function renderPage(page) { - var viewport = page.getViewport(1); - var canvas = document.getElementById("pdf-preview"); - var context = canvas.getContext('2d'); - canvas.height = 868; - canvas.width = 800; - - page.render({ - canvasContext: context, - viewport: viewport - }); - +function createIframe() { + $("#content").append("<iframe src='assets/js/pdf.js/web/viewer.html' height='863px' width='800px' id='iFrame'></iframe>"); } - - 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 new file mode 100644 index 00000000..bb2c89d7 --- /dev/null +++ b/pdf-as-web/src/main/webapp/assets/js/pdf.js/web/app.js @@ -0,0 +1,53 @@ +window.addEventListener("message", function (evt) { + var goto_last_page_on_render = false; + var file = evt.data; + 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); + }; + + function showSignatureBlock(evt) { + console.log(evt); + if(PDFViewerApplication.pdfViewer.getPageView(PDFViewerApplication.page - 1).renderingState === RenderingStates.RUNNING) { + return; + } + + 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); + + + + + 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 b3af4ada..6dae1b7b 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 @@ -24,23 +24,23 @@ http://sourceforge.net/adobe/cmap/wiki/License/ <meta name="google" content="notranslate"> <title>PDF.js viewer</title> - <link rel="stylesheet" href="viewer.css"/> - + <script src="compatibility.js"></script> - - -<!-- This snippet is used in production (included from viewer.html) --> -<link rel="resource" type="application/l10n" href="locale/locale.properties"/> -<script src="l10n.js"></script> -<script src="../build/pdf.js"></script> - - + <!-- This snippet is used in production (included from viewer.html) --> + <link rel="resource" type="application/l10n" href="locale/locale.properties"/> + + <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> + <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js"></script> + + <script src="l10n.js"></script> + <script src="../build/pdf.js"></script> <script src="debugger.js"></script> <script src="viewer.js"></script> - + <script src="app.js"></script> + </head> <body tabindex="1" class="loadingInProgress"> 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 34c44e46..9801be2f 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 @@ -27,7 +27,7 @@ 'use strict'; -var DEFAULT_URL = 'compressed.tracemonkey-pldi-09.pdf'; +var DEFAULT_URL = ''; var DEFAULT_SCALE_DELTA = 1.1; var MIN_SCALE = 0.25; var MAX_SCALE = 10.0; @@ -5843,7 +5843,7 @@ var PDFViewerApplication = { function getDocumentCallback(pdfDocument) { self.load(pdfDocument, scale); self.loading = false; - }, + }, function getDocumentError(exception) { var message = exception && exception.message; var loadingErrorMessage = mozL10n.get('loading_error', null, @@ -6666,14 +6666,18 @@ window.PDFView = PDFViewerApplication; // obsolete name, using it as an alias function webViewerLoad(evt) { - PDFViewerApplication.initialize().then(webViewerInitialized); + //PDFViewerApplication.initialize().then(webViewerInitialized); + PDFViewerApplication.initialize().then(function() { + webViewerInitialized(); + window.parent.postMessage("asdf yooooooo","*"); + }); } function webViewerInitialized() { var queryString = document.location.search.substring(1); var params = PDFViewerApplication.parseQueryString(queryString); var file = 'file' in params ? params.file : DEFAULT_URL; - + var fileInput = document.createElement('input'); fileInput.id = 'fileInput'; fileInput.className = 'fileInput'; @@ -7005,6 +7009,7 @@ window.addEventListener('change', function webViewerChange(evt) { if (!files || files.length === 0) { return; } + var file = files[0]; if (!PDFJS.disableCreateObjectURL && |