Initially forked from https://github.com/jmaupetit/md2pdf
Available through pip:
$ pip install txt2pdfUsage:
txt2pdf [options] INPUT.MD OUTPUT.PDF
Options:
--css=STYLE.CSS
For example, try to generate the project documentation with:
$ txt2pdf README.md README.pdfOptionally, you may load an external style (restricted to CSS2):
$ txt2pdf --css tests/resources/input.css README.md README.pdfYou may also include a HTML header and footer :
$ txt2pdf --header tests/resources/header.html README.md README.pdf
$ txt2pdf --footer tests/resources/footer.html README.md README.pdfOptional debug by printing HTML to stdout, includes optional header and footer :
$ txt2pdf --html-to-stdout README.md README.pdffrom txt2pdf.core import txt2pdf
txt2pdf(
pdf_file_path,
md_content=None,
md_file_path=None,
css_file_path=None,
html_header_content=None,
html_header_file_path=None,
html_footer_content=None,
html_footer_file_path=None,
base_url=None,
print_html_to_stdout=False,
)Function arguments:
pdf_file_path: output PDF file pathmd_content: input markdown raw string contentmd_file_path: input markdown file pathcss_file_path: input styles path (CSS)html_header_content: input HTML header raw string contenthtml_header_file_path: input HTML header file pathhtml_footer_content: input HTML footer raw string contenthtml_footer_file_path: input HTML footer file pathbase_url: absolute base path for markdown linked content (as images)print_html_to_stdout: print HTML to stdout for debug purposes
Install Docker
Build the image:
$ docker build -t txt2pdf .Now run your image:
$ docker run --rm -v $PWD:/app txt2pdf --css styles.css INPUT.MD OUTPUT.PDFEnsure, Weasyprint is fully functional before using txt2pdf. You will find installation instructions in the project documentation: https://weasyprint.readthedocs.io/en/latest/install.html
In a few words, here are the few steps you will need to follow:
- Install XQuartz from: https://xquartz.macosforge.org
- Install all dependencies at once with homebrew and go grab a coffee (this may take a while):
$ brew install cairo pango gdk-pixbuf libxml2 libxslt libffiWeasyPrint does not support the @font-face property yet (see project issue
28). If you use want to use
custom fonts, you should use system fonts and define them with the font-family
CSS property, like:
font-family: 'Neutraface Condensed';
Note that you should only define one single custom font, not a substitution list.
Generate default css defining a class for every code item type:
(venv) $ pygmentize -S default -f html -a .codehiliteClone this project first:
$ git clone git@github.com:c4ffein/txt2pdf.gitInstall it with its dependencies (ideally in a virtual environment):
$ cd txt2pdf
$ python -m venv venv
$ . venv/bin/activate
(venv) $ pip install .[dev]To run the test suite with your active python version (virtual environment):
(venv) $ pytestLint the code via:
(venv) $ black -l 120(venv) $ pip install .[deploy] # install flit if needed
(venv) $ flit publish --format sdist
txt2pdf is released under the MIT License. See the LICENSE file for details.
txt2pdf was based on md2pdf, original LICENSE kept in the licenses directory