Code Monkey home page Code Monkey logo

files2pdf's Introduction

Directory to PDF Converter ๐Ÿ“ โžก๏ธ ๐Ÿ“„

This Python script traverses a directory and converts all the text files found into a PDF.

๐Ÿ’ผ Usage

python files2pdf.py <dir_path> <pdf_path>

Here,

  • dir_path: Directory path to traverse. The script will look for text files in this directory and its subdirectories.
  • pdf_path: The output PDF file name.

๐Ÿ“œ Description

The script performs the following tasks:

  • Traverse the directory and its subdirectories using os.walk
  • For each file found, the text is extracted and written into a PDF. The file path is used as a title for each page in the PDF.
  • The '.git' directories are excluded from traversal.

๐Ÿงฉ Features

  1. Skip .git directories during directory traversal.
  2. Dynamic font setting for title and file content.

๐Ÿ“š Dependencies

You'll need the following python libraries:

  • os
  • argparse
  • fpdf

You can install the fpdf library using pip:

pip install fpdf

โš™๏ธ How it Works

The script's main function main() takes two arguments from the command line: dir_path and pdf_path. It passes these arguments to the create_pdf() function which creates a FPDF object, traverses the directory by calling traverse_directory(), and saves the created PDF.

The traverse_directory() function recursively walks through the directory and its subdirectories. For each file it finds, it reads the file content with extract_text(), adds a new page to the PDF, sets the title as the file's path, and writes the file content to the PDF.

๐Ÿš€ Getting Started

Clone this repository, install the required python libraries and you're good to go! ๐Ÿ˜ƒ

git clone <repo_url>
cd <repo_folder>
pip install fpdf
python script.py <dir_path> <pdf_path>

๐Ÿž Bug Reports & Feature Requests

Feel free to open an issue if you've found a bug or have a feature request.

๐Ÿ’– Contributions

All contributions are welcome! Please feel free to make a pull request.

โš–๏ธ License

This project is licensed under the MIT License.

files2pdf's People

Contributors

sanlega 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.