var PDF; var pdfdata; function initpdf() { PDF = new ns.PDFControl(); PDF.init(); RaiseAddInReady(); } // Event will be fired when the control add-in is ready for communication through its API. function RaiseAddInReady() { Microsoft.Dynamics.NAV.InvokeExtensibilityMethod('AddInReady'); } // Event raised when the update PDF has been called. function RaiseUpdatePDF() { Microsoft.Dynamics.NAV.InvokeExtensibilityMethod('UpdatePDF'); } function PutPDF(PDFData,pageno) { PDF.updatePDF(PDFData,pageno); } (function (ns) { ns.PDFControl = function () { var canvas, context; function init() { createControlElements(); context = canvas.getContext("2d"); } function createControlElements() { var PDFArea = document.createElement("div"); var canvasDiv = document.createElement("div"); canvas = document.createElement("canvas"), canvas.id = "pdfCanvas"; canvas.clientWidth = 700; canvas.clientHeight = 1000; canvas.width = canvas.clientWidth ; canvas.height = canvas.clientHeight; canvas.className = "pdfCanvas"; canvasDiv.appendChild(canvas); PDFArea.className = "PDFArea"; PDFArea.appendChild(canvasDiv); document.getElementById("controlAddIn").appendChild(PDFArea); } function updatePDF(PDFData,pageno) { pdfData = atob(PDFData); // PDFJS.workerSrc = 'http://www.example.dk/tmp/pdf.worker.js'; PDFJS.getDocument({data: pdfData}).then(function DisplayPDFNAV(pdf) { pdf.getPage(pageno).then(function DisplayPDFNAV(page) { var scale = 2.0; var viewport = page.getViewport(scale); // Prepare canvas using PDF page dimensions. canvas.height = viewport.height; canvas.width = viewport.width; //Render PDF page into canvas context. var renderContext = { canvasContext: context, viewport: viewport }; page.render(renderContext); }); RaiseUpdatePDF(); }); PDFArea.appendChild(canvasDiv); pdfData = ""; } return { init: init, updatePDF: updatePDF, }; }; })(this.ns = this.ns || {});
Answers