V1 standalone complete
This commit is contained in:
commit
597c52eefe
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
*.exe
|
36
README.md
Normal file
36
README.md
Normal file
@ -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 <path to PDF> <comma-separated list of paths to CS class files>`
|
||||||
|
-OR- `checkfields` and follow prompts.
|
||||||
|
|
||||||
|
### Output
|
||||||
|
|
||||||
|
> All form fields present!
|
||||||
|
|
||||||
|
-OR-
|
||||||
|
|
||||||
|
> The following field names are not present in the CS code
|
||||||
|
|
||||||
|
> \<list of missing form fields\>
|
11
deno.json
Normal file
11
deno.json
Normal file
@ -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"
|
||||||
|
}
|
||||||
|
}
|
54
deno.lock
generated
Normal file
54
deno.lock
generated
Normal file
@ -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"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
31
main.ts
Normal file
31
main.ts
Normal file
@ -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(`(?<!//\s?)case ?"${f}"`)
|
||||||
|
return !csFiles.some(c => 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!")
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user