From 597c52eefea36baed2b4ef5ee0f619b8cc73104d Mon Sep 17 00:00:00 2001 From: Emma Short Date: Thu, 17 Apr 2025 14:37:18 -0600 Subject: [PATCH] V1 standalone complete --- .gitignore | 1 + README.md | 36 ++++++++++++++++++++++++++++++++++++ deno.json | 11 +++++++++++ deno.lock | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ main.ts | 31 +++++++++++++++++++++++++++++++ 5 files changed, 133 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 deno.json create mode 100644 deno.lock create mode 100644 main.ts diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..adb36c8 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.exe \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..6c65625 --- /dev/null +++ b/README.md @@ -0,0 +1,36 @@ +# Emma's Simple Form Field Checker + +Compares a PDF form to a list of CS class files to see if all field names are +present, excluding signature fields. + +## Prereqs + +Deno >=2.2 (not required if downloading .exe) + +## Installation + +### Deno install + +`deno task install` -> installs as global command `checkfields` + +### Compile + +`deno task compile` -> compare-form-fields.exe -OR- Download .exe from release + +> If you want it to be a global command, create an executables directory and add +> it to the PATH + +## Usage + +`checkfields ` +-OR- `checkfields` and follow prompts. + +### Output + +> All form fields present! + +-OR- + +> The following field names are not present in the CS code + +> \ diff --git a/deno.json b/deno.json new file mode 100644 index 0000000..1831b86 --- /dev/null +++ b/deno.json @@ -0,0 +1,11 @@ +{ + "tasks": { + "dev": "deno run -A --watch main.ts", + "compile": "deno compile -o compare-form-fields.exe --target x86_64-pc-windows-msvc -R ./main.ts", + "install": "deno install -fgq --import-map ./deno.json -n checkfields -R ./main.ts" + }, + "imports": { + "@std/assert": "jsr:@std/assert@1", + "pdf-lib": "npm:pdf-lib@^1.17.1" + } +} diff --git a/deno.lock b/deno.lock new file mode 100644 index 0000000..1e00912 --- /dev/null +++ b/deno.lock @@ -0,0 +1,54 @@ +{ + "version": "4", + "specifiers": { + "jsr:@std/assert@1": "1.0.12", + "jsr:@std/internal@^1.0.6": "1.0.6", + "npm:pdf-lib@^1.17.1": "1.17.1" + }, + "jsr": { + "@std/assert@1.0.12": { + "integrity": "08009f0926dda9cbd8bef3a35d3b6a4b964b0ab5c3e140a4e0351fbf34af5b9a", + "dependencies": [ + "jsr:@std/internal" + ] + }, + "@std/internal@1.0.6": { + "integrity": "9533b128f230f73bd209408bb07a4b12f8d4255ab2a4d22a1fd6d87304aca9a4" + } + }, + "npm": { + "@pdf-lib/standard-fonts@1.0.0": { + "integrity": "sha512-hU30BK9IUN/su0Mn9VdlVKsWBS6GyhVfqjwl1FjZN4TxP6cCw0jP2w7V3Hf5uX7M0AZJ16vey9yE0ny7Sa59ZA==", + "dependencies": [ + "pako" + ] + }, + "@pdf-lib/upng@1.0.1": { + "integrity": "sha512-dQK2FUMQtowVP00mtIksrlZhdFXQZPC+taih1q4CvPZ5vqdxR/LKBaFg0oAfzd1GlHZXXSPdQfzQnt+ViGvEIQ==", + "dependencies": [ + "pako" + ] + }, + "pako@1.0.11": { + "integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==" + }, + "pdf-lib@1.17.1": { + "integrity": "sha512-V/mpyJAoTsN4cnP31vc0wfNA1+p20evqqnap0KLoRUN0Yk/p3wN52DOEsL4oBFcLdb76hlpKPtzJIgo67j/XLw==", + "dependencies": [ + "@pdf-lib/standard-fonts", + "@pdf-lib/upng", + "pako", + "tslib" + ] + }, + "tslib@1.14.1": { + "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==" + } + }, + "workspace": { + "dependencies": [ + "jsr:@std/assert@1", + "npm:pdf-lib@^1.17.1" + ] + } +} diff --git a/main.ts b/main.ts new file mode 100644 index 0000000..f4ecc9d --- /dev/null +++ b/main.ts @@ -0,0 +1,31 @@ +import {PDFDocument} from "pdf-lib"; + +let [pdfPath, csPath] = Deno.args; + +while (!pdfPath || !pdfPath.endsWith('.pdf')) pdfPath = prompt("Please provide path to PDF file:") || ""; +while (!csPath || !csPath.endsWith('.cs')) csPath = prompt("Please provide path to CS class file:") || ""; + +const pdfBytes = await Deno.readFile(pdfPath); + +const pdfDoc = await PDFDocument.load(pdfBytes); + +const form = pdfDoc.getForm(); + +const fields = form.getFields(); +const csFiles = await Promise.all(csPath.split(",").map(c => Deno.readTextFile(c.trim()))); + +const fieldNames:string[] = fields.map(f => f.getName()) +.filter(f => { + const rx = new RegExp(`(? rx.test(c)) +}) +.filter(f => !f.toLowerCase().includes("signature")); + +if (fieldNames.length) { + console.log("%cThe following field names are not present in the CS code", "color: red") + console.log(fieldNames) + alert("Your princess is in another castle...") +} else { + console.log("%cAll form fields present", 'color: lime') + alert("Ok!") +}