Coder Social home page Coder Social logo

ayalamac / percollate Goto Github PK

View Code? Open in Web Editor NEW

This project forked from danburzo/percollate

0.0 2.0 0.0 182 KB

🌐 β†’ πŸ“– A command-line tool to grab web pages as beautifully formatted PDFs

License: MIT License

JavaScript 66.21% CSS 24.56% HTML 9.23%

percollate's Introduction

percollate

Percollate is a command-line tool to turn web pages as beautifully formatted PDFs.

Installation

You can install percollate globally:

# using npm
npm install -g percollate

# using yarn
yarn global add percollate

To keep the package up-to-date, you can run:

# using npm, upgrading is the same command as installing
npm install -g percollate

# yarn has a separate command
yarn global upgrade --latest percollate

Usage

πŸ’‘ Run percollate --help for a list of available commands. For a particular command, percollate <command> --help lists all available options.

Available commands

Command What it does
percollate pdf Bundles one or more web pages into a PDF
percollate epub Not implemented yet
percollate html Not implemented yet

Available options

The pdf, epub, and html commands have these options:

Option What it does
-o, --output (Required) The path of the resulting bundle
--template Path to a custom HTML template
--style Path to a custom CSS

Examples

Generating a PDF

To transform a single web page to PDF:

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

To bundle several web pages into a single PDF, specify them as separate arguments to the command:

percollate pdf --output some.pdf https://example.com/page1 https://example.com/page2

You can use common Unix commands and keep the list of URLs in a newline-delimited text file:

cat urls.txt | xargs percollate pdf --output some.pdf

Using a custom HTML template

⚠️ TODO add example here

Using a custom CSS stylesheet

⚠️ TODO add example here

Customizing the page header / footer

⚠️ TODO add example here

How it works

  1. Fetch the page(s) using got
  2. Enhance the DOM using jsdom
  3. Pass the DOM through mozilla/readability to strip unnecessary elements
  4. Apply the HTML template and the print stylesheet to the resulting HTML
  5. Use puppeteer to generate a PDF from the page

Troubleshooting

On some Linux machines you'll need to install a few more Chrome dependencies before percollate works correctly. (Thanks to @ptica for sorting it out)

See also

Here are some other projects to check out if you're interested in building books using the browser:

percollate's People

Contributors

danburzo avatar juhq avatar

Watchers

James Cloos avatar AndrΓ©s Ayala avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.