A comprehensive Python document processing library that renders structured documents to PDF with advanced typography and customizable styling
npx @tessl/cli install tessl/pypi-rinohtype@0.5.0A comprehensive Python document processing library that renders structured documents to PDF with advanced typography, customizable styling, and professional layout capabilities. rinohtype enables creation of high-quality PDFs from reStructuredText, CommonMark, and Sphinx sources with extensive control over document appearance and structure.
pip install rinohtypeimport rinohtypeCommon for document processing:
from rinohtype import Document, DocumentTree, StyleSheet
from rinohtype import Paragraph, Section, Heading, List, Table
from rinohtype import Style, Dimension, ColorFor specific functionality:
# Template system
from rinohtype.template import Article, Book, DocumentTemplate
# Styling system
from rinohtype.style import StyleSheet, Style
from rinohtype.stylesheets import sphinx
# Layout and flowables
from rinohtype.flowable import Flowable, GroupedFlowables
from rinohtype.structure import Section, Heading, List, Table
from rinohtype.paragraph import Paragraph
from rinohtype.image import Image, Figure
# Typography and formatting
from rinohtype.font import Typeface, Font
from rinohtype.color import Color, HexColor, BLACK, WHITE
from rinohtype.dimension import Dimension, PT, MM, CM, INCHfrom rinohtype import Document, DocumentTree, StyleSheet
from rinohtype.structure import Section, Heading
from rinohtype.paragraph import Paragraph
from rinohtype.template import Article
from rinohtype.stylesheets import sphinx
from rinohtype.backend import pdf
# Create document content
heading = Heading("Document Title")
content = Paragraph("This is the main content of the document.")
section = Section([heading, content])
# Build document tree
doc_tree = DocumentTree([section])
# Create document with template and stylesheet
template = Article()
stylesheet = sphinx
document = Document(doc_tree, stylesheet, template)
# Render to PDF
document.render('output') # Creates output.pdfMore complex example with styling:
from rinohtype import *
from rinohtype.style import Style
from rinohtype.color import Color
from rinohtype.dimension import PT
# Create custom styles
title_style = Style(font_size=16*PT, font_weight='bold',
text_color=Color(0, 0, 0.8))
body_style = Style(font_size=11*PT, line_spacing=1.2)
# Create styled content
title = Heading("Custom Document", style=title_style)
paragraph = Paragraph("Content with custom styling.", style=body_style)
# Build and render document
doc_tree = DocumentTree([Section([title, paragraph])])
document = Document(doc_tree, stylesheet=sphinx)
document.render('styled_output')rinohtype uses a layered architecture for flexible document processing:
The core workflow: Content → Styling → Layout → Rendering → Output
Core document building blocks including sections, headings, paragraphs, lists, tables, and hierarchical content organization.
class Section(Flowable):
def __init__(self, flowables, id=None, style=None, parent=None, source=None): ...
class Heading(Paragraph):
def __init__(self, content, id=None, style=None, parent=None, source=None): ...
class Paragraph(Flowable):
def __init__(self, text_or_flowables, id=None, style=None, parent=None, source=None): ...
class List(Flowable): ...
class ListItem(Flowable): ...
class Table(Flowable): ...Comprehensive styling framework with CSS-like selectors, inheritance, attribute validation, and stylesheet management.
class Style(AttributesDictionary):
def __init__(self, base=None, **attributes): ...
class StyleSheet(dict):
def __init__(self, name, base=None, matcher=None): ...
class Styled(DocumentElement):
style = Attribute(Style): ...Advanced layout system with container management, text flow, pagination, and automatic element positioning.
class Container:
def __init__(self, name, parent, left=None, top=None, width=None, height=None): ...
def render(self, flowable, last_descender=None): ...
def advance(self, height): ...
class Flowable(Styled):
def flow(self, container, last_descender, state=None): ...
def render(self, container, descender, state=None, first_line_only=False): ...Advanced text processing including font management, text styling, inline elements, and OpenType features.
class Font:
def __init__(self, typeface, weight=MEDIUM, width=NORMAL, slant=UPRIGHT): ...
class Typeface:
def __init__(self, name, *fonts): ...
class StyledText(InlineFlowable):
def __init__(self, text, style=None, parent=None): ...
class TextStyle(Style): ...Image handling, drawing primitives, shapes, colors, and graphical elements for rich document content.
class Image(Flowable):
def __init__(self, filename_or_file, scale=1.0, width=None, height=None, dpi=None): ...
class Figure(Float):
def __init__(self, image_or_flowable, caption=None, id=None, style=None): ...
class Color:
def __init__(self, red, green, blue, alpha=1): ...
class Rectangle(Shape):
def __init__(self, bottom_left, width, height, style=None, parent=None): ...Document templates, page layouts, headers/footers, and document structure configuration.
class DocumentTemplate(TemplateConfiguration):
def __init__(self, name=None, configuration=None): ...
class Article(DocumentTemplate): ...
class Book(DocumentTemplate): ...
class PageTemplate:
def __init__(self, name, page_size, page_orientation='portrait'): ...Cross-reference system including footnotes, endnotes, table of contents, index, and internal linking.
class Reference(InlineFlowable):
def __init__(self, target, reference_type='reference', style=None): ...
class Note(GroupedFlowables):
def __init__(self, note_flowables, id=None, style=None, parent=None): ...
class TableOfContents(Section): ...
class Index(Section): ...References and Cross-References
Comprehensive measurement system with units, calculations, and layout dimensions.
class Dimension:
def __init__(self, value=0, unit=None): ...
def to_points(self, total_dimension=None): ...
# Unit constants
PT = <DimensionUnit> # Points (1/72 inch)
MM = <DimensionUnit> # Millimeters
CM = <DimensionUnit> # Centimeters
INCH = <DimensionUnit> # Inches
PERCENT = <DimensionUnit> # Percentagerinohtype provides several exception types for different error conditions:
Common error scenarios include missing font files, invalid style definitions, and layout overflow conditions.