Skip to main content

markdown to pdf

Project description

Markdown to PDF Converter

This project provides a CLI and a web-based API service for converting Markdown files into PDF and optionally HTML files.

Features

  • Convert Markdown files to PDF with syntax highlighting.
  • Optionally generate an HTML version of the output.
  • Custom CSS support for styling.
  • Adjustable page size and margins.
  • List available code highlighting styles.
  • FastAPI-based web service with RESTful API.

Installation

To install the required dependencies, use:

pip install -r requirements.txt

CLI Usage

python convert.py [INPUT_FILE] [OUTPUT_FILE] [OPTIONS]

Arguments:

  • INPUT_FILE (optional): Path to the Markdown file.
  • OUTPUT_FILE (optional): Output PDF file path.

Options:

  • --style, -s (default: xcode): Code highlighting style.
  • --css, -c: Path to a custom CSS file.
  • --page-size (default: A4): Page size options (e.g., Letter, A3).
  • --margin (default: 0.05in): Page margin settings.
  • --html, -h: Also generate an HTML file.
  • --list-styles, -l: List all available code highlighting styles.

Example:

python convert.py sample.md sample.pdf --html --style=monokai

API Usage

You can run the FastAPI web service to provide Markdown-to-PDF conversion:

python serve.py --host 127.0.0.1 --port 8882

API Endpoints

Convert Markdown to PDF

POST /api/topdf

Parameters:

  • mdcontent: Markdown content as a form parameter.

Response:

  • Returns the generated PDF file.

Health Check

GET /health

Response:

{"status": "ok"}

Running the Server

To start the web server:

python serve.py

By default, the server runs on http://127.0.0.1:8882/.

Dependencies

  • Click for the CLI interface.
  • FastAPI and Uvicorn for the web service.
  • MarkdownConverter for conversion logic.

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xpdf-0.0.2.tar.gz (786.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

xpdf-0.0.2-py3-none-any.whl (785.4 kB view details)

Uploaded Python 3

File details

Details for the file xpdf-0.0.2.tar.gz.

File metadata

  • Download URL: xpdf-0.0.2.tar.gz
  • Upload date:
  • Size: 786.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for xpdf-0.0.2.tar.gz
Algorithm Hash digest
SHA256 c9ed4ff2108dff4333f03541a271f365f18e9f079eaa6668a728549899a2ddb2
MD5 b587e21132f97354946dcb060b07e131
BLAKE2b-256 26a497eb9398463dbdbeb5617e018e9d5490ed40a8e030f6b5d94fd58e519288

See more details on using hashes here.

Provenance

The following attestation bundles were made for xpdf-0.0.2.tar.gz:

Publisher: python-publish.yml on hyxf/xpdf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file xpdf-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: xpdf-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 785.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for xpdf-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4211068bb25f1e5649ae4e181813a90f53ca8c635aa1d0fc26cf2b8b7ea60800
MD5 099b02edc33e5f937e45a42feeec9ec3
BLAKE2b-256 1fe0134fbea10fa10db48b6212101ab3cd209c67a3643547abdf26aa584ffe50

See more details on using hashes here.

Provenance

The following attestation bundles were made for xpdf-0.0.2-py3-none-any.whl:

Publisher: python-publish.yml on hyxf/xpdf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page