{"id":16357802,"url":"https://github.com/0tii/html-to-pdf","last_synced_at":"2025-10-26T04:31:03.467Z","repository":{"id":38403159,"uuid":"505748545","full_name":"0tii/html-to-pdf","owner":"0tii","description":"🖥️ An easy-to-use but reliable asynchronous library to create highly customizable PDFs from HTML or URL as buffer, base64 string and .pdf file using puppeteer.","archived":false,"fork":false,"pushed_at":"2023-09-28T07:17:28.000Z","size":40,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-31T14:34:37.779Z","etag":null,"topics":["convert","html","html-pdf","html2pdf","node","npm","pdf"],"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/0tii.png","metadata":{"files":{"readme":"readme.md","changelog":"CHANGELOG","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-06-21T08:07:57.000Z","updated_at":"2023-10-25T13:19:06.000Z","dependencies_parsed_at":"2022-09-07T20:21:27.383Z","dependency_job_id":null,"html_url":"https://github.com/0tii/html-to-pdf","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/0tii%2Fhtml-to-pdf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0tii%2Fhtml-to-pdf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0tii%2Fhtml-to-pdf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0tii%2Fhtml-to-pdf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/0tii","download_url":"https://codeload.github.com/0tii/html-to-pdf/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238259020,"owners_count":19442517,"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":["convert","html","html-pdf","html2pdf","node","npm","pdf"],"created_at":"2024-10-11T02:04:09.879Z","updated_at":"2025-10-26T04:31:03.121Z","avatar_url":"https://github.com/0tii.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🖥️ HTML2PDF\nAn easy-to-use but reliable asynchronous library to create highly customizable PDFs from HTML or URL as ``buffer``, ``base64 string`` and ``.pdf file``. Other than most npm-solutions for html-to-pdf conversion, this one leverages ``puppeteer`` as opposed to the deprecated and unmaintained ``phantomJS``. It also provides far more options to configure to your liking than most similar solutions. This *might* be the best html-to-pdf solution on npm at this point.\n\n## Installation\n```\nnpm i [-g] better-html-pdf\n```\n\n## Available functions\nOther than the main converter function, HTML2PDF exposes two more functions that allow writing pdf file content as both ``base64`` or ``buffer``. Those functions are also used internally to replace the situationally unreliable ``puppeteer``-native file save function that is controlled through the ``path`` option.\n\n### Function signatures\nConvert html to pdf\n```typescript\nhtml2pdf(html: string, options: Object) : Promise\u003cstring | Buffer\u003e\n```\nConvert base64 file content to PDF file\n```typescript\nbase64ToPdf(base64: string, file: string) : void\n```\nConvert file content buffer to PDF file\n```typescript\nbufferToPdf(buffer: Buffer, file: string) : void\n```\n\n### Usage\nUsing HTML2PDF is quick and simple: Import the ``html2pdf`` function and pass it the html and options.\n```javascript\nconst { html2pdf, base64ToPdf, bufferToPdf } = require('better-html-pdf');\n\n//[...]\n// convert html to PDF\nconst fileContentB64 = await html2pdf('\u003ch1\u003eTest\u003c/h1\u003e', { avoidTableRowBreak: true, marginTop: 10, repeatTableHeader: false });\nconst fileContentBuffer = await html2pdf('\u003ch1\u003eTest\u003c/h1\u003e', { fileType: 'buffer', url: 'https://google.com/', viewPort: '1000x700' });\n\n//convert output to pdf file\nbase64ToPdf(fileContentB64, './test1.pdf');\nbufferToPdf(fileContentBuffer, './test2.pdf');\n```\n\nFull type declarations are included so ES6 imports are available, too.\n```javascript\nimport { html2pdf } from 'better-html-pdf';\n\n//[...]\n// convert html to PDF\nconst fileContentB64 = await html2pdf('\u003ch1\u003eTest\u003c/h1\u003e', { avoidTableRowBreak: true, marginTop: 10, repeatTableHeader: false });\n```\n### Options\nThis solution provides a great number of options to configure for your conversion, passed as a javascript object.\n**Find a detailed doc of all options and defaults here**: [Options Documentation](https://github.com/0tii/html-to-pdf/blob/master/options.md).\n\n```javascript\n{\n    fileType: 'base64', // 'base64' | 'buffer'\n    url: '', //if specified ignores html\n    viewPort: '1920x1080', //string (width)x(height)\n    timeout: 5000, //timeout for page loading in ms\n    landscape: false,\n    format: '', //letter | legal | tabloid | ledger | a0 | a1 | a2 | a3 | a4 | a5 | a6\n    repeatTableHeader: true, //repeat html table headers on each page - note: headers only repeat when in \u003cthead\u003e\n    repeatTableFooter: true, //repeat html table footers on each page - note: footers only repeat when in \u003ctfoot\u003e\n    displayHeaderFooter: true,\n    headerTemplate: '',\n    footerTemplate: '',\n    width: '1920', //document size in pixels or with units (in, mm, cm)\n    height: '1080', //document size in pixels or with units (in, mm, cm)\n    marginTop: 0, //num in pixels or with units (in, mm, cm)\n    marginBottom: 0, //num in pixels or with units (in, mm, cm)\n    marginLeft: 0, //num in pixels or with units (in, mm, cm)\n    marginRight: 0, //num in pixels or with units (in, mm, cm)\n    breakImages: false, //break images between pages\n    avoidTableRowBreak: true, //tries avoiding breaking table rows between pages\n    avoidDivBreak: false, //tries to avoid breaking divs between pages - can cause unwanted behavior\n    omitBackground: false, //hide html background, allows for transparency\n    pageRanges: '', //'1-12' | '3-5'\n    path: '', //file save path, if empty no file is created\n    disableJavascript: false, //disable javascript on the target site/html\n    preferCSSPageSize: false, //css-declared page size takes precedent over format, width and height\n    printBackground: true, //apply background styling\n    trueColors: true, //use unaltered colors\n    scale: 1, //render scale, must be between 0.1 and 2\n    screenMedia: false //use 'screen' instead of 'print' CSS media\n}\n```\n\n## Dependencies\nHTML2PDF depends on `puppeteer`.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0tii%2Fhtml-to-pdf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F0tii%2Fhtml-to-pdf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0tii%2Fhtml-to-pdf/lists"}