or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

dimensions.mddocument-structure.mdgraphics-images.mdindex.mdlayout-engine.mdreferences.mdstyling-system.mdtemplate-system.mdtypography-text.md
tile.json

tessl/pypi-rinohtype

A comprehensive Python document processing library that renders structured documents to PDF with advanced typography and customizable styling

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/rinohtype@0.5.x

To install, run

npx @tessl/cli install tessl/pypi-rinohtype@0.5.0

index.mddocs/

rinohtype

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

Package Information

  • Package Name: rinohtype
  • Language: Python
  • Installation: pip install rinohtype

Core Imports

import rinohtype

Common for document processing:

from rinohtype import Document, DocumentTree, StyleSheet
from rinohtype import Paragraph, Section, Heading, List, Table
from rinohtype import Style, Dimension, Color

For 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, INCH

Basic Usage

from 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.pdf

More 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')

Architecture

rinohtype uses a layered architecture for flexible document processing:

  • Document Tree: Hierarchical content structure with flowables and elements
  • Template System: Page layout, headers/footers, and document structure templates
  • Style System: CSS-like styling with inheritance, selectors, and attribute validation
  • Layout Engine: Container-based layout with automatic text flow and pagination
  • Typography Engine: Advanced text rendering with font management and OpenType features
  • Backend System: Pluggable output backends (currently PDF via ReportLab)

The core workflow: Content → Styling → Layout → Rendering → Output

Capabilities

Document Structure

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): ...

Document Structure

Styling System

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): ...

Styling System

Layout Engine

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): ...

Layout Engine

Typography and Text

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): ...

Typography and Text

Graphics and Images

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): ...

Graphics and Images

Template System

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'): ...

Template System

References and Cross-References

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

Dimensions and Measurements

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>  # Percentage

Dimensions and Measurements

Error Handling

rinohtype provides several exception types for different error conditions:

  • ResourceNotFound: Raised when fonts, images, or other resources cannot be found
  • ParseError: Raised when parsing configuration files or style definitions fails
  • ContainerOverflow: Raised during layout when content doesn't fit in available space
  • InlineFlowableException: Raised for inline element rendering issues

Common error scenarios include missing font files, invalid style definitions, and layout overflow conditions.