{"id":18487251,"url":"https://github.com/hajareshyam/pdf-creator-node","last_synced_at":"2025-04-08T20:30:54.014Z","repository":{"id":33272729,"uuid":"157030347","full_name":"hajareshyam/pdf-creator-node","owner":"hajareshyam","description":"This package is used to generate HTML to PDF in Nodejs","archived":false,"fork":false,"pushed_at":"2024-03-03T17:56:03.000Z","size":369,"stargazers_count":238,"open_issues_count":75,"forks_count":80,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-06T12:59:24.778Z","etag":null,"topics":["html-pdf","html-template","node","pdf","pdf-converter","pdf-creator","pdf-generation"],"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/hajareshyam.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":"2018-11-10T23:20:11.000Z","updated_at":"2024-10-25T10:49:52.000Z","dependencies_parsed_at":"2024-11-06T12:54:48.209Z","dependency_job_id":"7bfd8773-dcb0-48cb-a7fa-bc43347dbea6","html_url":"https://github.com/hajareshyam/pdf-creator-node","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hajareshyam%2Fpdf-creator-node","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hajareshyam%2Fpdf-creator-node/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hajareshyam%2Fpdf-creator-node/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hajareshyam%2Fpdf-creator-node/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hajareshyam","download_url":"https://codeload.github.com/hajareshyam/pdf-creator-node/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247922716,"owners_count":21018849,"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","html-template","node","pdf","pdf-converter","pdf-creator","pdf-generation"],"created_at":"2024-11-06T12:50:21.079Z","updated_at":"2025-04-08T20:30:53.735Z","avatar_url":"https://github.com/hajareshyam.png","language":"JavaScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# Follow these steps to convert HTML to PDF\n\n- Step 1 - install the pdf creator package using the following command\n\n  `$ npm i pdf-creator-node --save`\n\n  \u003e --save flag adds package name to package.json file.\n\n- Step 2 - Add required packages and read HTML template\n\n  ```javascript\n  //Required package\n  var pdf = require(\"pdf-creator-node\");\n  var fs = require(\"fs\");\n\n  // Read HTML Template\n  var html = fs.readFileSync(\"template.html\", \"utf8\");\n  ```\n\n- Step 3 - Create your HTML Template\n\n  ```html\n  \u003c!DOCTYPE html\u003e\n  \u003chtml\u003e\n    \u003chead\u003e\n      \u003cmeta charset=\"utf-8\" /\u003e\n      \u003ctitle\u003eHello world!\u003c/title\u003e\n    \u003c/head\u003e\n    \u003cbody\u003e\n      \u003ch1\u003eUser List\u003c/h1\u003e\n      \u003cul\u003e\n        {{#each users}}\n        \u003cli\u003eName: {{this.name}}\u003c/li\u003e\n        \u003cli\u003eAge: {{this.age}}\u003c/li\u003e\n        \u003cbr /\u003e\n        {{/each}}\n      \u003c/ul\u003e\n    \u003c/body\u003e\n  \u003c/html\u003e\n  ```\n\n- Step 4 - Provide format and orientation as per your need\n\n  \u003e \"height\": \"10.5in\", // allowed units: mm, cm, in, px\n\n  \u003e \"width\": \"8in\", // allowed units: mm, cm, in, px\n\n  - or -\n\n  \u003e \"format\": \"Letter\", // allowed units: A3, A4, A5, Legal, Letter, Tabloid\n\n  \u003e \"orientation\": \"portrait\", // portrait or landscape\n\n    ```javascript\n        var options = {\n            format: \"A3\",\n            orientation: \"portrait\",\n            border: \"10mm\",\n            header: {\n                height: \"45mm\",\n                contents: '\u003cdiv style=\"text-align: center;\"\u003eAuthor: Shyam Hajare\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    \n- Step 5 - Provide HTML, user data and PDF path for output\n\n  ```javascript\n  var users = [\n    {\n      name: \"Shyam\",\n      age: \"26\",\n    },\n    {\n      name: \"Navjot\",\n      age: \"26\",\n    },\n    {\n      name: \"Vitthal\",\n      age: \"26\",\n    },\n  ];\n  var document = {\n    html: html,\n    data: {\n      users: users,\n    },\n    path: \"./output.pdf\",\n    type: \"\",\n  };\n  // By default a file is created but you could switch between Buffer and Streams by using \"buffer\" or \"stream\" respectively.\n  ```\n\n- Step 6 - After setting all parameters, just pass document and options to `pdf.create` method.\n\n  ```javascript\n  pdf\n    .create(document, options)\n    .then((res) =\u003e {\n      console.log(res);\n    })\n    .catch((error) =\u003e {\n      console.error(error);\n    });\n  ```\n\n### If Conditional Checks\nYou can do conditional checks by calling helper block _ifCond_ example\n\n```js\n{{#ifCond inputData \"===\" toCheckValue}}\n```\n\n  ```html\n  \u003c!DOCTYPE html\u003e\n  \u003chtml\u003e\n    \u003chead\u003e\n      \u003cmeta charset=\"utf-8\" /\u003e\n      \u003ctitle\u003eHello world!\u003c/title\u003e\n    \u003c/head\u003e\n    \u003cbody\u003e\n      \u003ch1\u003eUser List\u003c/h1\u003e\n      \u003cul\u003e\n        {{#each users}}\n        \u003cli\u003eName: {{this.name}}\u003c/li\u003e\n        \u003cli\u003eAge: {{#ifCond this.age '===' '26'}}\u003c/li\u003e\n        \u003cbr /\u003e\n        {{/ifCond}}\n        {{/each}}\n      \u003c/ul\u003e\n    \u003c/body\u003e\n  \u003c/html\u003e\n  ```\n\nCan check variables with different type ie _string_, _integer_, _boolean_, _double_\n\nOther logical operators are-:\n\n- ==\n   ```js\n    {{#ifCond inputData \"==\" toCheckValue}}\n   ```\n- ===\n   ```js\n    {{#ifCond inputData \"===\" toCheckValue}}\n   ```\n- != \n   ```js\n    {{#ifCond inputData \"!=\" toCheckValue}}\n   ```\n- !==\n   ```js\n    {{#ifCond inputData \"!==\" toCheckValue}}\n   ```\n- \u003c\n   ```js\n    {{#ifCond inputData \"\u003c\" toCheckValue}}\n   ```\n- \u003c=\n   ```js\n    {{#ifCond inputData \"\u003c=\" toCheckValue}}\n   ```\n- '\u003e\n   ```js\n    {{#ifCond inputData \"\u003e\" toCheckValue}}\n   ```\n- '\u003e=\n   ```js\n    {{#ifCond inputData \"\u003e=\" toCheckValue}}\n   ```\n- \u0026\u0026\n   ```js\n    {{#ifCond inputData \"\u0026\u0026\" toCheckValue}}\n   ```\n- ||\n   ```js\n    {{#ifCond inputData \"||\" toCheckValue}}\n   ```\n\n##NOTE!!\nYou can only match 2 variables\n\n### End\n\n### License\n\npdf-creator-node is [MIT licensed](./LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhajareshyam%2Fpdf-creator-node","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhajareshyam%2Fpdf-creator-node","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhajareshyam%2Fpdf-creator-node/lists"}