{"id":14971228,"url":"https://github.com/coderdotjs/html-to-pdf-node","last_synced_at":"2026-02-16T11:33:05.287Z","repository":{"id":152006764,"uuid":"625148955","full_name":"CoderDotJs/html-to-pdf-node","owner":"CoderDotJs","description":"This plugin will convert html page or public URL into PDF. This will work with Node.js","archived":false,"fork":false,"pushed_at":"2023-05-03T08:04:56.000Z","size":41,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-28T02:31:16.795Z","etag":null,"topics":["converter","html-pdf","nodejs","npm","npm-package","pdf","puppeteer","serverside"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@akash3080/html-to-pdf-node","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CoderDotJs.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-08T08:02:08.000Z","updated_at":"2023-05-19T13:01:39.000Z","dependencies_parsed_at":"2023-07-06T14:16:31.188Z","dependency_job_id":null,"html_url":"https://github.com/CoderDotJs/html-to-pdf-node","commit_stats":{"total_commits":6,"total_committers":1,"mean_commits":6.0,"dds":0.0,"last_synced_commit":"96acfa3e157923ee4a076417736ad7323eab1a4a"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/CoderDotJs/html-to-pdf-node","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CoderDotJs%2Fhtml-to-pdf-node","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CoderDotJs%2Fhtml-to-pdf-node/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CoderDotJs%2Fhtml-to-pdf-node/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CoderDotJs%2Fhtml-to-pdf-node/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CoderDotJs","download_url":"https://codeload.github.com/CoderDotJs/html-to-pdf-node/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CoderDotJs%2Fhtml-to-pdf-node/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278503205,"owners_count":25997718,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-05T02:00:06.059Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["converter","html-pdf","nodejs","npm","npm-package","pdf","puppeteer","serverside"],"created_at":"2024-09-24T13:44:53.542Z","updated_at":"2025-10-05T18:58:37.952Z","avatar_url":"https://github.com/CoderDotJs.png","language":"JavaScript","readme":"# html-to-pdf-node\n\n\u003e Pagination plugin for converts html or url to pdf\n\n# **Note:** This plugin will convert html page or public URL into PDF. This will work with Node.js\n\n## Installation\n\n```sh\nnpm install @akash3080/html-to-pdf-node\n```\n\n## Usage\n\nTo convert `HTML` page to `PDF` using `generatePdf` method:\n\n```js\nvar html_to_pdf = require(\"@akash3080/html-to-pdf-node\");\n\nlet options = { format: \"A4\" };\n// Example of options with args //\n// let options = { format: 'A4', args: ['--no-sandbox', '--disable-setuid-sandbox'] };\n\nlet file = { content: \"\u003ch1\u003eWelcome to html-to-pdf-node\u003c/h1\u003e\" };\n// or //\nlet file = { url: \"https://example.com\" };\nhtml_to_pdf.generatePdf(file, options).then((pdfBuffer) =\u003e {\n  console.log(\"PDF Buffer:-\", pdfBuffer);\n});\n```\n\n### html_to_pdf.generatePdf ( [file], [options], [callback] )\n\n**Parameters**\n\n`file` \u003c[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object \"Object\")\u003e File object should have one of the following properties:\n\n- `url` \u003c[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type \"String\")\u003e Any public url of the PDF.\n- `content`\u003c[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type \"String\")\u003e HTML file content of the PDF.\n\n`options` \u003c[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object \"Object\")\u003e Options object should have the following properties:\n\n- `args` \u003c[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array \"Array\")\u003c[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type \"String\")\u003e\u003e Additional arguments to pass to the browser instance. The list of Chromium flags can be found [here](http://peter.sh/experiments/chromium-command-line-switches/). This options will overwrite the default arguments. The default arguments are `['--no-sandbox', '--disable-setuid-sandbox']`.\n- `path` \u003c[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type \"String\")\u003e The file path to save the PDF to. If `path` is a relative path, then it is resolved to [current working directory](https://nodejs.org/api/process.html#process_process_cwd). If no path is provided, the PDF won't be saved anywhere.\n- `scale` \u003c[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type \"Number\")\u003e Scale of the webpage rendering. Defaults to `1`. Scale amount must be between 0.1 and 2.\n- `displayHeaderFooter` \u003c[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type \"Boolean\")\u003e Display header and footer. Defaults to `false`.\n- `headerTemplate` \u003c[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type \"String\")\u003e HTML template to print the header. Should be valid HTML markup with following classes used to inject printing values into them:\n  - `date` formatted date\n  - `title` document title\n  - `url` document location\n  - `pageNumber` current page number\n  - `totalPages` total pages in the document\n- `footerTemplate` \u003c[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type \"String\")\u003e HTML template to print the footer. Should use the same format as the `headerTemplate`.\n- `printBackground` \u003c[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type \"Boolean\")\u003e Print background graphics. Defaults to `false`.\n- `landscape` \u003c[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type \"Boolean\")\u003e Paper orientation. Defaults to `false`.\n- `pageRanges` \u003c[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type \"String\")\u003e Paper ranges to print, e.g., '1-5, 8, 11-13'. Defaults to the empty string, which means print all pages.\n- `format` \u003c[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type \"String\")\u003e Paper format. If set, takes priority over `width` or `height` options. Defaults to 'Letter'.\n- `width` \u003c[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type \"String\")|[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type \"Number\")\u003e Paper width, accepts values labeled with units.\n- `height` \u003c[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type \"String\")|[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type \"Number\")\u003e Paper height, accepts values labeled with units.\n- `margin` \u003c[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object \"Object\")\u003e Paper margins, defaults to none.\n  - `top` \u003c[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type \"String\")|[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type \"Number\")\u003e Top margin, accepts values labeled with units.\n  - `right` \u003c[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type \"String\")|[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type \"Number\")\u003e Right margin, accepts values labeled with units.\n  - `bottom` \u003c[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type \"String\")|[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type \"Number\")\u003e Bottom margin, accepts values labeled with units.\n  - `left` \u003c[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type \"String\")|[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type \"Number\")\u003e Left margin, accepts values labeled with units.\n- `preferCSSPageSize` \u003c[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type \"Boolean\")\u003e Give any CSS `@page` size declared in the page priority over what is declared in `width` and `height` or `format` options. Defaults to `false`, which will scale the content to fit the paper size.\n\n**Return value**\n\nPromise which resolves with PDF buffer.\n\n### html_to_pdf.generatePdfs ( [files], [options], [callback] )\n\n**Parameters**\n\n`files` \u003c[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array \"Array\")\u003c[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object \"Object\")\u003e\u003e File object should have one of the follwing properties:\n\n- `url` \u003c[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type \"String\")\u003e Any public url of the PDF.\n- `content`\u003c[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type \"String\")\u003e HTML file content of the PDF.\n\n`options` \u003c[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object \"Object\")\u003e Options object should have the following properties:\n\n- `args` \u003c[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array \"Array\")\u003c[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type \"String\")\u003e\u003e Additional arguments to pass to the browser instance. The list of Chromium flags can be found [here](http://peter.sh/experiments/chromium-command-line-switches/). This options will overwrite the default arguments. The default arguments are `['--no-sandbox', '--disable-setuid-sandbox']`.\n- `path` \u003c[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type \"String\")\u003e The file path to save the PDF to. If `path` is a relative path, then it is resolved to [current working directory](https://nodejs.org/api/process.html#process_process_cwd). If no path is provided, the PDF won't be saved anywhere.\n- `scale` \u003c[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type \"Number\")\u003e Scale of the webpage rendering. Defaults to `1`. Scale amount must be between 0.1 and 2.\n- `displayHeaderFooter` \u003c[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type \"Boolean\")\u003e Display header and footer. Defaults to `false`.\n- `headerTemplate` \u003c[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type \"String\")\u003e HTML template to print the header. Should be valid HTML markup with following classes used to inject printing values into them:\n  - `date` formatted date\n  - `title` document title\n  - `url` document location\n  - `pageNumber` current page number\n  - `totalPages` total pages in the document\n- `footerTemplate` \u003c[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type \"String\")\u003e HTML template to print the footer. Should use the same format as the `headerTemplate`.\n- `printBackground` \u003c[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type \"Boolean\")\u003e Print background graphics. Defaults to `false`.\n- `landscape` \u003c[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type \"Boolean\")\u003e Paper orientation. Defaults to `false`.\n- `pageRanges` \u003c[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type \"String\")\u003e Paper ranges to print, e.g., '1-5, 8, 11-13'. Defaults to the empty string, which means print all pages.\n- `format` \u003c[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type \"String\")\u003e Paper format. If set, takes priority over `width` or `height` options. Defaults to 'Letter'.\n- `width` \u003c[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type \"String\")|[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type \"Number\")\u003e Paper width, accepts values labeled with units.\n- `height` \u003c[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type \"String\")|[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type \"Number\")\u003e Paper height, accepts values labeled with units.\n- `margin` \u003c[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object \"Object\")\u003e Paper margins, defaults to none.\n  - `top` \u003c[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type \"String\")|[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type \"Number\")\u003e Top margin, accepts values labeled with units.\n  - `right` \u003c[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type \"String\")|[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type \"Number\")\u003e Right margin, accepts values labeled with units.\n  - `bottom` \u003c[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type \"String\")|[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type \"Number\")\u003e Bottom margin, accepts values labeled with units.\n  - `left` \u003c[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type \"String\")|[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type \"Number\")\u003e Left margin, accepts values labeled with units.\n- `preferCSSPageSize` \u003c[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type \"Boolean\")\u003e Give any CSS `@page` size declared in the page priority over what is declared in `width` and `height` or `format` options. Defaults to `false`, which will scale the content to fit the paper size.\n\n**Return value**\n\nPromise which resolves with array of object which contains file objects with PDF buffers.\n\n**_Example:_**\n\n```js\nlet options = { format: \"A4\" };\nlet file = [{ url: \"https://example.com\", name: \"example.pdf\" }];\n\nhtml_to_pdf.generatePdfs(file, options).then((output) =\u003e {\n  console.log(\"PDF Buffer:-\", output); // PDF Buffer:- [{url: \"https://example.com\", name: \"example.pdf\", buffer: \u003cPDF buffer\u003e}]\n});\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoderdotjs%2Fhtml-to-pdf-node","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoderdotjs%2Fhtml-to-pdf-node","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoderdotjs%2Fhtml-to-pdf-node/lists"}