Fit Height
@@ -139,7 +140,6 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
diff --git a/js/pdf.js b/js/pdf.js
index b73b7b2..c3e4730 100644
--- a/js/pdf.js
+++ b/js/pdf.js
@@ -40,8 +40,10 @@ function closePDF(showuserconfirm) {
$("#page-canvas-container .page-canvas").remove();
}
-function generatePDF() {
+function generatePDF(callback) {
var canvases = $("#page-canvas-container .page-canvas");
+ var statustextEl = $("#statustext");
+ statustextEl.html("
Processing document...");
const pdf = new jsPDF({
unit: "in",
compress: true
@@ -49,19 +51,32 @@ function generatePDF() {
// creating a PDF creates a blank page that we don't want to use,
// as we haven't done the calculations yet
pdf.deletePage(1);
- for (var i = 0; i < canvases.length; i++) {
- var canvas = $("#page-canvas-container .page-canvas")[i];
- var widthpx = canvas.getContext("2d").canvas.width;
- var heightpx = canvas.getContext("2d").canvas.height;
- var pageWidthInches = widthpx / (pdfAssumedDPI * pdfPageScale);
- var pageHeightInches = heightpx / (pdfAssumedDPI * pdfPageScale);
- console.log(pageWidthInches + " x " + pageHeightInches);
- var pageFormat = [pageWidthInches, pageHeightInches];
- var pageOrientation = (pageWidthInches > pageHeightInches ? "landscape" : "portrait");
- pdf.addPage(pageFormat, pageOrientation);
- pdf.addImage($("#page-canvas-container .page-canvas")[i].toDataURL(), 0, 0, pageWidthInches, pageHeightInches);
+
+ // Render each page in order with a pause in between to keep UI responsive
+ var processPage = function (i) {
+ if (i < canvases.length) {
+ statustextEl.html("
Processing page " + (i + 1) + " of " + canvases.length + "...");
+ console.log("Processing " + (i + 1));
+ var canvas = canvases[i];
+ var widthpx = canvas.getContext("2d").canvas.width;
+ var heightpx = canvas.getContext("2d").canvas.height;
+ var pageWidthInches = widthpx / (pdfAssumedDPI * pdfPageScale);
+ var pageHeightInches = heightpx / (pdfAssumedDPI * pdfPageScale);
+ console.log(pageWidthInches + " x " + pageHeightInches);
+ var pageFormat = [pageWidthInches, pageHeightInches];
+ var pageOrientation = (pageWidthInches > pageHeightInches ? "landscape" : "portrait");
+ pdf.addPage(pageFormat, pageOrientation);
+ pdf.addImage(canvases[i].toDataURL(), 0, 0, pageWidthInches, pageHeightInches);
+ i++;
+ setTimeout(function () {
+ processPage(i)
+ }, 100);
+ } else {
+ statustextEl.html("");
+ callback(pdf);
+ }
}
- return pdf;
+ processPage(0);
}
function getPDFAsByteArray(pdf) {
@@ -93,15 +108,23 @@ function makeAndSaveSignedPDF(pdf, savepath, callback) {
function savePDF() {
disableGuideBox();
+ var statustextEl = $("#statustext");
loadKeyFromLocalStorage(function (message, ok) {
if (ok) {
openSaveFileDialog(function (path) {
- var pdf = generatePDF();
- makeAndSaveSignedPDF(pdf, path, function (result) {
- alert("File signed and saved.\n SHA256 of file (without signature): " + result.hash);
+ generatePDF(function (pdf) {
+ statustextEl.html("
Signing document...");
+ makeAndSaveSignedPDF(pdf, path, function (result) {
+ statustextEl.html("
Signed and saved!");
+ alert("File signed and saved.\nSHA256 of file (without signature): " + result.hash);
+ setTimeout(function () {
+ statustextEl.html("");
+ }, 5000);
+ });
});
}, "signed.pdf", ".pdf");
} else {
+ statustextEl.html("");
alert("Error: " + message);
}
});