diff --git a/deno.json b/deno.json index 6246945..63d55c2 100644 --- a/deno.json +++ b/deno.json @@ -1,6 +1,6 @@ { "name": "@bearmetal/pdf-tools", - "version": "1.0.7", + "version": "1.0.8-a", "license": "GPL 3.0", "tasks": { "dev": "deno run -A --env-file=.env main.ts", diff --git a/tools/listFormFields.ts b/tools/listFormFields.ts index 77f8542..a75c64f 100644 --- a/tools/listFormFields.ts +++ b/tools/listFormFields.ts @@ -20,31 +20,10 @@ export class ListFormFields implements ITool { const form = await loadPdfForm(pdfPath); const fields = form.getFields(); - const height = this.block.getRenderHeight() - 1; - const fieldNames = fields.sort((a, b) => { - const aRect = a.acroField.getWidgets().find((e) => e.Rect())?.Rect() - ?.asRectangle(); - const bRect = b.acroField.getWidgets().find((e) => e.Rect())?.Rect() - ?.asRectangle(); - - if (aRect && bRect) { - if (aRect.x !== bRect.x) { - return aRect.x - bRect.x; // Sort left to right - } else { - return bRect.y - aRect.y; // If x is equal, sort top to bottom - } - } - return a.getName().localeCompare(b.getName()); - }).map((f) => f.getName()); - const maxLength = Math.max(...fieldNames.map((f) => f.length)) + 4; + const fieldNames = fields.map((f) => f.getName()); const lines = []; - for (let i = 0; i < height; i++) { - let line = ""; - for (let j = 0; j < fieldNames.length; j += height) { - const fieldName = fieldNames[i + j] ?? ""; - line += fieldName.padEnd(maxLength, " "); - } - lines.push(line); + for (const fieldName of fieldNames) { + lines.push(fieldName); } this.block.setLines(lines, [0, 1]); await cliAlert("", this.block);