Coder Social home page Coder Social logo

md2pdf's Introduction

md2pdf logo

Convert Markdown files to PDF with styles.

Build Status Coverage Status

Installation

The easiest way to go is to use pip:

$ pip install md2pdf

Usage

As a CLI

Usage:
    md2pdf [options] INPUT.MD OUTPUT.PDF

Options:
    --css=STYLE.CSS

For example, try to generate the project documentation with:

$ md2pdf README.md README.pdf

Optionally, you may load an external style (restricted to CSS2):

$ md2pdf --css tests/resources/input.css README.md README.pdf

As a library

You can use md2pdf in your python code, like:

from md2pdf.core import md2pdf

md2pdf(pdf_file_path,
       md_content=None,
       md_file_path=None,
       css_file_path=None,
       base_url=None)

Function arguments:

  • pdf_file_path: output PDF file path
  • md_content: input markdown raw string content
  • md_file_path: input markdown file path
  • css_file_path: input styles path (CSS)
  • base_url: absolute base path for markdown linked content (as images)

With Docker

Install Docker

Pull the image:

$ docker pull jmaupetit/md2pdf

Now run your image:

$ docker run --rm -v $PWD:/app jmaupetit/md2pdf --css styles.css INPUT.MD OUTPUT.PDF

Troubleshooting on MacOSX

Ensure, Weasyprint is fully functional before using md2pdf. 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:

$ brew install cairo pango gdk-pixbuf libxml2 libxslt libffi

Misc

Using custom fonts in styles

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

Contributing

Hacking

Clone this project first:

$ git clone [email protected]:jmaupetit/md2pdf.git

Install it with its dependencies (ideally in a virtual environment):

$ cd md2pdf
$ python -m venv venv
$ source venv/bin/activate
(venv) $ pip install -r requirements-dev.txt
(venv) $ python setup.py develop

Running the test suite

To run the test suite with your active python version (virtual environment):

(venv) $ pytest

Lint the code via:

(venv) $ flake8

Release a new version

Upload a new release to PyPI:

$ python setup.py sdist bdist_wheel
$ twine upload dist/* --username 'johndoe' --password 'secret'

License

md2pdf is released under the MIT License. See the bundled LICENSE file for details.

md2pdf's People

Contributors

jmaupetit avatar theeko74 avatar lunika avatar krichprollsch avatar trots 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.