{"id":18488202,"url":"https://github.com/signcl/docusaurus-prince-pdf","last_synced_at":"2025-04-09T19:17:43.290Z","repository":{"id":36974333,"uuid":"388139335","full_name":"signcl/docusaurus-prince-pdf","owner":"signcl","description":"Docusaurus/Fumadocs/etc PDF generator using Prince XML","archived":false,"fork":false,"pushed_at":"2025-02-06T01:52:15.000Z","size":182,"stargazers_count":161,"open_issues_count":11,"forks_count":24,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-09T19:17:36.354Z","etag":null,"topics":["docusaurus","pdf","prince","princexml"],"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/signcl.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":"2021-07-21T14:14:40.000Z","updated_at":"2025-04-08T17:20:30.000Z","dependencies_parsed_at":"2024-01-10T18:14:34.706Z","dependency_job_id":"77b63449-b16c-476a-abf5-08bc1009bf4e","html_url":"https://github.com/signcl/docusaurus-prince-pdf","commit_stats":{"total_commits":80,"total_committers":2,"mean_commits":40.0,"dds":"0.13749999999999996","last_synced_commit":"94acb83d2439853d1350a181d55244f7fee86920"},"previous_names":["signcl/docusaurs-prince-pdf"],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/signcl%2Fdocusaurus-prince-pdf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/signcl%2Fdocusaurus-prince-pdf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/signcl%2Fdocusaurus-prince-pdf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/signcl%2Fdocusaurus-prince-pdf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/signcl","download_url":"https://codeload.github.com/signcl/docusaurus-prince-pdf/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248094988,"owners_count":21046770,"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":["docusaurus","pdf","prince","princexml"],"created_at":"2024-11-06T12:51:24.274Z","updated_at":"2025-04-09T19:17:43.260Z","avatar_url":"https://github.com/signcl.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# Docusaurus Prince PDF Generator\n\nExtract rendered data from Docusaurus/Fumadocs/etc and generate PDF, the hard way\n\n## Demo/Examples\n\n\u003cimg width=\"1008\" alt=\"Prince PDF for Docusaurus Documentation\" src=\"https://user-images.githubusercontent.com/96356/127639981-68aae100-9b96-4abc-920a-5fd8c6507a0d.png\"\u003e\n\nYou can download it in [GitHub Actions](https://github.com/signcl/docusaurus-prince-pdf/actions/workflows/test.yml) artifacts section to see the result.\n\nThis project is using the method 1 (see below) for generating PDF. You must have [Prince](https://www.princexml.com/) installed on your local machine.\n\n## Usage\n\nInstall [Prince](https://www.princexml.com/download/) first.\n\nRun the following commands to generate PDF:\n\n```bash\n# Genrate PDF from specific site under `docs` scope\nnpx docusaurus-prince-pdf -u https://docusaurus.io/docs\n\n# Change generating scope to `/docs/cli/`\nnpx docusaurus-prince-pdf -u https://docusaurus.io/docs/cli\n\n# Custom working (output) directory\nnpx docusaurus-prince-pdf -u https://openbayes.com/docs --dest ./pdf-output\n\n# Custom output file name\nnpx docusaurus-prince-pdf -u https://openbayes.com/docs --output docs.pdf\n```\n\nTo generate PDF from a local Docusaurus instance. You need to first build the site locally:\n\n```bash\n# Build the site\n(npm|bun|yarn|pnpm) build\n\n# Serve built site locally\n(npm|bun|yarn|pnpm) serve\n\n# Generate PDF from local Docusaurus instance\nnpx docusaurus-prince-pdf -u http://localhost:4000/docs # Change port to your serving port\n```\n\n## Docker\n\n- [Docker Hub](https://hub.docker.com/r/openbayes/docusaurus-prince-pdf)\n- [ghcr.io](https://github.com/orgs/signcl/packages/container/package/docusaurus-prince-pdf)\n\nYou can run this program with Docker image:\n\n```bash\ndocker run --rm -it --init \\\n  -v $(pwd)/pdf:/app/pdf \\\n  openbayes/docusaurus-prince-pdf \\\n  -u https://docusaurus.io/docs/\n```\n\nIf you need Asiatic languages support like Chinese and Japanese. You can mount your custom fonts directory to Docker image:\n\n```bash\ndocker run --rm -it --init \\\n  -v $(pwd)/pdf:/app/pdf \\\n  -v $(pwd)/fonts:/root/.fonts \\\n  openbayes/docusaurus-prince-pdf \\\n  -u https://docusaurus.io/docs/\n```\n\n## GitHub Actions\n\nYou can also run this program inside GitHub Actions:\n\n```yaml\njobs:\n  build:\n    # prerequisites...\n\n    - name: Install Prince\n      run: |\n        curl https://www.princexml.com/download/prince-14.2-linux-generic-x86_64.tar.gz -O\n        tar zxf prince-14.2-linux-generic-x86_64.tar.gz\n        cd prince-14.2-linux-generic-x86_64\n        yes \"\" | sudo ./install.sh\n\n    - name: Build PDF\n      run: npx docusaurus-prince-pdf -u https://docusaurus.io/docs/\n\n    - name: Upload results\n      uses: actions/upload-artifact@v3\n      with:\n        name: result\n        # The output filename can be specified with --output option\n        path: pdf/docusaurus.io-docs.pdf\n        if-no-files-found: error\n\n    # ...other steps\n```\n\nYou can also run `prince` with prebuilt Prince Docker image:\n\n```yaml\njobs:\n  build:\n    # prerequisites...\n\n    - name: Build PDF\n      run: docker run --rm -it -v $(pwd)/pdf:/app/pdf openbayes/docusaurus-prince-pdf -u https://docusaurus.io/docs/\n\n    # ...other steps\n```\n\n## Development\n\nYou need to have [Bun](https://bun.sh/) installed first. This can also let you run latest code on your local machine.\n\n```bash\nbun run index.ts -u http://localhost:4000/docs\n```\n\n## Options\n\n- `--url` (`-u`): Base URL, should be the `baseUrl` of the Docusaurus instance (e.g. https://docusaurus.io/docs/)\n- `--selector` (`-s`): CSS selector to find the link of the next page\n- `--dest` (`-d`): Working directory. Default to `./pdf`\n- `--file` (`-f`): Change default list output filename\n- `--output` (`-o`): Change PDF output filename\n- `--include-index`: Include passed URL in generated PDF\n- `--prepend`: Prepend additional pages, split with comma\n- `--append`: Append additional pages, split with comma\n- `--prince-args`: Additional options for Prince. ie. `--prince-args=\"--page-size='210mm 297mm'\"` or `--prince-args \"\\\\-\\\\-page\\\\-size='210mm 297mm'\"`\n- `--prince-docker`: Use external Prince docker image to generate PDF. See https://github.com/sparanoid/docker-prince for more info\n- `--list-only`: Fetch list without generating PDF\n- `--pdf-only`: Generate PDF without fetching list. Ensure list exists\n- `--cookie`: Specify the cookie with the domain part, e.g. `--cookie=\"token=123456; domain=example.com;\"`\n\n## How it works\n\nLike [mr-pdf](https://github.com/kohheepeace/mr-pdf), this package looks for the next pagination links on generated Docusaurus site. Collect them in a list and then pass the list to Prince to generate the PDF.\n\nYou can specify the CSS selector if you're using custom Docusaurus theme:\n\n```bash\nnpx docusaurus-prince-pdf -u https://openbayes.com/ --selector 'nav.custom-pagination-item--next \u003e a'\n```\n\n## Does it work with Fumadocs or other static site/docs generators?\n\nIt should work with any static site/docs generators that have consistent pagination links.\n\nFor Fumadocs, you can use the same method to generate the PDF using custom selector like this:\n\n```bash\nnpx docusaurus-prince-pdf -u https://fumadocs.vercel.app/docs/ui --selector '#nd-page \u003e article \u003e div.grid.grid-cols-2.gap-4.pb-6 a:last-child'\n```\n\nThe Tailwind-styled selector is not elegant but it works.\n\n## Why this package?\n\nI made a comparison list for the two methods of generating PDF from Docusaurus.\n\n### Method 1: Prince\n\nThe good:\n\n- Best font subsetting support\n- Text can be selected and copy/paste correctly\n- Fancy Table of Contents\n\nThe bad:\n\n- Watermark on first page of generated PDF make it hard to handle in CI/CD environments\n- Doesn't work with some CSS syntax (e.g. `mask-image`)\n- Doesn't work with some HTML features (e.g. `srcset`)\n- Commercial license is expensive ([$3,800](https://www.princexml.com/purchase/))\n\nThe ugly:\n\n- None\n\n### Method 2: [mr-pdf](https://github.com/kohheepeace/mr-pdf) (not used in this project)\n\nThe good:\n\n- Free and open-source\n- Works with Docusaurus sites\n- CI/CD friendly\n- Based on Puppeteer make it works for most modern CSS syntax (e.g. `mask-image`)\n\nThe bad:\n\n- Doesn't work well with system Dark Mode. You will get a dark background in generated PDF when you have `respectPrefersColorScheme` enabled in your Docusaurus instance. But it's not an issue in Ci/CD environments\n- No Table of Contents\n\nThe ugly:\n\n- Based on Puppeteer make the text cannot be copied or searched correctly\n- Link anchors (links start with `#`) not well handled\n\nUsage:\n\n```bash\nnpx mr-pdf --initialDocURLs=\"https://openbayes.com/docs/\" --paginationSelector=\".pagination-nav__item--next \u003e a\" --contentSelector=\"article\"\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsigncl%2Fdocusaurus-prince-pdf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsigncl%2Fdocusaurus-prince-pdf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsigncl%2Fdocusaurus-prince-pdf/lists"}