Coder Social home page Coder Social logo

url_to_pdf's Introduction

This script will download the given urls as pdf files, using Microsoft Playwright (Chromium).

Installation

The script has a dependency on Playwright and BeautifulSoup4, which can be installed using pip:

pip install playwright
playwright install
pip install beautifulsoup4

Usage

NOTE: You might have to add https:// to the start of the urls!

To download pages directly, run the script with urls as the arguments:

python url_to_pdf.py <url> <url> <url>...

Downloading from urls in a file

To download pages from a file, run the script with the file as the argument:

python url_to_pdf.py -f <file>

The file should contain one url per line.

Downloading multiple files using numeric names

Maybe you want to download a bunch of pages as pdfs, and then combine them into a single large pdf file (see tips for suggestions on how to combine them), so you can read a bunch of articles while you're stuck on a plane without internet.

You can use the -n flag to specify that the script should save the urls using sequential numbers as the names. Ex. 0001.pdf, 0002.pdf, 0003.pdf etc.

python url_to_pdf.py -n <url> <url> <url>...

Or

python url_to_pdf.py -n -f <file>

Known issues

There's a bug where Playwright will get stuck on browser.new_page() if you have DISPLAY environment variable set with no X Server running. Clear the DISPLAY environment variable to fix this.

Tips

If you download multiple PDF-files, and want to combine them into one, you can use the poppler-utils package, which contains the pdfunite tool:

pdfunite *.pdf output.pdf

Or if you're on macOS, you can use the built-in sips tool. Though my understanding is that sips is not specifically designed for combining PDFs, so there may be some limitations or issues with certain PDF files.

sips -s format pdf *.pdf --out combined.pdf

url_to_pdf's People

Contributors

isalin avatar

Watchers

 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.