Skip to content

soumildatta/MD2PDF

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MD2PDF

MD2PDF is a CLI Tool created with Python 3 that allows you to convert your markdown documents into pdfs. There are several ways you can do this -- convert a markdown file into a pdf, convert a folder of markdown files into a folder of pdf files, and convert a folder of markdown files into one combined pdf file. This project was created after my personal need of a lightweight markdown folder converter. MD2PDF currently only works with Unix style systems, but will be extended to Windows shortly.

Requirements

To run this script on your machine, you will need the following:

  • Python 3
  • Python Libraries: markdown, pdfkit, argparse, os, re
  • Other: wkhtmltopdf

Installing the required Python libraries

The python libraries can be installed easily thanks to the requirements.txt file. You can install these packages by being in this project directory and running the following command:

pip install -r requirements.txt

Installing wkhtmltopdf

You'll need to install wkhtmltopdf for this project to run:

For Ubuntu/Linux, install with apt:

sudo apt-get install wkhtmltopdf

For macOS, install with Homebrew:

brew install wkhtmltopdf

You can also download it from wkhtmltopdf.org and follow installation instructions.

Using MD2PDF

Run the python code using

python md2pdf.py

The program will prompt you for the following:

  1. Input: The input for this program are file/folder paths. You can specify a path to a Markdown file (.md), or a folder consisting .md files
  2. Output: The output for this program are .pdf file paths/folder paths. You can specify a path to a .pdf file, or a folder that will contain the .pdf files. The folder does not need to already exist as the program can create a new folder for you.
  3. CSS file: You can specify the path to a .css file for styling your Markdown file

There are different outcomes of specifying files and folders as input and output:

  1. If you specify an .md file as input and specify a .pdf file as output, then the .md file is converted into a .pdf file.
  2. If you specify a folder as input and specify a folder as output , then the .md files in the input folder are converted to .pdf files in the output folder
  3. If you specify a folder as input and specify a .pdf file as output, then the .md files in the input folder are combined into a single .pdf file.

MD2PDF also supports inline HTML, so utilizing different div tags with different classes could allow even more customization through CSS.

sample.css includes a few custom div classes that simplify this process to get you started. Since one of the main feature requests has been to be able to align text, this can be easily achieved by inline HTML on your markdown file as such:

<div class="align-edges">
    <div class="left">
        Left text here
    </div>
    <div class="right">
        Right text here
    </div>
</div>

Styling PDFs with CSS

The resulting PDFs can be styled with CSS. Fonts, colors, sizes, stroke, etc. of each element in your generated PDF can all be customized as per your liking. A sample CSS file named sample.css has been included in the project and demonstrates the usage of CSS styling rules to determine the styling of the output PDFs.

Future Updates

There are a few future updates planned that can improve upon this tool:

  • Syntax coloring in code blocks
  • Ignore non .md files inside a folder and process only the .md files
  • MD2PDF will be available through HomeBrew soon

Feel free to suggest new features or bugs by opening an issue. This project is open to contributions! :) Contributions are open to help with the future updates, as well as adding useful templates such as resumes and CVs that can be used by others (make sure to remove any identifying information).

About

A CLI tool to convert Markdown (.md) files to PDFs

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published