percollate

repository·main·Indexed 26 days ago

https://github.com/danburzo/percollate

A Node.js command-line tool (version 4.3.0) used to transform web pages, local files, or Atom/RSS feeds into high-quality PDF, EPUB, HTML, or Markdown files. It supports bundling multiple sources into a single document with a table of contents and cover, or exporting them as individual files. Users can customize output via HTML templates, CSS stylesheets, and specific options for hyphenation, inline images, and PDF rendering using Chrome or Firefox.

Tokens
3.6K
Snippets
15
Records
29
Agent score
88%

What's inside percollate

  1. Create EPUB books from Atom or RSS feeds

    main

    Percollate supports XML web feeds (Atom/RSS). Each entry in the feed is treated as an individual article. By default, content is read directly from the feed file.

    percollate epub https://example.com/posts.xml
  2. Control processing flow and bundling

    main

    Sequential processing

    By default, Percollate processes URLs in parallel. To process them sequentially with a delay (in seconds), use --wait.

    percollate epub --wait=1 url1 url2 url3

    Individual files vs Bundles

    By default, Percollate bundles all provided pages into a single file. To export each source to its own separate file, use the --individual flag.

    percollate pdf --individual http://example.com/page1 http://example.com/page2
  3. Install Percollate

    main

    Percollate is a Node.js command-line tool. You can install it globally via npm. Note that Percollate and its dependencies require Node.js 14.17.0 or later.

    To install via npm:

    npm install -g percollate

    On Arch Linux, you can install the community-maintained package using an AUR helper like yay:

    yay -S nodejs-percollate
  4. Configure PDF page size and margins via `--css`

    main

    Use the --css option to pass CSS snippets that override default page settings like size, orientation, and margins using the @page rule.

    percollate pdf --css "@page { size: A3 landscape }" http://example.com
  5. Use Firefox to render PDFs

    main

    To use Firefox Nightly instead of Chrome for PDF rendering, install percollate with the PUPPETEER_PRODUCT environment variable set to firefox, then use the --browser=firefox flag during execution.

    Limitation: Firefox rendering currently does not support headers or footers (no page numbers).

  6. Configure output and source URL

    main

    Specify output path

    Use -o, --output to define the resulting file path relative to the current directory.

    percollate pdf https://example.com -o my-example.pdf

    Provide source URL for stdin

    When piping content via stdin (using -), Percollate cannot determine the original URL, which causes relative paths (images, anchors) to fail. Use --url to provide the source URL.

    curl https://example.com | percollate pdf - --url=https://example.com
  7. Override PDF font stacks using `--css`

    main

    Percollate uses CSS variables for its font stacks. You can override these using the --css option. Note: Fonts must be installed on your local machine.

    percollate pdf --css ":root { --main-font: 'PT Serif';  --alt-font: Roboto; }" http://example.com
  8. Use Percollate to convert web pages

    main

    Percollate converts URLs or local file paths into PDF, EPUB, HTML, or Markdown files. The general syntax is:

    percollate <command> [options] url [url]...

    Available commands:

    • percollate pdf: Produces a PDF file.
    • percollate epub: Produces an EPUB file.
    • percollate html: Produces an HTML file.
    • percollate md: Produces a Markdown file.

    Operands can be URLs, paths to local files, or - to read from stdin.

    percollate pdf https://example.com
  9. Customize PDF headers and footers with `--template`

    main

    To customize headers and footers, use the --template option with an HTML file containing <template> elements with classes header-template and footer-template.

    Available Puppeteer injection tokens:

    • date: formatted print date
    • title: document title
    • url: document location (path of the temporary HTML)
    • pageNumber: current page number
    • totalPages: total pages

    Note: Header/footer templates do not inherit styles from the main page cascade; you must define full CSS for them.

    <template class="header-template"> My header </template>
    
    <template class="footer-template">
    	<div class="text center">
    		<span class="pageNumber"></span>
    	</div>
    </template>
  10. Use the percollate CLI to bundle web pages

    main

    percollate is a command-line tool used to bundle web pages into various formats. You must specify a command followed by optional flags and one or more URLs. To read HTML from stdin, use the hyphen (-) as an operand.

    Commands

    • pdf: Bundle web pages as a PDF file.
    • epub: Bundle web pages as an EPUB file.
    • html: Bundle web pages as a HTML file.
    • md: Bundle web pages as a Markdown file.

    Basic Usage

    Single web page to PDF:

    percollate pdf --output my.pdf https://example.com

    Single web page read from stdin to PDF:

    curl https://example.com | percollate pdf -o my.pdf -u https://example.com -

    Several web pages to a single PDF:

    percollate pdf --output my.pdf https://example.com/1 https://example.com/2
    percollate <command> [options] url [url]...
  11. Process HTML from stdin

    main

    You can pipe HTML content into percollate using - as an operand. When doing this, use the --url option to provide the source URL so that relative links and images resolve correctly.

    curl https://example.com/page1 | percollate pdf --url=https://example.com/page1 -