### Install pdf2json Globally Source: https://github.com/modesty/pdf2json/blob/master/readme.md Install the pdf2json package globally to enable direct command-line execution. ```javascript npm install pdf2json -g ``` -------------------------------- ### Verify Node.js Version Source: https://github.com/modesty/pdf2json/blob/master/readme.md Check the installed Node.js version before proceeding with the installation. Ensure it meets the project's requirements. ```terminal nodejs --version v0.10.22 ``` -------------------------------- ### Verify pdf2json Installation Source: https://github.com/modesty/pdf2json/blob/master/readme.md Check the installation path and version of the pdf2json command-line tool. This confirms successful global installation. ```terminal which pdf2json /usr/bin/pdf2json pdf2json --version 0.6.2 ``` -------------------------------- ### Install pdf2json Locally or Globally Source: https://context7.com/modesty/pdf2json/llms.txt Install the pdf2json module using npm for either programmatic use (local) or command-line interface (global). ```bash npm install pdf2json ``` ```bash npm install -g pdf2json ``` -------------------------------- ### Example pdf2json --json output Source: https://context7.com/modesty/pdf2json/llms.txt This example demonstrates how to use the -j flag to output JSON and pipe it to grep to filter for the JSON object. ```bash pdf2json -f ./form.pdf -o ./out/ -t -c -j | grep ' {' ``` ```json { "version": "4.0.3", "input": "./form.pdf", "outputs": [ { "type": "json", "path": "./out/form.json" }, { "type": "fields", "path": "./out/form.fields.json" }, { "type": "content", "path": "./out/form.content.txt" } ], "stats": { "input": 1, "success": 1, "failed": 0 }, "errors": [], "elapsedMs": 187 } ``` -------------------------------- ### Show Version or Help Info Source: https://github.com/modesty/pdf2json/blob/master/readme.md Use these flags to display the version number or more detailed help information for the command-line utility. ```javascript node pdf2json.js -v ``` ```javascript node pdf2json.js -h ``` -------------------------------- ### Show pdf2json version or help Source: https://context7.com/modesty/pdf2json/llms.txt Use the -v flag to display the version and the -h flag to show help information. ```bash pdf2json -v ``` ```bash pdf2json -h ``` -------------------------------- ### Verify Node Installation and Path Source: https://github.com/modesty/pdf2json/blob/master/readme.md Confirm that the 'node' command is correctly linked and accessible in the system's PATH. This verifies the symbolic link creation. ```terminal which node /usr/sbin/node node --version v4.5.0 ``` -------------------------------- ### Install pdf2json Globally Source: https://github.com/modesty/pdf2json/blob/master/readme.md Install the pdf2json package globally using npm. This makes the pdf2json command-line tool available system-wide. ```terminal $ npm install -g pdf2json npm http GET https://registry.npmjs.org/pdf2json npm http 304 https://registry.npmjs.org/pdf2json /usr/bin/pdf2json -> /usr/lib/node_modules/pdf2json/bin/pdf2json pdf2json@0.6.1 /usr/lib/node_modules/pdf2json ``` -------------------------------- ### Importing Dictionary Constants Source: https://github.com/modesty/pdf2json/blob/master/readme.md Demonstrates how to import the color, font face, and font style constants. The import path differs based on the library version. ```javascript import { kColors, kFontFaces, kFontStyles } from "./lib/pdfconst.js"; // <-- pre 3.1.0 ``` ```javascript import { kColors, kFontFaces, kFontStyles } from "pdf2json"; // <-- since 3.1.0 ``` -------------------------------- ### PDF Metadata Example Source: https://github.com/modesty/pdf2json/blob/master/readme.md Example of the full metadata structure for a parsed PDF document, as of v2.0.0. This replaces the older 'Agency' and 'Id' fields. ```json Meta: { PDFFormatVersion: '1.7', IsAcroFormPresent: true, IsXFAPresent: false, Author: 'SE:W:CAR:MP', Subject: 'U.S. Individual Income Tax Return', Creator: 'Adobe Acrobat Pro 10.1.8', Producer: 'Adobe Acrobat Pro 10.1.8', CreationDate: "D:20131203133943-08'00'", ModDate: "D:20140131180702-08'00'", Metadata: { 'xmp:modifydate': '2014-01-31T18:07:02-08:00', 'xmp:createdate': '2013-12-03T13:39:43-08:00', 'xmp:metadatadate': '2014-01-31T18:07:02-08:00', 'xmp:creatortool': 'Adobe Acrobat Pro 10.1.8', 'dc:format': 'application/pdf', 'dc:description': 'U.S. Individual Income Tax Return', 'dc:creator': 'SE:W:CAR:MP', 'xmpmm:documentid': 'uuid:4d81e082-7ef2-4df7-b07b-8190e5d3eadf', 'xmpmm:instanceid': 'uuid:7ea96d1c-3d2f-284a-a469-f0f284a093de', 'pdf:producer': 'Adobe Acrobat Pro 10.1.8', 'adhocwf:state': '1', 'adhocwf:version': '1.1' } } ``` -------------------------------- ### Instantiate PDFParser Source: https://context7.com/modesty/pdf2json/llms.txt Create a new PDFParser instance. Pass `true` to `needRawText` to enable `getRawTextContent()`. An optional password string can be provided for encrypted PDFs. ```javascript import PDFParser from "pdf2json"; // Basic parser (JSON output only) const pdfParser = new PDFParser(); // Parser that also captures raw text const pdfParserWithText = new PDFParser(null, true); // Parser for a password-protected PDF const pdfParserSecure = new PDFParser(null, false, "mySecretPassword"); ```