1.0.2 #9

Merged
emma merged 4 commits from 1.0.2 into main 2025-05-20 12:46:32 -07:00
2 changed files with 40 additions and 32 deletions
Showing only changes of commit 19eaf2d664 - Show all commits

View File

@ -20,7 +20,8 @@ Deno >=2.2 (not required if downloading .exe)
### Deno install
`deno task install` -> installs as global command `checkfields`
`deno install -g --allow-read --allow-write --allow-net --allow-env jsr:@bearmetal/pdf-tools`
-> installs as global command `pdf-tools`
### Compile

View File

@ -103,50 +103,57 @@ class RenameFields implements ITool {
[pdfPath, pattern, change] = await forceArgs(
[pdfPath, pattern, change],
[
["Please provide path to PDF:", (p) => !!p && p.endsWith(".pdf")],
[
"Please provide path to PDF (comma separated for multiple):",
(p) => !!p && p.endsWith(".pdf"),
],
"Please provide search string:",
"Please provide requested change:",
],
this.block,
);
const patternRegex = new RegExp(pattern);
const paths = pdfPath.split(",");
const pdf = await loadPdf(pdfPath);
const form = pdf.getForm();
const fields = form.getFields();
for (const pdfPath of paths) {
const patternRegex = new RegExp(pattern);
const foundUpdates: [string, callback][] = [];
const pdf = await loadPdf(pdfPath);
const form = pdf.getForm();
const fields = form.getFields();
for (const field of fields) {
const name = field.getName();
const match = patternRegex.exec(name);
if (match) {
const toChange = evaluateChange(change, match);
const preview = name.replace(new RegExp(patternRegex), toChange);
foundUpdates.push([
`${colorize(name, "red")} -> ${colorize(preview, "green")}`,
() => {
applyRename(field, name, patternRegex, toChange);
},
]);
const foundUpdates: [string, callback][] = [];
for (const field of fields) {
const name = field.getName();
const match = patternRegex.exec(name);
if (match) {
const toChange = evaluateChange(change, match);
const preview = name.replace(new RegExp(patternRegex), toChange);
foundUpdates.push([
`${colorize(name, "red")} -> ${colorize(preview, "green")}`,
() => {
applyRename(field, name, patternRegex, toChange);
},
]);
}
}
}
if (foundUpdates.length) {
cliLog("Found updates:", this.block);
await multiSelectMenuInteractive(
"Please select an option to apply",
foundUpdates,
{ terminalBlock: this.block },
if (foundUpdates.length) {
cliLog("Found updates:", this.block);
await multiSelectMenuInteractive(
"Please select an option to apply",
foundUpdates,
{ terminalBlock: this.block },
);
}
const path = await cliPrompt(
"Save to path (or hit enter to keep current):",
this.block,
);
await savePdf(pdf, path || pdfPath);
}
const path = await cliPrompt(
"Save to path (or hit enter to keep current):",
this.block,
);
await savePdf(pdf, path || pdfPath);
}
}
export default new RenameFields();