{"_id":"@autotelic/fastify-pdf-export","name":"@autotelic/fastify-pdf-export","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"@autotelic/fastify-pdf-export","version":"0.1.0","description":"Plugin for Fastify","main":"index.js","types":"types/index.d.ts","type":"module","engines":{"node":">=20"},"scripts":{"build":"npx tailwindcss -i ./example/input.css -o ./public/output.css && cp example/index.html public/index.html","dev":"npm run build && concurrently \"npx http-server\" \"fastify start -l debug -P example/index.js\"","test":"npm run build && tap","lint":"eslint .","test:types":"tsd","validate":"npm run lint && npm test && npm run test:types"},"repository":{"type":"git","url":"git+https://github.com/autotelic/fastify-pdf-export.git"},"keywords":[],"author":{"name":"Autotelic Development Ltd","email":"info@autotelic.com"},"license":"MIT","bugs":{"url":"https://github.com/autotelic/fastify-pdf-export/issues"},"homepage":"https://github.com/autotelic/fastify-pdf-export#readme","dependencies":{"fastify-plugin":"^4.5.1","puppeteer":"^21.9.0"},"devDependencies":{"@autotelic/eslint-config-js":"^0.3.0","@autotelic/fastify-injector":"^0.3.0","@typescript-eslint/eslint-plugin":"^6.19.1","@typescript-eslint/parser":"^6.19.1","concurrently":"^8.2.2","eslint":"^8.56.0","eslint-import-resolver-typescript":"^3.6.1","fastify":"^4.25.2","fastify-cli":"^6.0.1","nock":"^13.5.0","pdf-lib":"^1.17.1","tailwindcss":"^3.4.1","tap":"^18.6.1","tsd":"^0.30.4","typescript":"^5.3.3"},"tsd":{"directory":"types"},"_id":"@autotelic/fastify-pdf-export@0.1.0","gitHead":"ea825664ab16d210fe0659f53773de8462b56c1b","_nodeVersion":"20.10.0","_npmVersion":"10.2.3","dist":{"integrity":"sha512-dCEzFgH4ECWOgRBX84pVM9MrY9q+GxxOFCQS5yB9pqUffTvQLXR0HRCm/B2kwqxVSvJGJ89+VdD8kry2/Vpnqw==","shasum":"d39e4642f0aba5224fd54b7c241cd005f0430f93","tarball":"https://registry.npmjs.org/@autotelic/fastify-pdf-export/-/fastify-pdf-export-0.1.0.tgz","fileCount":5,"unpackedSize":6174,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCHJpfNuH7+ROFe28LmoS3JlGMt41fYAelno/18fTf5RwIhAJ03zbF9CmtBg4LVxD4RtZ3L+2aTjLY4QVtpaahmLyfm"}]},"_npmUser":{"name":"autotelic","email":"info+npm@autotelic.com"},"directories":{},"maintainers":[{"name":"autotelic","email":"info+npm@autotelic.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/fastify-pdf-export_0.1.0_1707509185807_0.9227578503123717"},"_hasShrinkwrap":false}},"time":{"created":"2024-02-09T20:06:25.706Z","0.1.0":"2024-02-09T20:06:26.055Z","modified":"2024-02-09T20:06:26.258Z"},"maintainers":[{"name":"autotelic","email":"info+npm@autotelic.com"}],"description":"Plugin for Fastify","homepage":"https://github.com/autotelic/fastify-pdf-export#readme","keywords":[],"repository":{"type":"git","url":"git+https://github.com/autotelic/fastify-pdf-export.git"},"author":{"name":"Autotelic Development Ltd","email":"info@autotelic.com"},"bugs":{"url":"https://github.com/autotelic/fastify-pdf-export/issues"},"license":"MIT","readme":"# fastify-pdf-export\n\nThe `fastify-pdf-export` plugin for Fastify enables the generation and export of PDF files from URLs using Puppeteer.\n\n## Installation\n\n```sh\nnpm install @autotelic/fastify-pdf-export\n```\n\n## Usage\n\n```js\nimport Fastify from 'fastify'\nimport fastifyPdfExport from 'fastify-pdf-export'\n\nconst fastify = Fastify()\n\nfastify.register(fastifyPdfExport)\n\nfastify.get('/', async (request, reply) => {\n    const { pdfExport } = fastify\n    const { pdf } = await pdfExport({\n      pdfUrl: 'http://example.com'\n    })\n    reply.type('application/pdf').send(pdf)\n  })\n\nfastify.listen({ port: 3000 }, err => {\n  if (err) throw err\n  console.log(`Server listening on ${fastify.server.address().port}`)\n})\n```\n\n## API\n\nThe `fastify-pdf-export` plugin extends your Fastify instance with a new method: `pdfExport`. This method is used to generate PDFs from provided URLs using Puppeteer.\n\n### Methods\n\n#### `pdfExport(options)`\n\nGenerates a PDF from the specified URL.\n\n##### Options\n\n- `pdfUrl` (string): **Required**.The URL of the webpage to be converted into a PDF.\n- `pdfOptions` (`PDFOptions`): **Optional**. Configuration options for the PDF generation, as defined by Puppeteer's [`PDFOptions`](https://pptr.dev/api/puppeteer.pdfoptions). This includes settings such as `format`, `margin`, `printBackground`, etc.\n- `launchOptions` (`BrowserLaunchArgumentOptions`): **Optional**. Configuration options for launching the Puppeteer browser instance, as defined by Puppeteer's [`BrowserLaunchArgumentOptions`](https://pptr.dev/api/puppeteer.browserlaunchargumentoptions). This includes settings such as `headless`, `args`, `ignoreHTTPSErrors`, etc. By default, `headless` is set to `new`.\n\n##### Returns\n\nA promise that resolves to an object containing:\n\n- `pdf`: A `Buffer` containing the generated PDF data.\n- `error`: An error object, if any error occurred during the PDF generation process.\n\n##### Example\n\n```js\nconst { pdf, error } = await fastify.pdfExport({\n  pdfUrl: 'http://example.com',\n  pdfOptions: { format: 'A4' },\n  launchOptions: { headless: 'new' }\n});\n```\n","readmeFilename":"README.md"}