{"id":13566833,"url":"https://github.com/condorheroblog/html-export-pdf-cli","last_synced_at":"2025-04-30T20:31:19.771Z","repository":{"id":154124404,"uuid":"626223677","full_name":"condorheroblog/html-export-pdf-cli","owner":"condorheroblog","description":"Render HTML to PDF(with outline) using Puppeteer.","archived":false,"fork":false,"pushed_at":"2024-08-02T02:17:34.000Z","size":8022,"stargazers_count":18,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-11-04T21:39:56.427Z","etag":null,"topics":["bookmark","headless-chrome","html-pdf-chrome","html-to-pdf","outline","pdf","pdf-generator","puppeteer","toc"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/html-export-pdf-cli","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/condorheroblog.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":"2023-04-11T03:27:03.000Z","updated_at":"2024-09-13T07:04:23.000Z","dependencies_parsed_at":null,"dependency_job_id":"a0622b3b-4d08-460a-b287-2d7c08b37173","html_url":"https://github.com/condorheroblog/html-export-pdf-cli","commit_stats":null,"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/condorheroblog%2Fhtml-export-pdf-cli","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/condorheroblog%2Fhtml-export-pdf-cli/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/condorheroblog%2Fhtml-export-pdf-cli/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/condorheroblog%2Fhtml-export-pdf-cli/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/condorheroblog","download_url":"https://codeload.github.com/condorheroblog/html-export-pdf-cli/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224224633,"owners_count":17276427,"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":["bookmark","headless-chrome","html-pdf-chrome","html-to-pdf","outline","pdf","pdf-generator","puppeteer","toc"],"created_at":"2024-08-01T13:02:17.684Z","updated_at":"2024-11-12T05:30:07.971Z","avatar_url":"https://github.com/condorheroblog.png","language":"TypeScript","readme":"# html-export-pdf-cli\n\n[![NPM version](https://img.shields.io/npm/v/html-export-pdf-cli)](https://www.npmjs.com/package/html-export-pdf-cli)\n[![NPM Downloads](https://img.shields.io/npm/dm/html-export-pdf-cli)](https://www.npmjs.com/package/html-export-pdf-cli)\n[![LICENSE](https://img.shields.io/github/license/condorheroblog/html-export-pdf-cli.svg)](https://github.com/condorheroblog/html-export-pdf-cli/blob/main/LICENSE)\n[![GitHub stars](https://img.shields.io/github/stars/condorheroblog/html-export-pdf-cli)](https://github.com/condorheroblog/html-export-pdf-cli)\n\nRender HTML to PDF(**with outline**) using [Puppeteer](https://github.com/GoogleChrome/puppeteer).\n\n## Features\n\n- 🖥️ Converting HTML to PDF for `.html`, `.htm`, `.xhtml` file formats\n- 📑 **Added PDF outline**\n- ⚙️ Configurations for generating PDF with Puppeteer —— [pdfOptions](https://github.com/puppeteer/puppeteer/blob/main/docs/api/puppeteer.pdfoptions.md)\n- 📂 Multi-file PDF generation\n- ⌨️ Developed in TypeScript\n- ⏬ Download web page\n\n## Installation\n\n```bash\n# Global installation\nnpm install -g html-export-pdf-cli\n\n# Local installation\nnpm install --save-dev html-export-pdf-cli\n```\n\nThe installed `html-export-pdf-cli` command is available.\n\n## Usage\n\n### Generating a PDF\n\n```bash\nhtml-export-pdf-cli ./index.html -o result.pdf\n```\n\n### Generating two PDFs\n\n```bash\nhtml-export-pdf-cli ./index.html ./home.html\n# or\nhtml-export-pdf-cli -t ./index.html -t ./home.html\nhtml-export-pdf-cli --inputs ./index.html --inputs ./home.html\n```\n\n### Generating some PDFs\n\nThis Library uses glob to parse the path you enter, and its syntax refers to the [glob documentation](https://github.com/mrmlnc/fast-glob#basic-syntax).\n\n```bash\nhtml-export-pdf-cli ./pdf/*.html\n```\n\n### Outline\n\n```bash\nhtml-export-pdf-cli ./index.html --outlineTags h1,h2 -o index.pdf\n```\n\nUsing outlineContainerSelector specify an outline container selector\n\n```bash\nhtml-export-pdf-cli ./index.html --outlineContainerSelector .VPDoc --outlineTags h1,h2 -o index.pdf\n```\n\n### Additional Scripts\n\n```bash\nhtml-export-pdf-cli ./index.html --additionalScripts a.js --additionalScripts b.js -o index.pdf\n```\n### Additional Styles\n\n```bash\nhtml-export-pdf-cli ./index.html --additionalStyles a.css --additionalStyles b.css -o index.pdf\n```\n\n### PDF Options\n\nYou can customize all configuration parameters for Puppeteer to generate PDF except `path`.\n\n| Property            | Modifiers             | Type                                      | Description                                                                                                                                                                                                                                                                                                                                                                     | Default                                                                  |\n| ------------------- | --------------------- | ----------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------ |\n| footerTemplate      | \u003ccode\u003eoptional\u003c/code\u003e | string                                    | HTML template for the print footer. Has the same constraints and support for special classes as PDFOptions.headerTemplate.                                                                                                                                                                                                                                                      |                                                                          |\n| format              | \u003ccode\u003eoptional\u003c/code\u003e | [PaperFormat](#paperformat)               |                                                                                                                                                                                                                                                                                                                                                                                 | \u003ccode\u003eletter\u003c/code\u003e.                                                     |\n| headerTemplate      | \u003ccode\u003eoptional\u003c/code\u003e | string                                    | \u003cp\u003eHTML template for the print header. Should be valid HTML with the following classes used to inject values into them:\u003c/p\u003e\u003cp\u003e- \u003ccode\u003edate\u003c/code\u003e formatted print date\u003c/p\u003e\u003cp\u003e- \u003ccode\u003etitle\u003c/code\u003e document title\u003c/p\u003e\u003cp\u003e- \u003ccode\u003eurl\u003c/code\u003e document location\u003c/p\u003e\u003cp\u003e- \u003ccode\u003epageNumber\u003c/code\u003e current page number\u003c/p\u003e\u003cp\u003e- \u003ccode\u003etotalPages\u003c/code\u003e total pages in the document\u003c/p\u003e |                                                                          |\n| height              | \u003ccode\u003eoptional\u003c/code\u003e | string \\| number                          | Sets the height of paper. You can pass in a number or a string with a unit.                                                                                                                                                                                                                                                                                                     |                                                                          |\n| landscape           | \u003ccode\u003eoptional\u003c/code\u003e | boolean                                   | Whether to print in landscape orientation.                                                                                                                                                                                                                                                                                                                                      | \u003ccode\u003efalse\u003c/code\u003e                                                       |\n| margin              | \u003ccode\u003eoptional\u003c/code\u003e | [PDFMargin](#pdfmargin)                   | Set the PDF margins.                                                                                                                                                                                                                                                                                                                                                            | \u003ccode\u003eundefined\u003c/code\u003e no margins are set.                               |\n| omitBackground      | \u003ccode\u003eoptional\u003c/code\u003e | boolean                                   | Hides default white background and allows generating PDFs with transparency.                                                                                                                                                                                                                                                                                                    | \u003ccode\u003efalse\u003c/code\u003e                                                       |\n| pageRanges          | \u003ccode\u003eoptional\u003c/code\u003e | string                                    | Paper ranges to print, e.g. \u003ccode\u003e1-5, 8, 11-13\u003c/code\u003e.                                                                                                                                                                                                                                                                                                                         | The empty string, which means all pages are printed.                     |\n| preferCSSPageSize   | \u003ccode\u003eoptional\u003c/code\u003e | boolean                                   | Give any CSS \u003ccode\u003e@page\u003c/code\u003e size declared in the page priority over what is declared in the \u003ccode\u003ewidth\u003c/code\u003e or \u003ccode\u003eheight\u003c/code\u003e or \u003ccode\u003eformat\u003c/code\u003e option.                                                                                                                                                                                                        | \u003ccode\u003efalse\u003c/code\u003e, which will scale the content to fit the paper size.  |\n| printBackground     | \u003ccode\u003eoptional\u003c/code\u003e | boolean                                   | Set to \u003ccode\u003etrue\u003c/code\u003e to print background graphics.                                                                                                                                                                                                                                                                                                                          | \u003ccode\u003efalse\u003c/code\u003e                                                       |\n| scale               | \u003ccode\u003eoptional\u003c/code\u003e | number                                    | Scales the rendering of the web page. Amount must be between \u003ccode\u003e0.1\u003c/code\u003e and \u003ccode\u003e2\u003c/code\u003e.                                                                                                                                                                                                                                                                               | \u003ccode\u003e1\u003c/code\u003e                                                           |\n| timeout             | \u003ccode\u003eoptional\u003c/code\u003e | number                                    | Timeout in milliseconds. Pass \u003ccode\u003e0\u003c/code\u003e to disable timeout.                                                                                                                                                                                                                                                                                                                | \u003ccode\u003e30_000\u003c/code\u003e                                                      |\n| width               | \u003ccode\u003eoptional\u003c/code\u003e | string \\| number                          | Sets the width of paper. You can pass in a number or a string with a unit.                                                                                                                                                                                                                                                                                                      |                                                                          |\n\n#### Format\n\n```bash\nhtml-export-pdf-cli ./index.html -s A0 -o index.pdf\n# or\nhtml-export-pdf-cli ./index.html --pageSize A0 -o index.pdf\n```\n\n#### Margin\n\n```bash\nhtml-export-pdf-cli ./index.html -m top=10,bottom=10,left=10,right=10 -o index.pdf\n# or\nhtml-export-pdf-cli ./index.html --margin top=10,bottom=10,left=10,right=10 -o index.pdf\n```\n\nThe order can be customized, even omitting a few.\n\n```bash\nhtml-export-pdf-cli ./index.html -m top=10 -o index.pdf\nhtml-export-pdf-cli ./index.html -m right=10 -o index.pdf\nhtml-export-pdf-cli ./index.html -m right=10,left=10 -o index.pdf\nhtml-export-pdf-cli ./index.html -m top=10,left=10 -o index.pdf\n```\n\n#### Page Ranges\n\n```bash\nhtml-export-pdf-cli ./index.html --pageRanges 1-5 -o index.pdf\n```\n\n#### OmitBackground\n\n```bash\nhtml-export-pdf-cli ./index.html --omitBackground -o index.pdf\n```\n\netc.\n\n#### [PaperFormat](https://github.com/puppeteer/puppeteer/blob/main/docs/api/puppeteer.paperformat.md)\n\n#### [PDFMargin](https://github.com/puppeteer/puppeteer/blob/main/docs/api/puppeteer.pdfmargin.md)\n\n## PDF File Name Convention\n\nRules for automatically generating PDF file names.\n\n| URL                                           | Filename                     |\n|-----------------------------------------------|------------------------------|\n| `https://www.example.com/`                    | `www.example.com.pdf`        |\n| `https://www.example.com:80/`                 | `www.example.com.pdf`        |\n| `https://www.example.com/resource`            | `resource.pdf`               |\n| `https://www.example.com/resource.extension`  | `resource.pdf`               |\n| `https://www.example.com/path/`               | `path.pdf`                   |\n| `https://www.example.com/path/to/`            | `path_to.pdf`                |\n| `https://www.example.com/path/to/resource`    | `resource.pdf`               |\n| `https://www.example.com/path/to/resource.ext`| `resource.pdf`               |\n| `file:///User/path/to/resource.html`          | `resource.pdf`               |\n\n## Options\n\n| Key                          | Type                  | CLI option                      | Description                                                                                                                   |  Default Value         |\n| :--------------------------- | :--------------------:| :-----------------------------: | :---------------------------------------------------------------------------------------------------------------------------: | :---------------------:|\n| `inputs`                     | `string[]`            | `--inputs`                      | Input one or more local or online paths.                                                                                      | `[]`                   |\n| `outFile`                    | `string`              | `--outFile`                     | Output file name.                                                                                                             | {input}.pdf            |\n| `outDir`                     | `string`              | `--outDir`                      | Output directory.                                                                                                             | `process.cwd()`        |\n| `headless`                   | `boolean` \\| `shell`  | `--headless`                    | Whether to run the browser in headless mode.                                                                                  | `true`                 |\n| `PDFOptions`                 | `object`              |                                 | Valid options to configure PDF generation via Page.pdf().                                                                     |                        |\n| ┗ `scale`                    | `number`              | `--scale`                       | Scales the rendering of the web page. Amount must be between 0.1 and 2.                                                       | 1                      |\n| ┗ `headerTemplate`           | `string`              | `--headerTemplate`              | HTML template for the print header.                                                                                           |                        |\n| ┗ `footerTemplate`           | `string`              | `--footerTemplate`              | HTML template for the print footer.                                                                                           |                        |\n| ┗ `preferCSSPageSize`        | `boolean`             | `--preferCSSPageSize`           | Give any CSS @page size declared in the page priority over what is declared in the width or height or format option.          | `false`                |\n| ┗ `printBackground`          | `boolean`             | `--printBackground`             | Set to print background graphics.                                                                                             | `false`                |\n| ┗ `omitBackground`           | `boolean`             | `--omitBackground`              | Hides default white background and allows generating PDFs with transparency.                                                  | `false`                |\n| ┗ `pageRanges`               | `string`              | `--pageRanges`                  | Paper ranges to print, e.g. `1-5, 8, 11-13`.                                                                                  |                        |\n| ┗ `margin`                   | `object`              | `-m, --margin`                  | Set the PDF margins. e.g. `top=10,bottom=10,left=10,right=10`.                                                                |                        |\n| ┗ `landscape`                | `boolean`             | `-l, --landscape`               | Whether to print in landscape orientation.                                                                                    | `false`                |\n| ┗ `pageSize`                 | `string`              | `-s, --page-size`               | Print to Page Size [size].                                                                                                    | `letter`               |\n| ┗ `width`                    | `string` \\| `number`  | `-w, --width`                   | Print to Page Width [width] in MM.                                                                                            |                        |\n| ┗ `height`                   | `string` \\| `number`  | `-h, --height`                  | Print to Page Height [height] in MM.                                                                                          |                        |\n| ┗ `timeout`                  | `number`              | `-t, --timeout`                 | Set a max timeout of [ms].                                                                                                    |                        |\n| `html`                       | `boolean`             | `-x, --html`                    | Output html file.                                                                                                             |                        |\n| `blockLocal`                 | `boolean`             | `-b, --blockLocal`              | Disallow access to filesystem for local files.                                                                                | `false`                |\n| `blockRemote`                | `boolean`             | `-r, --blockRemote`             | Disallow requests to remote servers.                                                                                          | `false`                |\n| `outlineContainerSelector`   | `string`              | `--outlineContainerSelector`    | Specify an outline container selector.                                                                                        |                        |\n| `allowedPaths`               | `string[]`            | `--allowedPaths`                | Only allow access to given filesystem paths, repeatable.                                                                      | `[]`                   |\n| `ignoreHTTPSErrors`          | `boolean`             | `--ignoreHTTPSErrors`           | Whether to ignore HTTPS errors during navigation.                                                                             | `false`                |\n| `allowedDomains`             | `string[]`            | `--allowedDomains`              | Only allow access to given remote domains, repeatable.                                                                        | `[]`                   |\n| `outlineTags`                | `string[]`            | `--outline-tags`                | Add outlines (bookmarks) to PDF.                                                                                              |[`h1,h2,h3,h4,h5,h6`]   |\n| `additionalScripts`          | `string[]`            | `--additional-scripts`          | additional script tags to the HTML document.                                                                                  | `[]`                   |\n| `additionalStyles`           | `string[]`            | `--additional-styles`           | additional style tags to the HTML document.                                                                                   | `[]`                   |\n| `browserEndpoint`            | `string`              | `--browserEndpoint`             | Use a remote Chrome server with browserWSEndpoint.                                                                            |                        |\n| `browserArgs`                | `string[]`            | `--browserArgs`                 | Launch Chrome with comma separated args.                                                                                      | `[]`                   |\n| `media`                      | `string`              | `--media`                       | Emulate `print` or `screen` media, defaults to print.                                                                         | `print`                |\n| `debug`                      | `boolean`             | `--debug`                       | Debug.                                                                                                                        | `false`                |\n| `warn`                       | `boolean`             | `--warn`                        | Enable warning logs.                                                                                                          | `false`                |\n\n## License\n\nThis library is under the [MIT License](https://github.com/condorheroblog/html-export-pdf-cli/blob/main/LICENSE).\n","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcondorheroblog%2Fhtml-export-pdf-cli","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcondorheroblog%2Fhtml-export-pdf-cli","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcondorheroblog%2Fhtml-export-pdf-cli/lists"}