{"_id":"@bigtechbro/nestjs-html-pdf","_rev":"1-4e9762058087de672d1c09d2207fc58a","name":"@bigtechbro/nestjs-html-pdf","dist-tags":{"latest":"0.1.1"},"versions":{"0.1.0":{"version":"0.1.0","license":"MIT","main":"dist/index.js","typings":"dist/index.d.ts","engines":{"node":">=20"},"scripts":{"start":"tsdx watch","build":"tsdx build","test":"tsdx test","lint":"tsdx lint","prepare":"tsdx build","size":"size-limit","analyze":"size-limit --why"},"husky":{"hooks":{"pre-commit":"tsdx lint"}},"prettier":{"printWidth":80,"semi":true,"singleQuote":true,"trailingComma":"es5"},"name":"@bigtechbro/nestjs-html-pdf","module":"dist/nestjs-html-pdf.esm.js","description":"A NestJS module to generate PDF files from HTML","author":{"name":"Ifeanyi Amadi","email":"helloamadiify@gmail.com","url":"https://github.com/line33"},"repository":{"type":"git","url":"git+https://github.com/line33/nestjs-html-pdf.git"},"bugs":{"url":"https://github.com/line33/nestjs-html-pdf/issues"},"homepage":"https://github.com/line33/nestjs-html-pdf#readme","size-limit":[{"path":"dist/nestjs-html-pdf.cjs.production.min.js","limit":"10 KB"},{"path":"dist/nestjs-html-pdf.esm.js","limit":"10 KB"}],"devDependencies":{"@size-limit/preset-small-lib":"^11.1.2","husky":"^9.0.11","size-limit":"^11.1.2","tsdx":"^0.14.1","tslib":"^2.6.2","typescript":"^5.4.5"},"dependencies":{"fs-extra":"^11.2.0","handlebars":"^4.7.8","puppeteer":"^22.8.0"},"_id":"@bigtechbro/nestjs-html-pdf@0.1.0","gitHead":"ed06607fff337b1a261dc990286c15f8b6b593f9","_nodeVersion":"20.12.2","_npmVersion":"10.5.0","dist":{"integrity":"sha512-IFZwx0cbASiZv28nL9BmNqao6CR4R1jjVPjpBtnB/kVfNsiYETmZkctNGxwavA0PUxecogj4eQEI1ezwKdANgA==","shasum":"3ca098e15642198ab122ef5d28888f424aef91e3","tarball":"https://registry.npmjs.org/@bigtechbro/nestjs-html-pdf/-/nestjs-html-pdf-0.1.0.tgz","fileCount":12,"unpackedSize":78597,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD7f/a1N5e90cIczqckOvSHO6LL8puuoVEbyAV3/3wrEgIgIUkmpCrGG5pc3Mth3Kunk5cv+HnkwX/2jH9pf4JpFZU="}]},"_npmUser":{"name":"bigtechbro","email":"helloamadiify@gmail.com"},"directories":{},"maintainers":[{"name":"bigtechbro","email":"helloamadiify@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/nestjs-html-pdf_0.1.0_1715273713030_0.6506135865948306"},"_hasShrinkwrap":false},"0.1.1":{"version":"0.1.1","license":"MIT","main":"dist/index.js","typings":"dist/index.d.ts","engines":{"node":">=18"},"scripts":{"start":"tsdx watch","build":"tsdx build","test":"tsdx test","lint":"tsdx lint","prepare":"tsdx build","size":"size-limit","analyze":"size-limit --why"},"husky":{"hooks":{"pre-commit":"tsdx lint"}},"prettier":{"printWidth":80,"semi":true,"singleQuote":true,"trailingComma":"es5"},"name":"@bigtechbro/nestjs-html-pdf","module":"dist/nestjs-html-pdf.esm.js","description":"A NestJS module to generate PDF files from HTML","author":{"name":"Ifeanyi Amadi","email":"helloamadiify@gmail.com","url":"https://github.com/line33"},"repository":{"type":"git","url":"git+https://github.com/line33/nestjs-html-pdf.git"},"bugs":{"url":"https://github.com/line33/nestjs-html-pdf/issues"},"homepage":"https://github.com/line33/nestjs-html-pdf#readme","size-limit":[{"path":"dist/nestjs-html-pdf.cjs.production.min.js","limit":"10 KB"},{"path":"dist/nestjs-html-pdf.esm.js","limit":"10 KB"}],"devDependencies":{"@size-limit/preset-small-lib":"^11.1.2","husky":"^9.0.11","size-limit":"^11.1.2","tsdx":"^0.14.1","tslib":"^2.6.2","typescript":"^5.4.5"},"dependencies":{"fs-extra":"^11.2.0","handlebars":"^4.7.8","puppeteer":"^22.8.0"},"_id":"@bigtechbro/nestjs-html-pdf@0.1.1","gitHead":"89a6a62933a6344060fa5a5a5ddebe5919942691","_nodeVersion":"20.12.2","_npmVersion":"10.5.0","dist":{"integrity":"sha512-rzG3tTsHLe3qpqi+8icSNpwm42G74HOWXBv61FOWl6mormyV2RdQSLICoevyumV0JK0nygK4ffRVlAeu0cXEZg==","shasum":"4717890321d680ecdfc4eb21d4205c400372356b","tarball":"https://registry.npmjs.org/@bigtechbro/nestjs-html-pdf/-/nestjs-html-pdf-0.1.1.tgz","fileCount":12,"unpackedSize":78597,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGN+QD6A9ksMRN+o/jOvx+hs1HtekkHzCoLAA7YWcDegAiEAunG5arBVDkn0VRejXb+QJlHLrilCZFEXhwY+DXb1Zp0="}]},"_npmUser":{"name":"bigtechbro","email":"helloamadiify@gmail.com"},"directories":{},"maintainers":[{"name":"bigtechbro","email":"helloamadiify@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/nestjs-html-pdf_0.1.1_1715274219272_0.2240676241026156"},"_hasShrinkwrap":false}},"time":{"created":"2024-05-09T16:55:12.876Z","0.1.0":"2024-05-09T16:55:13.163Z","modified":"2024-05-09T17:03:39.863Z","0.1.1":"2024-05-09T17:03:39.680Z"},"maintainers":[{"name":"bigtechbro","email":"helloamadiify@gmail.com"}],"description":"A NestJS module to generate PDF files from HTML","homepage":"https://github.com/line33/nestjs-html-pdf#readme","repository":{"type":"git","url":"git+https://github.com/line33/nestjs-html-pdf.git"},"author":{"name":"Ifeanyi Amadi","email":"helloamadiify@gmail.com","url":"https://github.com/line33"},"bugs":{"url":"https://github.com/line33/nestjs-html-pdf/issues"},"license":"MIT","readme":"# NEST HTML PDF\n\nA package to generate PDF files from HTML for NestJs\n\n## Installation\n\n`npm i @bigtechbro/nestjs-html-pdf`\n\n## Usage\n\n### Initialization\n\nservice file\n\n```\nimport { Injectable } from '@nestjs/common';\nimport { createPdf } from '@bigtechbro/nestjs-html-pdf';\nimport * as path from 'path';\n```\n\ncall the function create createPdf([filePath], [options], [data])\n\n- `filePath` <[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type 'String')> It's required. HTML file path.\n- `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object 'Object')> It's optional.\n  Default value:\n\n```\n{\n    format: 'a4',\n    printBackground: true,\n    margin: {\n        left: '10mm',\n        top: '10mm',\n        right: '10mm',\n        bottom: '10mm',\n    }\n}\n```\n\nFor more values [see this link](https://github.com/saemhco/master/pdf-options.txt)\n\n- `data` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object 'Object')> It's optional.\n\n### Quick use\n\nservice file\n\n```\nfirstExample() {\n    const filePath = path.join(process.cwd(), 'templates', 'pdf-profile.hbs');\n    return createPdf(filePath);\n}\n```\n\npath/pdf-profile.hbs\n\n```\n<!doctype html>\n<html lang=\"en\">\n  <head>\n    <meta charset=\"utf-8\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n    <title>Profile</title>\n    <link href=\"https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css\" rel=\"stylesheet\" integrity=\"sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65\" crossorigin=\"anonymous\">\n    <style>\n        img {\n                width: 50%;\n                height: auto;\n            }\n        .bg-black {\n            background: #000;\n        }\n\n        .skill-block {\n            width: 30%;\n        }\n\n        .skill-block {\n            padding: 32px !important;\n        }\n\n        body {\n            background-color: #eeeeee;\n        }\n    </style>\n  </head>\n    <body>\n        <div class=\"container mt-5 mb-5\">\n            <div class=\"row no-gutters text-center\">\n                <div class=\"col-12\"><img src=\"https://cdn0.iconfinder.com/data/icons/fillicons-information-technology/1550/programmer_software_developer-512.png\"></div>\n                <div class=\"col-12\">\n                    <div class=\"d-flex flex-column\">\n                        <div class=\"d-flex flex-row justify-content-between align-items-center p-5 bg-dark text-white\">\n                            <h3 class=\"display-5\">Saúl Escandón</h3>\n                        </div>\n                        <div class=\"p-3 bg-black text-white\">\n                            <h6>Sistem enginer &amp; Developer</h6>\n                        </div>\n                        <div class=\"d-flex flex-row text-white\">\n                            <div class=\"p-4 bg-primary text-center skill-block\">\n                                <h4>90%</h4>\n                                <h6>JavaScript</h6>\n                            </div>\n                            <div class=\"p-3 bg-success text-center skill-block\">\n                                <h4>70%</h4>\n                                <h6>NodeJs</h6>\n                            </div>\n                            <div class=\"p-3 bg-warning text-center skill-block\">\n                                <h4>80%</h4>\n                                <h6>HTML</h6>\n                            </div>\n                            <div class=\"p-3 bg-danger text-center skill-block\">\n                                <h4>75%</h4>\n                                <h6>PHP</h6>\n                            </div>\n                        </div>\n                    </div>\n                </div>\n            </div>\n        </div>\n    </body>\n</html>\n```\n\ncontroller\n\n```\n@Get('pdf')\nasync generatePdf(@Res() res) {\nconst buffer = await this.appService.firstExample();\nres.set({\n    // pdf\n    'Content-Type': 'application/pdf',\n    'Content-Disposition': `attachment; filename=pdf.pdf`,\n    'Content-Length': buffer.length,\n    // prevent cache\n    'Cache-Control': 'no-cache, no-store, must-revalidate',\n    Pragma: 'no-cache',\n    Expires: 0,\n});\nres.end(buffer);\n}\n```\n\nResult\n![image](https://user-images.githubusercontent.com/26281994/207532590-f4f7a0db-a620-4912-8137-3803cf748c66.png)\n\n### Other example\n\nservice file\n\n```\nsecondExample() {\n    const data = {\n    title: 'My PDF file',\n    status: 'paid',\n    invoiceId: '#123-123',\n    customerName: 'Saúl Escandón',\n    customerAddress: '1234 Main St',\n    customerCity: 'Huánuco',\n    customerState: 'Huánuco',\n    customerCountry: 'Perú',\n    customerPhone: '555-555-5555',\n    items: [\n            {\n            description: 'custom suit',\n            detail: {\n                color: 'blue',\n                size: '42',\n            },\n            price: {\n                price0: 1500.0,\n                price: 1050.0,\n                save: 25,\n            },\n            quantity: 1,\n            image:\n                'https://mdbcdn.b-cdn.net/img/Photos/Horizontal/E-commerce/new/img(4).webp',\n            },\n            {\n            description: 'playstation 5',\n            detail: {\n                color: 'white',\n                size: '45cmx45cm',\n            },\n            price: {\n                price0: 500.0,\n                price: 250.0,\n                save: 50,\n            },\n            quantity: 2,\n            image:\n                'https://promart.vteximg.com.br/arquivos/ids/931599-1000-1000/image-b08a9ed36e114598bc56d7d4a5e7dd2d.jpg?v=637569550232800000',\n            },\n      ],\n      subTotal: 1550.0,\n      shipping: 15.0,\n      total: 1565.0,\n    };\n    const options = {\n      format: 'A4',\n      displayHeaderFooter: true,\n      margin: {\n        left: '10mm',\n        top: '25mm',\n        right: '10mm',\n        bottom: '15mm',\n      },\n      headerTemplate: `<div style=\"width: 100%; text-align: center;\"><span style=\"font-size: 20px;\">@saemhco CORP</span><br><span class=\"date\" style=\"font-size:15px\"><span></div>`,\n      footerTemplate:\n        '<div style=\"width: 100%; text-align: center; font-size: 10px;\">Page <span class=\"pageNumber\"></span> of <span class=\"totalPages\"></span></div>',\n      landscape: true,\n    };\n    const filePath = path.join(process.cwd(), 'templates', 'pdf-invoice.hbs');;\n    return createPdf(filePath, options, data);\n}\n```\n\npath/pdf-invoice.hbs\n\n```\n<!doctype html>\n<html lang=\"en\">\n  <head>\n    <meta charset=\"utf-8\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n    <title>{{title}}</title>\n    <link href=\"https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css\" rel=\"stylesheet\" integrity=\"sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65\" crossorigin=\"anonymous\">\n  </head>\n    <body>\n        <div class=\"card\">\n            <div class=\"card-body\">\n                <div class=\"container mb-5 mt-3\">\n                <div class=\"row d-flex align-items-baseline\">\n                    <div class=\"col-xl-9\">\n                    <p style=\"color: #7e8d9f;font-size: 20px;\">Invoice &gt;&gt; <strong>ID: {{invoiceId}}</strong></p>\n                    </div>\n                </div>\n                <div class=\"container\">\n                    <div class=\"col-md-12\">\n                    </div>\n                    <div class=\"row\">\n                    <div class=\"col-8\">\n                        <ul class=\"list-unstyled\">\n                        <li class=\"text-muted\">To: <span style=\"color:#8f8061 ;\">{{customerName}}</span></li>\n                        <li class=\"text-muted\">{{customerAddress}} | {{customerState}}, {{customerCountry}}</li>\n                        <li class=\"text-muted\"><i class=\"fas fa-phone\"></i> {{customerPhone}}</li>\n                        </ul>\n                    </div>\n                    <div class=\"col-4\">\n                        <ul class=\"list-unstyled\">\n                        <li class=\"text-muted\"><i class=\"fas fa-circle\" style=\"color:#8f8061 ;\"></i> <span\n                            class=\"fw-bold\">ID:</span>#123-456</li>\n                        <li class=\"text-muted\"><i class=\"fas fa-circle\" style=\"color:#8f8061;\"></i>\n                            <span class=\"me-1 fw-bold\">Status:</span>\n                                {{#ifCond status \"===\" \"paid\"}}\n                                <span class=\"badge bg-warning text-black fw-bold\">Unpaid</span>\n                                {{/ifCond}}\n                                 {{#ifCond status \"===\" \"unpaid\"}}\n                                <span class=\"badge bg-success text-black fw-bold\">Paid</span>\n                                {{/ifCond}}\n                        </li>\n                        </ul>\n                    </div>\n                    </div>\n                    <div class=\"row my-2 mx-1 justify-content-center\">\n                        {{#each items}}\n                        <div class=\"col-md-2 mb-4 mb-md-0\">\n                            <div class=\"bg-image ripple rounded-5 mb-4 overflow-hidden d-block\" data-ripple-color=\"light\">\n                            <img src=\"{{image}}\" class=\"w-100\" height=\"100px\" alt=\"Elegant shoes and shirt\" />\n                            <a href=\"#!\">\n                                <div class=\"hover-overlay\">\n                                <div class=\"mask\" style=\"background-color: hsla(0, 0%, 98.4%, 0.2)\"></div>\n                                </div>\n                            </a>\n                            </div>\n                        </div>\n                        <div class=\"col-md-7 mb-4 mb-md-0\">\n                            <p class=\"fw-bold\">{{description}}</p>\n                            <p class=\"mb-1\">\n                            <span class=\"text-muted me-2\">Size:</span><span>{{detail.size}}</span>\n                            </p>\n                            <p>\n                            <span class=\"text-muted me-2\">Color:</span><span>{{detail.color}}</span>\n                            </p>\n                        </div>\n                        <div class=\"col-md-3 mb-4 mb-md-0\">\n                            <h5 class=\"mb-2\">\n                            <s class=\"text-muted me-2 small align-middle\">${{price.price0}}</s><span class=\"align-middle\">${{price.price}}</span>\n                            </h5>\n                            <p class=\"text-danger\"><small>You save {{price.save}}%</small></p>\n                        </div>\n                        {{/each}}\n\n                    <hr>\n                    </div>\n                    <div class=\"row\">\n                        <div class=\"col-xl-3\">\n                            <ul class=\"list-unstyled\">\n                            <li class=\"text-muted ms-3\"><span class=\"text-black me-4\">SubTotal</span>${{subTotal}}</li>\n                            <li class=\"text-muted ms-3 mt-2\"><span class=\"text-black me-4\">Shipping</span>${{shipping}}</li>\n                            </ul>\n                            <p class=\"text-black float-start\"><span class=\"text-black me-3\"> Total Amount</span><span\n                                style=\"font-size: 20px;\">${{total}}</span></p>\n                        </div>\n                    </div>\n                </div>\n                </div>\n            </div>\n        </div>\n    </body>\n</html>\n```\n\ncontroller\n\n```\n@Get('pdf')\nasync generatePdf2(@Res() res) {\n    const buffer = await this.appService.secondExample();\n    res.set({\n      // pdf\n      'Content-Type': 'application/pdf',\n      'Content-Disposition': `attachment; filename=pdf.pdf`,\n      'Content-Length': buffer.length,\n      // prevent cache\n      'Cache-Control': 'no-cache, no-store, must-revalidate',\n      Pragma: 'no-cache',\n      Expires: 0,\n    });\n    res.end(buffer);\n  }\n}\n```\n\nResult\n![image](https://user-images.githubusercontent.com/26281994/207534170-ad8ffd45-3385-4c3a-a579-aad5b585e1eb.png)\n\n### More details\n\n---\n\n| JavaScript      | HTMLBars OP1           | HTMLBars OP2                  |\n| --------------- | ---------------------- | ----------------------------- |\n| `if (a === b)`  | `{{#if (eq a b)}}`     | `{{#ifCond var1 '===' var2}}` |\n| `if (a !== b)`  | `{{#if (not-eq a b)}}` | `{{#ifCond var1 '!==' var2}}` |\n| `if (a && b)`   | `{{#if (and a b)}}`    | `{{#ifCond var1 '&&' var2}}`  |\n| `if (a > b)`    | `{{#if (gt a b)}}`     | `{{#ifCond var1 '>' var2}}`   |\n| `if (a >= b)`   | `{{#if (gte a b)}}`    | `{{#ifCond var1 '>=' var2}}`  |\n| `if (a < b)`    | `{{#if (lt a b)}}`     | `{{#ifCond var1 '<' var2}}`   |\n| `if (a <= b)`   | `{{#if (lte a b)}}`    | `{{#ifCond var1 '<=' var2}}`  |\n| `if (a && b)`   | `{{#if (and a b)}}`    | `{{#ifCond var1 '&&' var2}}`  |\n| `if (a \\|\\| b)` | `{{#if (or a b)}}`     | `{{#ifCond var1 \\|\\| var2}}`  |\n","readmeFilename":"README.md"}