{"analyzedAt":"2022-10-07T10:46:40.151Z","collected":{"metadata":{"name":"@sparticuz/pdffiller","scope":"sparticuz","version":"4.2.0","description":"Take an existing PDF Form and data and PDF Filler will create a new PDF with all given fields populated.","keywords":["nodejs","pdftk","fdf","pdffiller","pdf","pdftk-java"],"date":"2022-10-06T16:57:14.741Z","author":{"name":"original: John Taylor and David Baldwynn; stream fork: Jason Phillips, stream fork, typescript fork: Kyle McNally"},"publisher":{"username":"sparticuz","email":"kyle@kmcnally.net"},"maintainers":[{"username":"sparticuz","email":"kyle@kmcnally.net"}],"repository":{"type":"git","url":"git+https://github.com/Sparticuz/pdffiller-stream.git"},"links":{"npm":"https://www.npmjs.com/package/%40sparticuz%2Fpdffiller","homepage":"https://github.com/Sparticuz/pdffiller-stream#readme","repository":"https://github.com/Sparticuz/pdffiller-stream","bugs":"https://github.com/Sparticuz/pdffiller-stream/issues"},"license":"MIT","devDependencies":{"@rushstack/eslint-patch":"^1.2.0","@sparticuz/eslint-config":"^7.1.8","@tsconfig/node14":"^1.0.3","@types/node":"^16.11.64","ava":"^4.3.3","c8":"^7.12.0","eslint":"^8.24.0","eslint-config-prettier":"^8.5.0","eslint-plugin-prettier":"^4.2.1","prettier":"^2.7.1","ts-node":"^10.9.1","typescript":"^4.8.4"},"releases":[{"from":"2022-09-07T00:00:00.000Z","to":"2022-10-07T00:00:00.000Z","count":2},{"from":"2022-07-09T00:00:00.000Z","to":"2022-10-07T00:00:00.000Z","count":3},{"from":"2022-04-10T00:00:00.000Z","to":"2022-10-07T00:00:00.000Z","count":3},{"from":"2021-10-07T00:00:00.000Z","to":"2022-10-07T00:00:00.000Z","count":3},{"from":"2020-10-07T00:00:00.000Z","to":"2022-10-07T00:00:00.000Z","count":6}],"hasTestScript":true,"readme":"PDF Filler Stream\n======\n\n[![npm version](https://badge.fury.io/js/%40sparticuz%2Fpdffiller.svg)](https://badge.fury.io/js/%40sparticuz%2Fpdffiller) ![Node.js CI](https://github.com/Sparticuz/pdffiller-stream/workflows/Node.js%20CI/badge.svg) ![CodeQL](https://github.com/Sparticuz/pdffiller-stream/workflows/CodeQL/badge.svg)\n\n> This is a fork of the [pdf-filler](https://github.com/pdffillerjs/pdffiller) package, modified to return promises and readable streams, by piping data in/out of a spawned pdftk process instead of temporarily writing files to disk.\n\n> The goal is cleaner integration, in eg. a microservices context, where it is preferable not to write multiple temporary files to disk and where you may wish to stream the generated pdf directly to a service like AWS.\n\nA node.js PDF form field data filler and FDF generator toolkit. This essentially is a wrapper around the PDF Toolkit library [PDF ToolKit](http://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/).\n\nAs of version 4.0.0, this library now targets [pdftk-java](https://gitlab.com/pdftk-java/pdftk), a modern fork of pdftk.\n\n\nQuick start\n-----------\n\n**You must first have `pdftk` (from pdftk-java, found [here](https://gitlab.com/pdftk-java/pdftk)) installed correctly on your platform.**\n\nThen, install this library:\n\n```bash\nnpm install @sparticuz/pdffiller --save\n```\n\n**Note for AWS Lambda users, you may use a pdftk layer, found [here](https://github.com/Sparticuz/pdftk-aws-lambda)**\n\n## Examples\n\n#### 1.Fill PDF with existing FDF Data\n\n````javascript\nimport fillForm from '@sparticuz/pdffiller';\n\nconst sourcePDF = \"test/test.pdf\";\n\nconst data = {\n    \"last_name\" : \"John\",\n    \"first_name\" : \"Doe\",\n    \"date\" : \"Jan 1, 2013\",\n    \"football\" : \"Off\",\n    \"baseball\" : \"Yes\",\n    \"basketball\" : \"Off\",\n    \"hockey\" : \"Yes\",\n    \"nascar\" : \"Off\"\n};\n\nconst output = await fillForm(sourcePDF, data);\n// output will be instance of stream.Readable\n````\n\nThis will take the test.pdf, fill the fields with the data values and stream a filled in, read-only PDF.\n\nA chainable convenience method `toFile` is attached to the response, if you simply wish to write the stream to a file with no fuss:\n\n```javascript\nfillForm(sourcePDF, data)\n    .toFile('outputFile.PDF')\n    .then(() => {\n        // your file has been written\n    }).catch((err) => {\n        console.log(err);\n    });\n```\n\nYou could also stream the resulting data directly to AWS, doing something like this with an instantiated `s3` client:\n\n```javascript\nfillForm(sourcePDF, data)\n    .then((outputStream) => {\n        const Body = outputStream;\n        const Bucket = 'some-bucket';\n        const Key = 'myFancyNewFilledPDF';\n        const ContentType = 'application/pdf';\n\n        const uploader = new AWS.S3.ManagedUpload({\n            params: {Bucket, Key, Body, ContentType},\n            service: s3,\n        });\n\n        uploader.promise().then((data) => {/* do something with AWS response */})\n\n    }).catch((err) => {\n        console.log(err);\n    });\n\n```\n\nCalling `fillForm()` with `shouldFlatten = false` will leave any unmapped fields still editable, as per the `pdftk` command specification.\n\n```javascript\n\nconst shouldFlatten = false;\n\nfillForm(sourcePDF, data, shouldFlatten)\n    .then((outputStream) {\n        // etc, same as above\n    })\n```\n\n\n#### 2. Generate FDF Template from PDF\n\n````javascript\nimport { generateFDFTemplate } from '@sparticuz/pdffiller';\n\nconst sourcePDF = \"test/test.pdf\";\n\nconst FDF_data = generateFDFTemplate(sourcePDF).then((fdfData) => {\n    console.log(fdfData);\n}).catch((err) => {\n    console.log(err);\n});\n\n````\n\nThis will print out this\n```json\n{\n    \"last_name\" : \"\",\n    \"first_name\" : \"\",\n    \"date\" : \"\",\n    \"football\" : \"\",\n    \"baseball\" : \"\",\n    \"basketball\" : \"\",\n    \"hockey\" : \"\",\n    \"nascar\" : \"\"\n}\n```\n\n#### 3. Map form fields to PDF fields\n````javascript\nimport { mapForm2PDF } from '@sparticuz/pdffiller';\n\nconst conversionMap = {\n\n    \"lastName\": \"last_name\",\n    \"firstName\": \"first_name\",\n    \"Date\": \"date\",\n    \"footballField\": \"football\",\n    \"baseballField\": \"baseball\",\n    \"bballField\": \"basketball\",\n    \"hockeyField\": \"hockey\",\n    \"nascarField\": \"nascar\"\n};\n\nconst FormFields = {\n    \"lastName\" : \"John\",\n    \"firstName\" : \"Doe\",\n    \"Date\" : \"Jan 1, 2013\",\n    \"footballField\" : \"Off\",\n    \"baseballField\" : \"Yes\",\n    \"bballField\" : \"Off\",\n    \"hockeyField\" : \"Yes\",\n    \"nascarField\" : \"Off\"\n};\n\nmapForm2PDF(data, convMap).then((mappedFields) => {\n    console.log(mappedFields);\n});\n````\n\nThis will print out the object below.\n```json\n\n{\n    \"last_name\" : \"John\",\n    \"first_name\" : \"Doe\",\n    \"date\" : \"Jan 1, 2013\",\n    \"football\" : \"Off\",\n    \"baseball\" : \"Yes\",\n    \"basketball\" : \"Off\",\n    \"hockey\" : \"Yes\",\n    \"nascar\" : \"Off\"\n\n}\n```\n\n#### 4. Convert fieldJson to FDF data\n````javascript\nimport { convFieldJson2FDF } from '@sparticuz/pdffiller';\n\nconst fieldJson = [\n    {\n        \"title\" : \"last_name\",\n        \"fieldfieldType\": \"Text\",\n        \"fieldValue\": \"Doe\"\n    },\n    {\n        \"title\" : \"first_name\",\n        \"fieldfieldType\": \"Text\",\n        \"fieldValue\": \"John\"\n    },\n    {\n        \"title\" : \"date\",\n        \"fieldType\": \"Text\",\n        \"fieldValue\": \"Jan 1, 2013\"\n    },\n    {\n        \"title\" : \"football\",\n        \"fieldType\": \"Button\",\n        \"fieldValue\": false\n    },\n    {\n        \"title\" : \"baseball\",\n        \"fieldType\": \"Button\",\n        \"fieldValue\": true\n    },\n    {\n        \"title\" : \"basketball\",\n        \"fieldType\": \"Button\"\n        \"fieldValue\": false\n    },\n    {\n        \"title\" : \"hockey\",\n        \"fieldType\": \"Button\"\n        \"fieldValue\": true\n    },\n    {\n        \"title\" : \"nascar\",\n        \"fieldType\": \"Button\"\n        \"fieldValue\": false\n    }\n];\n\n\nconst FDFData = convFieldJson2FDF(data);\n\nconsole.log(FDFData)\n````\n\nThis will print out:\n\n````json\n{\n    \"last_name\" : \"John\",\n    \"first_name\" : \"Doe\",\n    \"date\" : \"Jan 1, 2013\",\n    \"football\" : \"Off\",\n    \"baseball\" : \"Yes\",\n    \"basketball\" : \"Off\",\n    \"hockey\" : \"Yes\",\n    \"nascar\" : \"Off\"\n};\n````"},"npm":{"downloads":[{"from":"2022-10-06T00:00:00.000Z","to":"2022-10-07T00:00:00.000Z","count":71},{"from":"2022-09-30T00:00:00.000Z","to":"2022-10-07T00:00:00.000Z","count":88},{"from":"2022-09-07T00:00:00.000Z","to":"2022-10-07T00:00:00.000Z","count":179},{"from":"2022-07-09T00:00:00.000Z","to":"2022-10-07T00:00:00.000Z","count":364},{"from":"2022-04-10T00:00:00.000Z","to":"2022-10-07T00:00:00.000Z","count":658},{"from":"2021-10-07T00:00:00.000Z","to":"2022-10-07T00:00:00.000Z","count":1336}],"starsCount":0},"github":{"forkOf":"jasonphillips/pdffiller-stream","starsCount":0,"forksCount":0,"subscribersCount":2,"issues":{"count":26,"openCount":3,"distribution":{"3600":13,"10800":1,"32400":1,"97200":1,"291600":1,"874800":0,"2624400":0,"7873200":3,"23619600":2,"70858800":4,"212576400":0},"isDisabled":false},"contributors":[{"username":"Sparticuz","commitsCount":74},{"username":"whitef0x0","commitsCount":29},{"username":"jasonphillips","commitsCount":14},{"username":"JaakkoL","commitsCount":3},{"username":"anperez78","commitsCount":3},{"username":"rhaseven7h","commitsCount":2},{"username":"johntayl","commitsCount":2},{"username":"g3k0","commitsCount":2},{"username":"scotato","commitsCount":1},{"username":"madsnedergaard","commitsCount":1},{"username":"mnort9","commitsCount":1},{"username":"kevitan","commitsCount":1},{"username":"yoz","commitsCount":1},{"username":"ztzven","commitsCount":1},{"username":"webtaculars","commitsCount":1},{"username":"SChetwynd","commitsCount":1}],"commits":[{"from":"2022-09-30T00:00:00.000Z","to":"2022-10-07T00:00:00.000Z","count":4},{"from":"2022-09-07T00:00:00.000Z","to":"2022-10-07T00:00:00.000Z","count":4},{"from":"2022-07-09T00:00:00.000Z","to":"2022-10-07T00:00:00.000Z","count":12},{"from":"2022-04-10T00:00:00.000Z","to":"2022-10-07T00:00:00.000Z","count":12},{"from":"2021-10-07T00:00:00.000Z","to":"2022-10-07T00:00:00.000Z","count":13}]},"source":{"files":{"readmeSize":6025,"testsSize":261138,"hasNpmIgnore":true},"linters":["editorconfig","eslint","prettier"]}},"evaluation":{"quality":{"carefulness":0.9199999999999999,"tests":0.6,"health":1,"branding":0},"popularity":{"communityInterest":18,"downloadsCount":121.33333333333333,"downloadsAcceleration":0.5754185692541857,"dependentsCount":0},"maintenance":{"releasesFrequency":1,"commitsFrequency":0.9,"openIssues":1,"issuesDistribution":0.9}},"score":{"final":0.6190423799837352,"detail":{"quality":0.8364556389013833,"popularity":0.051824214291500505,"maintenance":0.9999063237465573}}}