Giter Site home page Giter Site logo

imbernoulli / pdf-color-inverter Goto Github PK

View Code? Open in Web Editor NEW
4.0 1.0 0.0 2 KB

PDF Color Inverter is a simple yet powerful tool that helps to convert PDF files with dark backgrounds to a lighter scheme (also can from light to dark, it is decided by the file's original scheme).

Python 100.00%
pdf

pdf-color-inverter's Introduction

PDF Color Inverter

PDF Color Inverter is a simple yet powerful tool that helps to convert PDF files with dark backgrounds to a lighter scheme (also can from light to dark, it is decided by the file's original scheme), making them more suitable for printing. It utilizes PyMuPDF, PIL, and FPDF libraries to process PDFs and invert the colors for an optimized print-friendly version.

Steps

  • Convert PDF pages to images
  • Invert colors of each image
  • Reassemble images back into a single PDF

Installation

To use PDF Color Inverter, you need to have Python installed on your machine along with the following dependencies:

  • PyMuPDF
  • Pillow
  • FPDF

You can install these packages using pip:

pip install PyMuPDF Pillow fpdf

Usage

Using PDF Color Inverter is simple. Import the main function from the script and provide it with the input and output PDF paths:

from pdf_color_inverter import main

input_pdf_path = 'path_to_your_input.pdf'
output_pdf_path = 'path_to_your_output.pdf'
main(input_pdf_path, output_pdf_path)

Or you can just modify the paths in pdf_color_inverter and run it.

You can adjust dpi in pdf_to_images(pdf_path, dpi=300) and quality in img.save(temp_img_file.name, format='JPEG', quality=95) to adjust the quality of the output. Output with better quality will take longer to process.

How It Works

  1. Converting PDF to Images: The pdf_to_images function opens a PDF and converts each page into an image at a specified DPI.
  2. Inverting Image Colors: The invert_colors function takes the list of images and inverts their colors to a negative.
  3. Saving Images to PDF: The save_images_to_pdf function takes the inverted images and saves them back into a single PDF document.

pdf-color-inverter's People

Contributors

imbernoulli avatar

Stargazers

Siddhant Laddha avatar Yifei avatar 朱子晗 avatar  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.