{"id":25322729,"url":"https://github.com/ccjmne/puppeteer-html2pdf","last_synced_at":"2025-12-28T20:47:23.176Z","repository":{"id":43455446,"uuid":"180798485","full_name":"ccjmne/puppeteer-html2pdf","owner":"ccjmne","description":"Print your HTML to PDF via Puppeteer in a Docker container.","archived":false,"fork":false,"pushed_at":"2025-08-19T13:25:39.000Z","size":392,"stargazers_count":16,"open_issues_count":0,"forks_count":10,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-08-19T15:29:46.342Z","etag":null,"topics":["docker","html-to-pdf","nodejs","pdf","puppeteer"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/ccjmne.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,"zenodo":null}},"created_at":"2019-04-11T13:29:58.000Z","updated_at":"2025-08-19T13:25:43.000Z","dependencies_parsed_at":"2023-11-21T20:26:53.836Z","dependency_job_id":"4c364354-326d-4d9a-9c8b-37e9920139e5","html_url":"https://github.com/ccjmne/puppeteer-html2pdf","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"purl":"pkg:github/ccjmne/puppeteer-html2pdf","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ccjmne%2Fpuppeteer-html2pdf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ccjmne%2Fpuppeteer-html2pdf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ccjmne%2Fpuppeteer-html2pdf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ccjmne%2Fpuppeteer-html2pdf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ccjmne","download_url":"https://codeload.github.com/ccjmne/puppeteer-html2pdf/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ccjmne%2Fpuppeteer-html2pdf/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273459068,"owners_count":25109568,"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-09-03T02:00:09.631Z","response_time":76,"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":["docker","html-to-pdf","nodejs","pdf","puppeteer"],"created_at":"2025-02-13T23:47:58.701Z","updated_at":"2025-12-28T20:47:23.161Z","avatar_url":"https://github.com/ccjmne.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ccjmne/puppeteer-html2pdf\n\nPrint your HTML to PDF through a Web server.\n\n[![Docker Image CI](https://github.com/ccjmne/puppeteer-html2pdf/actions/workflows/publish-to-ghcr.yml/badge.svg)](https://github.com/ccjmne/puppeteer-html2pdf/actions/workflows/publish-to-ghcr.yml)\n\n## Inside the box\n\nThis is a simple [Express](https://expressjs.com/) server listening for `POST` requests passing some arbitrary HTML to print as PDF for generating fancy reports.\n\nTechnologies used:\n\n- [Docker](https://www.docker.com/)\n- [Puppeteer](https://github.com/GoogleChrome/puppeteer)\n- [Express](https://expressjs.com/)\n- [NodeJS](https://nodejs.org/en/)\n\nIt offers images for both ARM and AMD architectures.\n\n## Quick Start\n\nThis example (which you can copy and directly paste into your shell interpreter) will run it on port `3000` and print a simple HTML document to PDF.\n\n```shell\ndocker run --name html2pdf --detach --publish=3000:3000 --memory 500M ghcr.io/ccjmne/puppeteer-html2pdf:latest\n# It may take a second to precompute fonts cache on the first start-up\nuntil curl -q localhost:3000 \u003e/dev/null 2\u003e\u00261; do sleep 0.1; done\n\n# Or for a quick test, to be killed with Ctrl-C:\n# docker run -it --rm -p=3000:3000 ghcr.io/ccjmne/puppeteer-html2pdf:latest\n\ncurl localhost:3000 -H 'Content-Type: text/html' --data '\n\u003ch1\u003eHello World!\u003c/h1\u003e\n\u003cblockquote\u003e\n  I love deadlines. I like the whooshing sound they make as they fly by.\n  \u003cbr\u003e\n  \u003csmall style=\"float:right\"\u003e— Douglas Adams\u003c/small\u003e\n\u003c/blockquote\u003e\n' \u003e out.pdf \u0026\u0026 xdg-open out.pdf\n```\n\n## Docker Environment Variables\n\n| Name              | Description                                                                                                               | Default Value |\n| ----------------- | ------------------------------------------------------------------------------------------------------------------------- | ------------- |\n| BODY_LIMIT        | Maximum request body size. Passed on to [body-parser](https://github.com/expressjs/body-parser#limit) and `express.json`. | `1mb`         |\n| BROWSER_KEEPALIVE | Period (in ms) of inactivity after which the shared browser instance is shut down.                                        | `30000` (30s) |\n\n## Setting PDF Information Dictionary\n\nThe [properties of the PDF Information Dictionary](https://www.verypdf.com/document/pdf-format-reference/pg_0844.htm) can also be controlled via query parameters. These are:\n\n| Parameter      | Description                                                                                                                                                 |\n| -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| `title`        | The document's title                                                                                                                                        |\n| `author`       | The name of the person who created the document                                                                                                             |\n| `subject`      | The subject of the document                                                                                                                                 |\n| `keywords`     | Keywords associated with the document                                                                                                                       |\n| `creator`      | If the document was converted to PDF from another format, the name of the conforming product that created the original document from which it was converted |\n| `producer`     | If the document was converted to PDF from another format, the name of the conforming product that converted it to PDF                                       |\n| `creationDate` | The date and time the document was created                                                                                                                  |\n| `modDate`      | The date and time the document was most recently modified                                                                                                   |\n\nDefault values are provided for five of these:\n\n| Parameter      | Default value                                                                          |\n| -------------- | -------------------------------------------------------------------------------------- |\n| `title`        | The first (or only) HTML document or Web page's title                                  |\n| `creator`      | The full name and version of Chromium driven that generated the PDFs through Puppeteer |\n| `producer`     | The name and version of this application                                               |\n| `creationDate` | The current date and time                                                              |\n| `modDate`      | The current date and time                                                              |\n\n## Custom Fonts\n\nThe simplest way to add fonts is to mount a volume with the fonts you want to use to the `/usr/share/fonts` directory in the container.\n\n```shell\n# Obtain a font\nlongcang=$(curl -L 'https://fonts.googleapis.com/css2?family=Long+Cang' | grep -Po '(?\u003c=url\\()[^)]+')\ncurl -L \"$longcang\" -o LongCang-Regular.ttf\n\n# Add it to the container\ndocker run -it --rm -p3000:3000                                          \\\n    -v./LongCang-Regular.ttf:/usr/local/share/fonts/LongCang-Regular.ttf \\\n    ghcr.io/ccjmne/puppeteer-html2pdf:latest\n\n# Use it in your HTML\ncurl localhost:3000 -H 'Content-Type: text/html' --data '\n\u003chtml\u003e\n  \u003cbody style=\"font-family: '\\''Long Cang'\\'', cursive;\"\u003e\n    \u003ch1\u003eI play nice with custom fonts, too!\u003c/h1\u003e\n    \u003cp\u003e鉴于对人类家庭所有成员的固有尊严及其平等的和不移的权利的承认,乃是世界自由、正义与和平的基础\u003c/p\u003e\n  \u003c/body\u003e\n\u003c/html\u003e' \u003e out.pdf \u0026\u0026 xdg-open out.pdf\n```\n\n## Endpoints\n\nThe Web server listens on a port of your choosing (see the [Quick Start](#quick-start) section) and exposes two endpoints:\n\nSingle-page document, default settings (format: `A4`, orientation: `portrait`):\n\n|                        | Single-page document    | Multi-page document                       | List of URLs to render    |\n| ---------------------- | ----------------------- | ----------------------------------------- | ------------------------- |\n| Request Path           | `/`                     | `/multiple`                               | `/url`                    |\n| Request Method         | `POST`                  | `POST`                                    | `POST`                    |\n| `Content-Type` header  | `text/html`             | `application/json`                        | `text/plain`              |\n| Request Body           | HTML content            | JSON array of strings containing HTML     | One absolute URL per line |\n| Request Body (example) | `\u003ch1\u003eHello World!\u003c/h1\u003e` | `[\"\u003ch1\u003ePage 1\u003c/h2\u003e\", \"\u003ch1\u003ePage 2\u003c/h1\u003e\" ]` | `https://google.com`      |\n\nAll endpoints handle the following query parameters:\n\n- `filename`: the name of the resulting PDF file (will automatically append the `.pdf` extension if absent)\n- `onepage`: `true` to force the creation of a single (possibly gigantic) page for each individual URL or HTML document. If set, overrules `format` and `landscape`\n- all the [properties of the PDF Information Dictionary](https://www.verypdf.com/document/pdf-format-reference/pg_0844.htm), except `trapped`:\n  - `title`\n  - `author`\n  - `subject`\n  - `keywords` (you may provide several, e.g.: `?keywords=travelling\u0026keywords=korea\u0026keywords=beautiful`)\n  - `creator`\n  - `producer`\n  - `creationDate` (parsed as `ISO-8601`, e.g.: `2025-12-28`)\n  - `modDate` (parsed as `ISO-8601`, e.g.: `2025-12-28`)\n- all the options supported by [Puppeteer's `page#pdf(\\[options\\])`](https://github.com/puppeteer/puppeteer/blob/main/docs/api.md#pagepdfoptions), except:\n  - `path`\n  - `headerTemplate`\n  - `margin`\n\n### Examples\n\nSingle-page document, default settings (format: `A4`, orientation: `portrait`):\n\n```bash\ncurl 'http://localhost:3000'                           \\\n  -H 'Content-Type: text/html'                         \\\n  -d '\u003chtml\u003e\u003cbody\u003e\u003ch1\u003eHello World!\u003c/h1\u003e\u003c/body\u003e\u003c/html\u003e' \\\n  \u003e out.pdf \u0026\u0026 xdg-open out.pdf\n```\n\nSingle-page document (format: `A3`, orientation: `landscape`):\n\n```bash\ncurl 'http://localhost:3000?format=a3\u0026landscape=true'  \\\n  -H 'Content-Type: text/html'                         \\\n  -d '\u003chtml\u003e\u003cbody\u003e\u003ch1\u003eHello World!\u003c/h1\u003e\u003c/body\u003e\u003c/html\u003e' \\\n  \u003e out.pdf \u0026\u0026 xdg-open out.pdf\n```\n\nSpecify Information Dictionary:\n\n```bash\ncurl 'http://localhost:3000?author=ccjmne\u0026title=Hello+World' \\\n  -H 'Content-Type: text/html'                               \\\n  -d '\u003chtml\u003e\u003cbody\u003e\u003ch1\u003eHello World!\u003c/h1\u003e\u003c/body\u003e\u003c/html\u003e'       \\\n  \u003e out.pdf \u0026\u0026 xdg-open out.pdf\n```\n\nMulti-page document:\n\n```bash\ncurl 'http://localhost:3000/multiple'                  \\\n  -H 'Content-Type: application/json'                  \\\n  -d '[\n    \"\u003chtml\u003e\u003cbody\u003e\u003ch1\u003eHello World!\u003c/h1\u003e\u003c/body\u003e\u003c/html\u003e\",\n    \"This is the \u003cstrong\u003esecond\u003c/strong\u003e page\"\n  ]'                                                   \\\n  \u003e out.pdf \u0026\u0026 xdg-open out.pdf\n```\n\nConverting a Web page to PDF:\n\n```bash\ncurl 'http://localhost:3000/url?onepage=true' \\\n  -H 'Content-Type: text/plain'               \\\n  -d 'https://justinjackson.ca/webmaster/'    \\\n  \u003e out.pdf \u0026\u0026 xdg-open out.pdf\n```\n\nConverting several Web pages into a single PDF:\n\n```bash\ncurl 'http://localhost:3000/url?onepage=true' \\\n  -H 'Content-Type: text/plain'               \\\n  -d '\n    https://justinjackson.ca/webmaster/\n    https://ccjmne.sh/blog/\n  '                                           \\\n  \u003e out.pdf \u0026\u0026 xdg-open out.pdf\n```\n\n## Maintainer Notes\n\n**Automatically builds and publishes to GitHub Packages** (GitHub Container Registry) with each **GitHub Release**.\n\nIncludes a comprehensive script that lets you build and publish new versions of the image: `./compose.sh \u003cversion\u003e`\n\n### TODO\n\n- [ ] Support printing screenshots as images\n  - [ ] Rename to html-printer?\n- [ ] Provide as plain TypeScript library rather than a Web server\n  - [ ] Publish library to [npm](https://www.npmjs.com/)\n\n## License\n\nMIT. Do as you please.  \nRefer to the [LICENSE](./LICENSE) file for more details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fccjmne%2Fpuppeteer-html2pdf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fccjmne%2Fpuppeteer-html2pdf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fccjmne%2Fpuppeteer-html2pdf/lists"}