{"bugs":{"url":"https://github.com/Hopding/pdf-lib/issues"},"dist":{"shasum":"5b0d595930a8ca72756881956965141bcec6fde2","tarball":"https://registry.npmjs.org/pdf-lib/-/pdf-lib-0.6.2-rc4.tgz","fileCount":505,"integrity":"sha512-bJy/tzvpWlRkw6Hkz6o7dvoOWLN46Z1HOKN43LbAWKaxsxHN/0UdtnySdDaau/6oCaZgNDRgzSNBUWXg3IOusQ==","signatures":[{"sig":"MEYCIQCBxSK46LRsjxyprQqDwgNwY/02DBk82zboolLvpwZ+dwIhALgUJCuLWX1u+dKatufA6s413Umi4KLIIZEuM8G1mgB7","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":3986755,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJczifFCRA9TVsSAnZWagAAzq0P/2H3WxRqSjkINsFMpreI\nkFfZmDbePLVqW93GJD8gD7xSWyj9qtHcz92p9vOqw174yltZ5phbBLXh/Dab\nnuaJ174oVrEafN5RcJRLc/3N+BRS7vF/00whFjZklUXRUpetzHXz+JYvbGZ3\nai/kv5Wi4iKnsdqRJWe14GozAhuKc25k5piMwrtKaz3Lv1nxrVoSc2qrqFR7\nvYrxQNqdlPfFguRNFmy+NJjkcHl7b3MTWW4M3+OV2S63zLwJVRrZIHSNKGDM\nmaJhoS4KJjDUOQEhxJL7ggVCB6yISTNo5JJ2GrGOCebWq1gwazlQldbr0dKY\nfVO9cTM8Rp62o2Xq5duH8IrDRL6ex3c8CzQf7KBIjSgJO064emuM3kNgoscX\n/jZnr4t91bM76GBoFH78nvlxCVakgY3kyUpqu2mBDS/5/yNlr/2dNlcVMzgS\nJAJuT1d8tP+pkSQPBiyi82xYlWj5mlaXaplvCzq2jNi19+Ogs9OtkAmDfQvs\neGjVGs5JXAGujr0UDIljsnPq6Jd5ZcaeeElL5c59jO2BGKyyWr7I/az/j1Cy\nkcAA/DqAUaFi3PYryK5tOfELjogKz9fkgb3WX4N5CT655PV3GfaePijEds5e\nrjXsxpkVXrXpVUDMbx/8xhj+hynMeToh06uI/xNBoX8CCnFBRGin13h3w5Sz\n1Vua\r\n=06++\r\n-----END PGP SIGNATURE-----\r\n"},"jest":{"globals":{"ts-jest":{"tsConfigFile":"./tsconfig.json"}},"testRegex":"(/__tests__/.*|(\\.|/)(test|spec))$","transform":{"^.+$":"ts-jest"},"collectCoverage":true,"moduleNameMapper":{"^utils":"<rootDir>/src/utils/index.ts","^core/(.*)":"<rootDir>/src/core/$1","^utils/(.*)":"<rootDir>/src/utils/$1"},"collectCoverageFrom":["<rootDir>/src/**/*.ts"],"moduleFileExtensions":["ts","js","json","node"],"testResultsProcessor":"./node_modules/jest-junit","testPathIgnorePatterns":["<rootDir>/integration-tests/","<rootDir>/node_modules/","<rootDir>/__tests__/tsconfig.json","(.*).spec.ts.snap","PDFOperatorSingletonTest.ts"],"coveragePathIgnorePatterns":["<rootDir>/node_modules/","<rootDir>/src/types/"]},"main":"lib/index.js","name":"pdf-lib","types":"lib/index.d.ts","unpkg":"dist/pdf-lib.min.js","author":{"name":"Andrew Dillon","email":"andrew.dillon.j@gmail.com"},"module":"es/index.js","readme":"<h1 align=\"center\">pdf-lib</h1>\n\n<div align=\"center\">\n  <strong>Create and modify PDF documents in any JavaScript environment.</strong>\n</div>\n<div align=\"center\">\n  Designed to work in any modern JavaScript runtime. Tested in Node, Browser, and React Native environments.\n</div>\n\n<br />\n\n<div align=\"center\">\n  <!-- NPM Version -->\n  <a href=\"https://www.npmjs.com/package/pdf-lib\">\n    <img\n      src=\"https://img.shields.io/npm/v/pdf-lib.svg?style=flat-square\"\n      alt=\"NPM Version\"\n    />\n  </a>\n  <!-- Build Status -->\n  <a href=\"https://circleci.com/gh/Hopding/pdf-lib\">\n    <img\n      src=\"https://img.shields.io/circleci/project/github/Hopding/pdf-lib/master.svg?style=flat-square&label=CircleCI\"\n      alt=\"CircleCI Build Status\"\n    />\n  </a>\n  <!-- Prettier Badge -->\n  <a href=\"https://prettier.io/\">\n    <img\n      src=\"https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square\"\n      alt=\"Prettier Badge\"\n    />\n  </a>\n</div>\n\n<div align=\"center\">\n  <h3>\n    <a href=\"https://github.com/Hopding/pdf-lib/tree/master/docs\">\n      Documentation\n    </a>\n    <span> | </span>\n    <a href=\"https://github.com/Hopding/pdf-lib/tree/master/examples\">\n      Examples\n    </a>\n  </h3>\n</div>\n\n## Table of Contents\n* [Motivation](#motivation)\n* [Features](#features)\n* [Usage Examples](#usage-examples)\n  * [Document Creation](#document-creation)\n  * [Document Modification](#document-modification)\n  * [Copying Pages](#copying-pages)\n  * [Embed Font and Measure Text](#embed-font-and-measure-text)\n* [Installation](#installation)\n* [API Documentation](#api-documentation)\n* [Contributing](#contributing)\n* [Prior Art](#prior-art)\n* [License](#license)\n\n## Motivation\n`pdf-lib` was created to address the JavaScript ecosystem's lack of robust support for PDF manipulation (especially for PDF _modification_).\n\nTwo of `pdf-lib`'s design requirements since its inception are to:\n1. Support modification (editing) of existing documents.\n2. Work in all JavaScript environments - not just in Node or the browser.\n\nThere are other good open source JavaScript PDF libraries available. However, most of them can only _create_ documents, they cannot _modify_ existing ones (e.g. [`pdfkit`](https://github.com/devongovett/pdfkit), [`jspdf`](https://github.com/MrRio/jsPDF), [`pdfmake`](https://github.com/bpampuch/pdfmake)). [`hummus`](https://github.com/galkahana/HummusJS) is a NodeJS library capable of both creating and modifying PDF documents. However, `hummus` is a Node wrapper around a [C++ library](https://github.com/galkahana/PDF-Writer). This means that it cannot run in _all_ JavaScript environments. For example, you cannot use `hummus` in the Browser or in React Native.\n\n## Features\n* Create new PDFs\n* Modify existing PDFs\n* _**New:**_ [Copy pages between PDFs](#copying-pages)\n* Add Pages\n* Insert Pages\n* Remove Pages\n* Draw Text\n* Draw Images\n* Draw Vector Graphics\n* Embed Fonts\n  * _**New:**_ UTF-8 and UTF-16 character sets are supported\n  * _**New:**_ Measure width and height of text\n* Embed Images\n\n## Usage Examples\nMore detailed examples are available [here](https://github.com/Hopding/pdf-lib/tree/master/examples).\n\n### Document Creation\n```javascript\nimport { PDFDocumentFactory, PDFDocumentWriter, StandardFonts, drawText } from 'pdf-lib';\n\nconst pdfDoc = PDFDocumentFactory.create();\nconst [timesRomanRef, timesRomanFont] = pdfDoc.embedStandardFont(\n  StandardFonts.TimesRoman,\n);\n\nconst page = pdfDoc\n  .createPage([350, 500])\n  .addFontDictionary('TimesRoman', timesRomanRef);\n\nconst contentStream = pdfDoc.createContentStream(\n  drawText(timesRomanFont.encodeText('Creating PDFs in JavaScript is awesome!'), {\n    x: 50,\n    y: 450,\n    size: 15,\n    font: 'TimesRoman',\n    colorRgb: [0, 0.53, 0.71],\n  }),\n);\n\npage.addContentStreams(pdfDoc.register(contentStream));\n\npdfDoc.addPage(page);\n\nconst pdfBytes = PDFDocumentWriter.saveToBytes(pdfDoc);\n```\n\n### Document Modification\n```javascript\nimport { PDFDocumentFactory, PDFDocumentWriter, StandardFonts, drawText } from 'pdf-lib';\n\n// This should be a Uint8Array.\n// This data can be obtained in a number of different ways.\n// If your running in a Node environment, you could use fs.readFile().\n// In the browser, you could make a fetch() call and use res.arrayBuffer().\nconst existingPdfDocBytes = ...\n\nconst pdfDoc = PDFDocumentFactory.load(existingPdfDocBytes);\nconst [helveticaRef, helveticaFont] = pdfDoc.embedStandardFont(\n  StandardFonts.Helvetica,\n);\n\nconst pages = pdfDoc.getPages();\nconst page  = pages[0];\n\npage.addFontDictionary('Helvetica', helveticaRef);\n\nconst contentStream = pdfDoc.createContentStream(\n  drawText(helveticaFont.encodeText('This text was added to the PDF with JavaScript!'), {\n    x: 25,\n    y: 25,\n    size: 24,\n    font: 'Helvetica',\n    colorRgb: [0.95, 0.26, 0.21],\n  }),\n);\n\npage.addContentStreams(pdfDoc.register(contentStream));\n\nconst pdfBytes = PDFDocumentWriter.saveToBytes(pdfDoc);\n```\n\n### Copying Pages\n```javascript\nimport { PDFDocumentFactory, PDFDocumentWriter } from 'pdf-lib';\n\n// These should be a Uint8Arrays. (see Document Modification example for more details)\nconst firstDonorPdfBytes = ...\nconst secondDonorPdfBytes = ...\n\nconst firstDonorPdfDoc = PDFDocumentFactory.load(firstDonorPdfBytes);\nconst secondDonorPdfDoc = PDFDocumentFactory.load(secondDonorPdfBytes);\n\n// We'll copy the fourth page from the first donor document, and the\n// first page from the second donor document.\nconst firstDonorPage = firstDonorPdfDoc.getPages()[3];\nconst secondDonorPage = secondDonorPdfDoc.getPages()[0];\n\nconst pdfDoc = PDFDocumentFactory.create();\n\n// Copy over the pages from the donor documents into our new document\npdfDoc.addPage(firstDonorPage);\npdfDoc.insertPage(0, secondDonorPage);\n\nconst pdfBytes = PDFDocumentWriter.saveToBytes(pdfDoc);\n```\n\n### Embed Font and Measure Text\nThis example demonstrates the use of the `font.widthOfTextAtSize()` and \n`font.heightOfFontAtSize()` methods for a `font` embedded with \n`pdfDoc.embedNonstandardFont`. But note that these methods also exist on standard \nfonts embedded with `pdfDoc.embedStandardFont`.\n```javascript\nimport { PDFDocumentFactory, PDFDocumentWriter, drawText, drawRectangle } from 'pdf-lib';\n\n// This should be a Uint8Array.\n// This data can be obtained in a number of different ways.\n// If your running in a Node environment, you could use fs.readFile().\n// In the browser, you could make a fetch() call and use res.arrayBuffer().\nconst fontBytes = ...\n\nconst pdfDoc = PDFDocumentFactory.create();\nconst [fontRef, font] = pdfDoc.embedNonstandardFont(fontBytes);\n\nconst page = pdfDoc\n  .createPage([350, 500])\n  .addFontDictionary('FontName', fontRef);\n\nconst text = 'This is text in an embedded font!';\nconst textSize = 15;\nconst textWidth = font.widthOfTextAtSize(text, textSize);\nconst textHeight = font.heightOfFontAtSize(textSize);\n\nconst contentStream = pdfDoc.createContentStream(\n  // Draw text on page\n  drawText(font.encodeText(text), {\n    x: 50,\n    y: 450,\n    size: textSize,\n    font: 'FontName',\n    colorRgb: [0, 0.53, 0.71],\n  }),\n  // Draw a box around the text\n  drawRectangle({\n    x: 50,\n    y: 450,\n    width: textWidth,\n    height: textHeight,\n    borderColorRgb: [1],\n    borderWidth: 0.5,\n  }),\n);\n\npage.addContentStreams(pdfDoc.register(contentStream));\n\npdfDoc.addPage(page);\n\nconst pdfBytes = PDFDocumentWriter.saveToBytes(pdfDoc);\n```\n\n## Installation\n### NPM Module\nTo install the latest stable version:\n```bash\n# With npm\nnpm install --save pdf-lib\n\n# With yarn\nyarn add pdf-lib\n```\nThis assumes you're using [npm](https://www.npmjs.com/) or [yarn](https://yarnpkg.com/lang/en/) as your package manager.\n\n### UMD Module\nYou can also download `pdf-lib` as a UMD module from [unpkg](https://unpkg.com/#/). The UMD builds have been compiled to ES5, so they should work [in any modern browser](https://caniuse.com/#feat=es5). UMD builds are useful if you aren't using a package manager or module bundler. For example, you can use them directly in the `<script>` tag of an HTML page.\n\nThe following builds are available:\n\n* https://unpkg.com/pdf-lib/dist/pdf-lib.js\n* https://unpkg.com/pdf-lib/dist/pdf-lib.min.js\n\nWhen using a UMD build, you will have access to a global `window.PDFLib` variable. This variable contains all of the classes and functions exported by `pdf-lib`. For example:\n\n```javascript\n// NPM module\nimport { PDFDocumentFactory, drawText } from 'pdf-lib';\n\n// UMD module\nvar PDFDocumentFactory = PDFLib.PDFDocumentFactory;\nvar drawText = PDFLib.drawText;\n```\n\n## API Documentation\nAPI documentation is available [here](https://github.com/Hopding/pdf-lib/tree/master/docs).\n\n## Contributing\nWe welcome contributions from the open source community! If you are interested in contributing to `pdf-lib`, please take a look at the [CONTRIBUTING.md](https://github.com/Hopding/pdf-lib/blob/master/CONTRIBUTING.md) file. It contains information to help you get `pdf-lib` setup and running on your machine.\n\n## Prior Art\n* [`pdfkit`](https://github.com/devongovett/pdfkit) is a PDF generation library for Node and the Browser. This library was immensely helpful as a reference and existence proof when creating `pdf-lib`. `pdfkit`'s code for [font embedding](https://github.com/Hopding/pdf-lib/blob/AddDocumentation/src/core/pdf-structures/factories/PDFFontFactory.ts#L64-L68), [PNG embedding](https://github.com/Hopding/pdf-lib/blob/AddDocumentation/src/core/pdf-structures/factories/PNGXObjectFactory.ts#L19-L23), and [JPG embedding](https://github.com/Hopding/pdf-lib/blob/AddDocumentation/src/core/pdf-structures/factories/JPEGXObjectFactory.ts#L32-L36) was especially useful.\n* [`jspdf`](https://github.com/MrRio/jsPDF) is a PDF generation library for the browser.\n* [`pdfmake`](https://github.com/bpampuch/pdfmake) is a PDF generation library for the browser.\n* [`hummus`](https://github.com/galkahana/HummusJS) is a PDF generation and modification library for Node environments. `hummus` is a Node wrapper around a [C++ library](https://github.com/galkahana/PDF-Writer).\n* [`react-native-pdf-lib`](https://github.com/Hopding/react-native-pdf-lib) is a PDF generation and modification library for React Native environments. `react-native-pdf-lib` is a wrapper around [C++](https://github.com/galkahana/PDF-Writer) and [Java](https://github.com/TomRoush/PdfBox-Android) libraries.\n* [`pdfassembler`](https://github.com/DevelopingMagic/pdfassembler) is a PDF generation and modification library for Node and the browser. It requires some knowledge about the logical structure of PDF documents to use.\n\n## License\n[MIT](https://choosealicense.com/licenses/mit/)\n","license":"MIT","scripts":{"docs":"node Makefile.js docs","lint":"node Makefile.js lint","make":"node Makefile.js","test":"jest --runInBand --no-coverage","testw":"jest --no-coverage --watch","it:node":"ts-node --module commonjs -r tsconfig-paths/register __integration_tests__/runners/node/index.ts","typecheck":"tsc --noEmit","releaseNext":"node Makefile.js releaseNext","releaseLatest":"node Makefile.js releaseLatest","test:coverage":"jest --runInBand","coverage-report":"open coverage/lcov-report/index.html","it:node:profile":"node Makefile.js runFlamebearerTest","jest:clear-cache":"rm -rf $TMPDIR/jest*"},"_npmUser":{"name":"hopding","email":"andrew.dillon.j@gmail.com"},"homepage":"https://github.com/Hopding/pdf-lib#readme","keywords":["pdf-lib","pdf","document","create","modify","creation","modification","edit","editing","typescript","javascript","library"],"jest-junit":{"output":"./coverage/junit.xml"},"repository":{"url":"git+https://github.com/Hopding/pdf-lib.git","type":"git"},"description":"Library for creating and modifying PDF files in JavaScript","directories":{},"licenseText":"MIT License\n\nCopyright (c) 2018 Andrew Dillon\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","maintainers":[{"name":"hopding","email":"andrew.dillon.j@gmail.com"}],"contributors":[{"url":"https://github.com/jerp","name":"jerp"},{"url":"https://github.com/gregbacchus","name":"Greg Bacchus"}],"dependencies":{"pako":"^1.0.6","lodash":"^4.17.4","png-ts":"^0.0.3","proxy-polyfill":"^0.3.0","@pdf-lib/fontkit":"^0.0.4","@pdf-lib/standard-fonts":"^0.0.4"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jest":"^22.4.3","chalk":"^2.4.1","faker":"^4.1.0","rollup":"^0.68.0","tslint":"^5.11.0","shelljs":"^0.8.3","ts-jest":"^22.4.2","ts-node":"^6.0.5","typedoc":"^0.11.1","inquirer":"^6.0.0","prettier":"^1.15.2","relative":"^3.0.2","jest-junit":"^3.6.0","typescript":"^2.7.2","@types/jest":"^22.2.2","@types/node":"^9.6.0","@types/pako":"^1.0.0","@types/faker":"^4.1.2","@types/lodash":"^4.14.110","tsconfig-paths":"^3.3.2","@types/inquirer":"^0.0.41","rollup-plugin-json":"^3.1.0","rollup-plugin-terser":"^3.0.0","rollup-plugin-analyzer":"^2.0.3","rollup-plugin-commonjs":"^9.1.3","tslint-config-prettier":"^1.17.0","typedoc-plugin-markdown":"^1.1.13","rollup-plugin-visualizer":"^0.9.2","rollup-plugin-node-resolve":"^3.3.0"},"_npmOperationalInternal":{"tmp":"tmp/pdf-lib_0.6.2-rc4_1557014468531_0.2943306377675057","host":"s3://npm-registry-packages"},"_id":"pdf-lib@0.6.2-rc4","version":"0.6.2-rc4"}