From f22eb52113cc190db1bd2b960aabea4681778d42 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Mon, 5 Jul 2021 17:36:36 -0600 Subject: [PATCH] Add certificate generator tool (close #3) --- src/index.html | 34 ++ src/js/certbuilder.js | 61 +++ src/js/data.js | 61 +++ src/js/drawtools.js | 17 + src/js/pdf.js | 13 + .../mt/certifiedcopyelectronic.svg | 360 ++++++++++++++++++ src/templates/certificates/mt/generic.svg | 359 +++++++++++++++++ 7 files changed, 905 insertions(+) create mode 100644 src/js/certbuilder.js create mode 100644 src/js/data.js create mode 100644 src/templates/certificates/mt/certifiedcopyelectronic.svg create mode 100644 src/templates/certificates/mt/generic.svg diff --git a/src/index.html b/src/index.html index dcf3a5c..cd70a77 100644 --- a/src/index.html +++ b/src/index.html @@ -118,6 +118,37 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/. + +
@@ -167,10 +199,12 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/. + + \ No newline at end of file diff --git a/src/js/certbuilder.js b/src/js/certbuilder.js new file mode 100644 index 0000000..04cc605 --- /dev/null +++ b/src/js/certbuilder.js @@ -0,0 +1,61 @@ +/* + * Copyright 2021 Netsyms Technologies. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +function getCertificateSvg(callback) { + var path = getStorage("notary_state") + "/generic.svg"; + var act = $("#certificateBuilderModal #cert_act option:selected").val(); + + if (act == "CERTIFIEDCOPYELECTRONIC") { + path = getStorage("notary_state") + "/certifiedcopyelectronic.svg"; + } + getCertificateSvgWithValues(path, { + name: getStorage("notary_name"), + location: getStorage("notary_location"), + expires: getStorage("notary_expires"), + idnumber: getStorage("notary_idnumber"), + state: $("#certificateBuilderModal #cert_state option:selected").val(), + county: $("#certificateBuilderModal #cert_county").val(), + act: act, + date: formatTimestamp("F j, Y"), + signer: $("#certificateBuilderModal #cert_signer").val(), + pagecount: $("#page-canvas-container .page-canvas").length, + doctitle: pdfTitle == "" ? "(untitled)" : pdfTitle + }, callback); +} + +function getCertificateSvgWithValues(path, values, callback) { + $.get("templates/certificates/" + path, {}, function (svg) { + svg = svg + ""; + for (const key in values) { + svg = svg.replaceAll("[[[" + key.toUpperCase() + "]]]", values[key]); + } + + callback(svg); + }, "text"); +} + +function initCertificateBuilder() { + /** + * Load state dropdown with default of notary state + */ + $("#cert_state").html(""); + for (const abbrev in STATE_ABBREV) { + var selected = ""; + if (abbrev == getStorage("notary_state").toUpperCase()) { + selected = " selected"; + } + $("#cert_state").append(""); + } + + new bootstrap.Modal(document.getElementById('certificateBuilderModal')).show(); +} + +$("body").on("input change paste select", "#certificateBuilderModal input,#certificateBuilderModal select", function () { + getCertificateSvg(function (svg) { + $("#certificateBuilderModal #certificate-preview").attr("src", "data:image/svg+xml;base64," + btoa(svg)); + }); +}); \ No newline at end of file diff --git a/src/js/data.js b/src/js/data.js new file mode 100644 index 0000000..258e759 --- /dev/null +++ b/src/js/data.js @@ -0,0 +1,61 @@ +/* + * Copyright 2021 Netsyms Technologies. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + + +const STATE_ABBREV = { + "AL": "Alabama", + "AK": "Alaska", + "AZ": "Arizona", + "AR": "Arkansas", + "CA": "California", + "CO": "Colorado", + "CT": "Connecticut", + "DE": "Delaware", + "DC": "District of Columbia", + "FL": "Florida", + "GA": "Georgia", + "HI": "Hawaii", + "ID": "Idaho", + "IL": "Illinois", + "IN": "Indiana", + "IA": "Iowa", + "KS": "Kansas", + "KY": "Kentucky", + "LA": "Louisiana", + "ME": "Maine", + "MD": "Maryland", + "MA": "Massachusetts", + "MI": "Michigan", + "MN": "Minnesota", + "MS": "Mississippi", + "MO": "Missouri", + "MT": "Montana", + "NE": "Nebraska", + "NV": "Nevada", + "NH": "New Hampshire", + "NJ": "New Jersey", + "NM": "New Mexico", + "NY": "New York", + "NC": "North Carolina", + "ND": "North Dakota", + "OH": "Ohio", + "OK": "Oklahoma", + "OR": "Oregon", + "PA": "Pennsylvania", + "RI": "Rhode Island", + "SC": "South Carolina", + "SD": "South Dakota", + "TN": "Tennessee", + "TX": "Texas", + "UT": "Utah", + "VT": "Vermont", + "VA": "Virginia", + "WA": "Washington", + "WV": "West Virginia", + "WI": "Wisconsin", + "WY": "Wyoming" +}; \ No newline at end of file diff --git a/src/js/drawtools.js b/src/js/drawtools.js index ca7aac0..e6f7cb6 100644 --- a/src/js/drawtools.js +++ b/src/js/drawtools.js @@ -90,6 +90,23 @@ function activateNotarySignatureTool() { }); } +function activateNotaryCertificateTool() { + initCertificateBuilder(); + + certificateBuilderCallback = function () { + getCertificateSvg(function (svg) { + svgToImage(svg, function (err, image) { + if (err) { + console.error(err); + return; + } + activeDrawImage = image; + enableGuideBox(image); + }); + }); + }; +} + function activateClientSignaturePad() { initSignaturePad(); signaturePadCallback = function () { diff --git a/src/js/pdf.js b/src/js/pdf.js index 85c0d6d..1b4ae00 100644 --- a/src/js/pdf.js +++ b/src/js/pdf.js @@ -11,14 +11,27 @@ var pdfPageScale = 3; var pdfAssumedDPI = 72; var pdfDoc = null; var pageNumber = 0; +var pdfTitle = ""; function addPDF() { openFileDialog(function (path) { var filedata = getFileAsUint8Array(path); + // Get filename + // https://stackoverflow.com/a/424006 + pdfTitle = path.split('\\').pop().split('/').pop(); + pdfjsLib.getDocument(filedata).promise.then(function (pdfDoc_) { pdfDoc = pdfDoc_; + pdfDoc.getMetadata().then(function (meta) { + if (typeof meta.contentDispositionFilename == "string") { + pdfTitle = meta.contentDispositionFilename; + } + }).catch(function (err) { + console.log('Error getting PDF metadata: ', err); + }); + renderAllPages(pdfDoc); pdfZoom("fitwidth"); // Initial/first page rendering diff --git a/src/templates/certificates/mt/certifiedcopyelectronic.svg b/src/templates/certificates/mt/certifiedcopyelectronic.svg new file mode 100644 index 0000000..53339ae --- /dev/null +++ b/src/templates/certificates/mt/certifiedcopyelectronic.svg @@ -0,0 +1,360 @@ + + + + + + image/svg+xml + + + + + + + + + + + NOTARIAL CERTIFICATE + + + [[[NAME]]]Notary Public for theState of MontanaResiding at[[[LOCATION]]]My Commission Expires[[[EXPIRES]]] + + SEAL + Notarial + + + + + + + + + + State of Montana + [[[NAME]]] + + + + + + + State of [[[STATE]]]County of [[[COUNTY]]] + + I certify that this record, titled [[[DOCTITLE]]]and consisting of [[[PAGECOUNT]]] pages is a true and correct copy of anelectronic record printed directly from the electronic file by meon [[[DATE]]]. + + (notarial signature) + diff --git a/src/templates/certificates/mt/generic.svg b/src/templates/certificates/mt/generic.svg new file mode 100644 index 0000000..2c3844e --- /dev/null +++ b/src/templates/certificates/mt/generic.svg @@ -0,0 +1,359 @@ + + + + + + image/svg+xml + + + + + + + + + + + NOTARIAL CERTIFICATE + + + [[[NAME]]]Notary Public for theState of MontanaResiding at[[[LOCATION]]]My Commission Expires[[[EXPIRES]]] + + SEAL + Notarial + + + + + + + + + + State of Montana + [[[NAME]]] + + + + + + + + State of [[[STATE]]]County of [[[COUNTY]]] + This electronic record was [[[ACT]]] before me on [[[DATE]]]by [[[SIGNER]]]. + This PDF file has a PGP cryptographic signature appended. Changing or saving the file willremove the signature. To verify signature, go to https://ntsm.io/enotary. + + + (notarial signature) +