markdown2pdf
markdown2pdf is a versatile command-line tool and library designed to convert Markdown content into pre-styled PDF documents. It supports reading Markdown from a file or directly from a string, offering flexibility for both users and developers.
This project includes both a binary and a library:
- Binary (cli): A command-line interface that uses the core library to provide an easy way to convert Markdown to PDF.
- Library (lib): Can be integrated into your Rust projects for parsing Markdown or generating PDF documents programmatically.
Note: This project is currently under active development, with ongoing improvements and new features being added.
Installation
Currently, there isn't a simplified official method to install the command-line tool across platforms. To use it, you can clone the repository and build the project yourself using Cargo:
Configuration
The markdown2pdf tool supports customization through a TOML configuration file. You can configure various styling options for the generated PDFs by creating a markdown2pdfrc.toml file in your home directory. To get started with configuration:
-
Create the config file:
-
Copy the example configuration:
- View the example config at markdown2pdfrc.example.toml
- Copy the contents to your
~/markdown2pdfrc.tomlfile - Modify the values according to your preferences
The configuration file allows you to customize the appearance of your generated PDFs by defining styling options for different Markdown elements.
Usage
To use the markdown2pdf tool, you can either specify a Markdown file path, provide Markdown content directly, or set the output PDF path.
Options
-p,--path: Specify the path to the Markdown file to convert.-s,--string: Provide Markdown content directly as a string.-o,--output: Specify the output file path for the generated PDF.
Examples
-
Convert a Markdown file to a PDF:
This will convert the
resume.mdfile located in thedocsfolder to a PDF file namedresume.pdf. -
Convert Markdown content provided as a string:
This will convert the provided Markdown string to a PDF file named
output.pdf. -
Convert a Markdown file to a PDF with default output:
This will convert the
file.mdto a PDF and save it asoutput.pdf.
Notes
- If both
-pand-soptions are provided, the--pathoption will take precedence. - If no output file is specified using the
-ooption, the default output file will be namedoutput.pdf.