{"_id":"@_codehead/vitepress-export-pdf","name":"@_codehead/vitepress-export-pdf","dist-tags":{"latest":"1.0.1-beta.1"},"versions":{"1.0.1-beta.1":{"name":"@_codehead/vitepress-export-pdf","type":"module","version":"1.0.1-beta.1","packageManager":"pnpm@9.1.0","description":"VitePress export PDF","author":{"name":"CondorHero"},"license":"MIT","homepage":"https://github.com/condorheroblog/vitepress-export-pdf#readme","repository":{"type":"git","url":"git+https://github.com/condorheroblog/vitepress-export-pdf.git"},"bugs":{"url":"https://github.com/condorheroblog/vitepress-export-pdf/issues"},"keywords":["vitepress-plugin-export-pdf","vitepress-export-pdf","vitepress-pdf","vitepress"],"exports":{".":{"import":"./dist/index.mjs","require":"./dist/index.cjs"}},"main":"dist/index.cjs","module":"dist/index.mjs","types":"dist/index.d.ts","typesVersions":{"*":{"*":["./dist/*","./dist/index.d.ts"]}},"bin":{"press-export-pdf":"bin/press-export-pdf.mjs"},"engines":{"node":">=18"},"scripts":{"release":"bumpp -r && pnpm -r publish","dev":"esno ./src/commands/press-export-pdf.ts export ./example/vitepress-docs","coverage":"vitest run --coverage","lint:fix":"eslint . --fix","lint":"eslint .","test":"vitest","build":"unbuild"},"workspaces":["examples/*"],"publishConfig":{"access":"public","registry":"https://registry.npmjs.org"},"peerDependencies":{"vitepress":">=1.0.0-alpha.35"},"dependencies":{"@condorhero/vuepress-plugin-export-pdf-core":"^3.0.3","debug":"^4.3.4","hash-sum":"^2.0.0"},"devDependencies":{"@antfu/eslint-config":"^2.17.0","@types/debug":"^4.1.12","@types/hash-sum":"^1.0.2","bumpp":"^9.4.1","eslint":"^9.2.0","esno":"^4.7.0","fast-glob":"^3.3.2","husky":"^9.0.11","lint-staged":"^15.2.2","typescript":"^5.4.5","unbuild":"^2.0.0","vitepress":"^1.1.4","vitest":"^1.6.0"},"_id":"@_codehead/vitepress-export-pdf@1.0.1-beta.1","gitHead":"0d26f8399d7e3f3881b16497d59c2fddc16647c2","_nodeVersion":"20.14.0","_npmVersion":"10.7.0","dist":{"integrity":"sha512-pprN4Zgd1j1pffeTZyNMJzbDudJcBS8CRo3PaqgZcmpepTXYMi1sh9qzRs0NkQqzI9TJGzj7Gb6BP8N7k4NPaw==","shasum":"eb89c86e9d5f30563b0427404c2a5e2423c8de75","tarball":"https://registry.npmjs.org/@_codehead/vitepress-export-pdf/-/vitepress-export-pdf-1.0.1-beta.1.tgz","fileCount":16,"unpackedSize":24814,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC0ONsKTUiLFkK8/+7tXF9TYMSHbzQ8FNmmk/1ZN+XW1gIhAIk5wIJUpdnxhD3axkrmlUF2A2305tLhaeQMR2hgMfHb"}]},"_npmUser":{"name":"_codehead","email":"codehead@gmail.com"},"directories":{},"maintainers":[{"name":"_codehead","email":"codehead@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/vitepress-export-pdf_1.0.1-beta.1_1728407200466_0.5965834768856901"},"_hasShrinkwrap":false}},"time":{"created":"2024-10-08T17:06:40.345Z","1.0.1-beta.1":"2024-10-08T17:06:40.658Z","modified":"2024-10-08T17:06:40.945Z"},"maintainers":[{"name":"_codehead","email":"codehead@gmail.com"}],"description":"VitePress export PDF","homepage":"https://github.com/condorheroblog/vitepress-export-pdf#readme","keywords":["vitepress-plugin-export-pdf","vitepress-export-pdf","vitepress-pdf","vitepress"],"repository":{"type":"git","url":"git+https://github.com/condorheroblog/vitepress-export-pdf.git"},"author":{"name":"CondorHero"},"bugs":{"url":"https://github.com/condorheroblog/vitepress-export-pdf/issues"},"license":"MIT","readme":"# vitepress-export-pdf\n\n<p align=\"left\">\n  <a href=\"https://www.npmjs.com/package/vitepress-export-pdf\" target=\"__blank\">\n    <img src=\"https://img.shields.io/npm/v/vitepress-export-pdf.svg?color=a1b858\" alt=\"NPM version\">\n  </a>\n  <a href=\"https://www.npmjs.com/package/vitepress-export-pdf\" target=\"__blank\">\n    <img alt=\"NPM Downloads\" src=\"https://img.shields.io/npm/dm/vitepress-export-pdf.svg?color=50a36f\">\n  </a>\n  <a href=\"https://github.com/condorheroblog/vitepress-export-pdf\" target=\"__blank\">\n    <img alt=\"GitHub stars\" src=\"https://img.shields.io/github/stars/condorheroblog/vitepress-export-pdf?style=social\">\n  </a>\n</p>\n\n`vitepress-export-pdf` allows you to export your sites to a PDF file.\n\n## Related\n\n- [@condorhero/vuepress-plugin-export-pdf-v1](https://github.com/condorheroblog/vuepress-plugin-export-pdf/blob/main/packages/vuepress-plugin-export-pdf-v1/README.md)\n- [@condorhero/vuepress-plugin-export-pdf-v2](https://github.com/condorheroblog/vuepress-plugin-export-pdf/blob/main/packages/vuepress-plugin-export-pdf-v2/README.md)\n\n## Installation\n\n```sh\nnpm install vitepress-export-pdf -D\n```\n\nthen add script to your `package.json`:\n\n```json\n{\n  \"scripts\": {\n    \"export-pdf\": \"press-export-pdf export [path/to/your/docs]\"\n  }\n}\n```\n\nThen run:\n\n```sh\nnpm run export-pdf\n```\n\n## `press-export-pdf` Command Options\n\nThe package provides the `press-export-pdf` command with the following command line options:\n\n![vitepress-export-pdf.png](https://github.com/condorheroblog/vitepress-export-pdf/raw/main/assets/vitepress-export-pdf.svg)\n\n- `export [sourceDir]`: Export your site to a PDF file\n  - `-c, --config <config>`: Set path to config file\n  - `--outFile <outFile>`: Name of output file\n  - `--outDir <outDir>`: Directory of output files\n  - `--pdfOutlines <pdfOutlines>`: Keep PDF outlines/bookmarks([**Node >= 18.5.0**](https://github.com/condorheroblog/vitepress-export-pdf/tree/v1.0.0-alpha.3#qa))\n  - `--urlOrigin <urlOrigin>`: Change the origin of the print url(Option `displayHeaderFooter` of `pdfOptions` is true)\n  - `--debug`: Enable debug mode\n- `info`: Display environment information\n- `--help`: Display help information\n- `--version`: Display version information\n\n## Config File Options\n\nYou can create a new config file, we support the following files:\n\n- `vitepress-pdf.config.ts`\n- `vitepress-pdf.config.js`\n- `vitepress-pdf.config.cjs`\n- `vitepress-pdf.config.mjs`\n- `.vitepress/vitepress-pdf.config.ts`\n- `.vitepress/vitepress-pdf.config.js`\n- `.vitepress/vitepress-pdf.config.cjs`\n- `.vitepress/vitepress-pdf.config.mjs`\n\nIn addition, you can also customize the configuration file through `--config` or `-c`.\n\nIt is recommended to use TS(`.vitepress/vitepress-pdf.config.ts`) files, which are easy to manage and have **friendly code prompts**.\n\nex:\n\n```ts\n// .vitepress/vitepress-pdf.config.ts\nimport { defineUserConfig } from 'vitepress-export-pdf'\n\nexport default defineUserConfig({\n  // ...\n})\n```\n\nif you want to use JS files, **you can leverage your IDE's intellisense with jsdoc type hints**:\n\n```js\n/**\n * @type {import('vitepress-export-pdf').UserConfig}\n */\nconst config = {\n  // ...\n}\n\nexport default config\n```\n\nconfig options:\n\n- `sorter` - function for changing pages order (default `undefined`)\n- `outFile` - name of output file (default `vitepress-YYMMDD-HHmmss.pdf`)\n- `outDir` - Directory of output files (default `package.json` file exists in directory)\n- `routePatterns` - Specify the patterns of files you want to be exported. The patterns are relative to the source directory (default `[\"/**\", \"!/404.html\"]`).Patterns to match Route path using [multimatch](https://github.com/sindresorhus/multimatch)\n- `puppeteerLaunchOptions` - [Puppeteer launch options object](https://github.com/puppeteer/puppeteer/blob/main/docs/api/puppeteer.puppeteerlaunchoptions.md)\n- `pdfOptions` - [Valid options to configure PDF generation via Page.pdf()](https://github.com/puppeteer/puppeteer/blob/main/docs/api/puppeteer.pdfoptions.md) (default `{ format: 'A4 }`), **`pageNumber` and `totalPages` of `headerTemplate` and `footerTemplate` cannot be used because of [this reason](https://github.com/condorheroblog/vitepress-export-pdf/issues/5)**\n- `pdfOutlines` - Keep PDF outlines/bookmarks(default `true`)\n- `urlOrigin`: Change the origin of the print url(Option `displayHeaderFooter` of `pdfOptions` is true) - ([How do I change the URL point to the localhost](https://github.com/condorheroblog/vuepress-plugin-export-pdf/issues/5))\n- `outlineContainerSelector`: Specify an outline container selector.\n\n## Examples\n\nA usable example of quick start [click here](https://github.com/condorheroblog/vitepress-export-pdf/blob/main/examples/vitepress-docs).\n\nRefer to [this example](https://github.com/condorheroblog/vitepress-export-pdf/blob/main/examples/vitepress-docs) for more information，there is a very useful configuration file [vitepress-pdf.config.ts](https://github.com/condorheroblog/vitepress-export-pdf/blob/main/examples/vitepress-docs/docs/.vitepress/vitepress-pdf.config.ts)\n\n### Order of PDF\n\n`console.log` all the routes in the sort function and assign them to the variable `routeOrder` as a value. You can adjust the order of printing in the array `routeOrder`.\n\n```ts\nimport { defineUserConfig } from 'vitepress-export-pdf'\n\nconst routeOrder = [\n  '/index.html',\n  '/guide/what-is-vitepress.html',\n  '/guide/getting-started.html',\n  '/guide/configuration.html',\n  // ...\n]\n\nexport default defineUserConfig({\n  sorter: (pageA, pageB) => {\n    const aIndex = routeOrder.findIndex(route => route === pageA.path)\n    const bIndex = routeOrder.findIndex(route => route === pageB.path)\n    return aIndex - bIndex\n  },\n})\n```\n\nIn order to avoid maintaining two routes, you can read the link fields specified by `Nav` and `Sidebar` in the vitepress configuration file by coding, and then sort them. The outline of the code is as follows:\n\n```ts\nimport vitepressConfig from './config'\n\nfunction extractLinksFromConfig(config: DefaultTheme.Config) {\n  const links: string[] = []\n  // Some code logic\n  return links\n}\n\nconst links = extractLinksFromConfig(vitepressConfig.themeConfig!)\nconst routeOrder = [\n  '/index.html',\n  ...links,\n]\n```\n\n[The full code is here](https://github.com/condorheroblog/vitepress-export-pdf/blob/main/examples/vitepress-docs/docs/.vitepress/vitepress-pdf.config.ts)\n\n### Don't export homepage\n\n`.vitepress/vitepress-pdf.config.ts` add `routePatterns`:\n\n```ts\nimport { defineUserConfig } from 'vitepress-export-pdf'\n\nexport default defineUserConfig({\n  routePatterns: ['!/'],\n})\n```\n\n> Note: `!` at the beginning of a pattern will negate the match\n\n### PDF print style\n\nUnlike VuePress, VitePress has no customization [global style](https://v2.vuepress.vuejs.org/reference/default-theme/styles.html)(ex VuePress2.x `.vuepress/styles/index.scss`) function, but we can customize themes to achieve this.\n\ncreate the `.vitepress/theme/index.ts` or `.vitepress/theme/index.js` file (the \"theme entry file\").\n\n```ts\n// .vitepress/theme/index.ts\nimport DefaultTheme from 'vitepress/theme'\n\n// custom CSS\nimport './style/print.css'\n\nexport default {\n  // Extending the Default Theme\n  ...DefaultTheme,\n}\n```\n\ncreate `/style/print.css`:\n\n```css\n@media print {\n  .VPNav,\n  .VPLocalNav,\n  .VPDocFooter {\n    display: none !important;\n  }\n}\n```\n\n![compare-print-style.png](https://github.com/condorheroblog/vitepress-export-pdf/blob/main/assets/compare-print-style.png)\n\n## Contributing\n\n1. Fork it!\n2. Create your feature branch: git checkout -b my-new-feature\n3. Commit your changes: git commit -am 'Add some feature'\n4. Push to the branch: git push origin my-new-feature\n5. Submit a pull request :D\n\n## Report Bug\n\nrun `press-export-pdf info` Shows debugging information about the local environment.\n\n## License\n\n[MIT](https://github.com/condorheroblog/vitepress-export-pdf/blob/main/LICENSE)\n","readmeFilename":"README.md"}