{"id":13576176,"url":"https://github.com/marcbachmann/node-html-pdf","last_synced_at":"2025-05-13T19:16:49.333Z","repository":{"id":16171297,"uuid":"18917566","full_name":"marcbachmann/node-html-pdf","owner":"marcbachmann","description":"This repo isn't maintained anymore as phantomjs got dreprecated a long time ago. Please migrate to headless chrome/puppeteer.","archived":false,"fork":false,"pushed_at":"2024-05-15T14:58:10.000Z","size":415,"stargazers_count":3565,"open_issues_count":470,"forks_count":537,"subscribers_count":39,"default_branch":"master","last_synced_at":"2025-05-11T08:16:09.356Z","etag":null,"topics":["html","pdf","pdf-converter","phantomjs"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/marcbachmann.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2014-04-18T15:51:48.000Z","updated_at":"2025-05-08T07:57:36.000Z","dependencies_parsed_at":"2024-10-19T04:21:36.235Z","dependency_job_id":null,"html_url":"https://github.com/marcbachmann/node-html-pdf","commit_stats":{"total_commits":131,"total_committers":23,"mean_commits":5.695652173913044,"dds":0.2137404580152672,"last_synced_commit":"7e8c02af936341c1ba23a6a1c422649363e7a7aa"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcbachmann%2Fnode-html-pdf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcbachmann%2Fnode-html-pdf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcbachmann%2Fnode-html-pdf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcbachmann%2Fnode-html-pdf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marcbachmann","download_url":"https://codeload.github.com/marcbachmann/node-html-pdf/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254010822,"owners_count":21999003,"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","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":["html","pdf","pdf-converter","phantomjs"],"created_at":"2024-08-01T15:01:07.660Z","updated_at":"2025-05-13T19:16:49.272Z","avatar_url":"https://github.com/marcbachmann.png","language":"JavaScript","readme":"# node-html-pdf\n## HTML to PDF converter that uses phantomjs\n![image](examples/businesscard/businesscard.png)  \n[Example Business Card](examples/businesscard/businesscard.pdf)  \n -\u003e [and its Source file](examples/businesscard/businesscard.html)  \n\n[Example Receipt](http://imgr-static.s3-eu-west-1.amazonaws.com/order.pdf)\n\n## Changelog\n\nHave a look at the releases page: https://github.com/marcbachmann/node-html-pdf/releases\n\n## Installation\n\nInstall the html-pdf utility via [npm](http://npmjs.org/):\n\n```\n$ npm install -g html-pdf\n```\n\n## Command-line example\n\n```\n$ html-pdf test/businesscard.html businesscard.pdf\n```\n\n## Code example\n```javascript\nvar fs = require('fs');\nvar pdf = require('html-pdf');\nvar html = fs.readFileSync('./test/businesscard.html', 'utf8');\nvar options = { format: 'Letter' };\n\npdf.create(html, options).toFile('./businesscard.pdf', function(err, res) {\n  if (err) return console.log(err);\n  console.log(res); // { filename: '/app/businesscard.pdf' }\n});\n```\n\n## API\n\n```js\nvar pdf = require('html-pdf');\npdf.create(html).toFile([filepath, ]function(err, res){\n  console.log(res.filename);\n});\n\npdf.create(html).toStream(function(err, stream){\n  stream.pipe(fs.createWriteStream('./foo.pdf'));\n});\n\npdf.create(html).toBuffer(function(err, buffer){\n  console.log('This is a buffer:', Buffer.isBuffer(buffer));\n});\n\n\n// for backwards compatibility\n// alias to pdf.create(html[, options]).toBuffer(callback)\npdf.create(html [, options], function(err, buffer){});\n```\n\n### Footers and Headers\n\n`html-pdf` can read the header or footer either out of the `footer` and `header` config object or out of the html source. You can either set a default header \u0026 footer or overwrite that by appending a page number (1 based index) to the `id=\"pageHeader\"` attribute of a html tag.\n\nYou can use any combination of those tags. The library tries to find any element, that contains the `pageHeader` or `pageFooter` id prefix.\n```html\n\u003cdiv id=\"pageHeader\"\u003eDefault header\u003c/div\u003e\n\u003cdiv id=\"pageHeader-first\"\u003eHeader on first page\u003c/div\u003e\n\u003cdiv id=\"pageHeader-2\"\u003eHeader on second page\u003c/div\u003e\n\u003cdiv id=\"pageHeader-3\"\u003eHeader on third page\u003c/div\u003e\n\u003cdiv id=\"pageHeader-last\"\u003eHeader on last page\u003c/div\u003e\n...\n\u003cdiv id=\"pageFooter\"\u003eDefault footer\u003c/div\u003e\n\u003cdiv id=\"pageFooter-first\"\u003eFooter on first page\u003c/div\u003e\n\u003cdiv id=\"pageFooter-2\"\u003eFooter on second page\u003c/div\u003e\n\u003cdiv id=\"pageFooter-last\"\u003eFooter on last page\u003c/div\u003e\n```\n\n\n## Options\n```javascript\nconfig = {\n\n  // Export options\n  \"directory\": \"/tmp\",       // The directory the file gets written into if not using .toFile(filename, callback). default: '/tmp'\n\n  // Papersize Options: http://phantomjs.org/api/webpage/property/paper-size.html\n  \"height\": \"10.5in\",        // allowed units: mm, cm, in, px\n  \"width\": \"8in\",            // allowed units: mm, cm, in, px\n  - or -\n  \"format\": \"Letter\",        // allowed units: A3, A4, A5, Legal, Letter, Tabloid\n  \"orientation\": \"portrait\", // portrait or landscape\n\n  // Page options\n  \"border\": \"0\",             // default is 0, units: mm, cm, in, px\n  - or -\n  \"border\": {\n    \"top\": \"2in\",            // default is 0, units: mm, cm, in, px\n    \"right\": \"1in\",\n    \"bottom\": \"2in\",\n    \"left\": \"1.5in\"\n  },\n\n  paginationOffset: 1,       // Override the initial pagination number\n  \"header\": {\n    \"height\": \"45mm\",\n    \"contents\": '\u003cdiv style=\"text-align: center;\"\u003eAuthor: Marc Bachmann\u003c/div\u003e'\n  },\n  \"footer\": {\n    \"height\": \"28mm\",\n    \"contents\": {\n      first: 'Cover page',\n      2: 'Second page', // Any page number is working. 1-based index\n      default: '\u003cspan style=\"color: #444;\"\u003e{{page}}\u003c/span\u003e/\u003cspan\u003e{{pages}}\u003c/span\u003e', // fallback value\n      last: 'Last Page'\n    }\n  },\n\n\n  // Rendering options\n  \"base\": \"file:///home/www/your-asset-path/\", // Base path that's used to load files (images, css, js) when they aren't referenced using a host\n\n  // Zooming option, can be used to scale images if `options.type` is not pdf\n  \"zoomFactor\": \"1\", // default is 1\n\n  // File options\n  \"type\": \"pdf\",           // allowed file types: png, jpeg, pdf\n  \"quality\": \"75\",         // only used for types png \u0026 jpeg\n\n  // Script options\n  \"phantomPath\": \"./node_modules/phantomjs/bin/phantomjs\", // PhantomJS binary which should get downloaded automatically\n  \"phantomArgs\": [], // array of strings used as phantomjs args e.g. [\"--ignore-ssl-errors=yes\"]\n  \"localUrlAccess\": false, // Prevent local file:// access by passing '--local-url-access=false' to phantomjs\n                           // For security reasons you should keep the default value if you render arbritary html/js.\n  \"script\": '/url',        // Absolute path to a custom phantomjs script, use the file in lib/scripts as example\n  \"timeout\": 30000,        // Timeout that will cancel phantomjs, in milliseconds\n\n  // Time we should wait after window load\n  // accepted values are 'manual', some delay in milliseconds or undefined to wait for a render event\n  \"renderDelay\": 1000,\n\n  // HTTP Headers that are used for requests\n  \"httpHeaders\": {\n    // e.g.\n    \"Authorization\": \"Bearer ACEFAD8C-4B4D-4042-AB30-6C735F5BAC8B\"\n  },\n\n  // To run Node application as Windows service\n  \"childProcessOptions\": {\n    \"detached\": true\n  }\n\n  // HTTP Cookies that are used for requests\n  \"httpCookies\": [\n    // e.g.\n    {\n      \"name\": \"Valid-Cookie-Name\", // required\n      \"value\": \"Valid-Cookie-Value\", // required\n      \"domain\": \"localhost\",\n      \"path\": \"/foo\", // required\n      \"httponly\": true,\n      \"secure\": false,\n      \"expires\": (new Date()).getTime() + (1000 * 60 * 60) // e.g. expires in 1 hour\n    }\n  ]\n\n}\n```\n\nThe full options object gets converted to JSON and will get passed to the phantomjs script as third argument.  \nThere are more options concerning the paperSize, header \u0026 footer options inside the phantomjs script.\n","funding_links":[],"categories":["JavaScript","JAVASCRIPT"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcbachmann%2Fnode-html-pdf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarcbachmann%2Fnode-html-pdf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcbachmann%2Fnode-html-pdf/lists"}