layout

package
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2026 License: MIT Imports: 5 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package layout groups positioned characters into words, lines and text boxes, and orders the boxes for reading. It is a port of pdfminer.six's layout analysis (layout.py), so text comes out in the order and with the spacing pdfminer (and so markitdown) gives.

Index

Constants

This section is empty.

Variables

View Source
var DefaultParams = Params{LineOverlap: 0.5, CharMargin: 2.0, LineMargin: 0.5, WordMargin: 0.1, BoxesFlow: 0.5}

DefaultParams are pdfminer.six's defaults.

Functions

func Analyze

func Analyze(page *Page, p Params)

Analyze lays out a page: its characters become text boxes in reading order, followed by its figures (as drawn) and whitespace-only lines.

func Text

func Text(page *Page) string

Text renders a page as pdfminer's TextConverter does: each box's lines, a newline after each box, figures' characters as drawn, and a form feed at the end.

Types

type Char

type Char struct {
	Rect
	Text     string
	Font     string
	Size     float64 // height for horizontal text, width for vertical
	Adv      float64
	Upright  bool
	Vertical bool
}

Char is one drawn character.

func (*Char) Box

func (c *Char) Box() Rect

type Figure

type Figure struct {
	Rect
	Name  string
	Items []Item
}

Figure is the content of a form XObject. Like pdfminer, the analysis leaves its characters as drawn.

func (*Figure) Box

func (f *Figure) Box() Rect

type Item

type Item interface{ Box() Rect }

Item is something on a page: a *Char or a *Figure before analysis; after it, also *TextBox and *TextLine.

type Page

type Page struct {
	Rect
	Number int
	Items  []Item // as drawn; after Analyze, boxes then other items
}

Page is one page's content.

func (*Page) Box

func (p *Page) Box() Rect

type Params

type Params struct {
	LineOverlap    float64
	CharMargin     float64
	LineMargin     float64
	WordMargin     float64
	BoxesFlow      float64
	NoBoxesFlow    bool // order boxes by position alone (boxes_flow=None)
	DetectVertical bool
}

Params tunes the analysis; DefaultParams are pdfminer's LAParams.

type Path

type Path struct {
	Rect
	Kind         PathKind
	Pts          []Point
	Stroke, Fill bool
}

Path is a painted path: a line, rectangle or curve, with the points pdfminer keeps for it (each segment's end point). Layout analysis leaves paths alone; table detection reads their edges.

func NewPath

func NewPath(kind PathKind, pts []Point, stroke, fill bool) *Path

NewPath builds a path item from its points.

func (*Path) Box

func (p *Path) Box() Rect

type PathKind

type PathKind int

PathKind classifies a painted path as pdfminer does.

const (
	PathCurve PathKind = iota // any other shape, as a polyline of its points
	PathLine                  // one straight segment
	PathRect                  // an axis-aligned rectangle
)

type Point

type Point struct{ X, Y float64 }

Point is a position in user space.

type Rect

type Rect struct{ X0, Y0, X1, Y1 float64 }

Rect is a bounding box in PDF user space: x grows right, y grows up.

func (Rect) Height

func (r Rect) Height() float64

func (Rect) Width

func (r Rect) Width() float64

type TextBox

type TextBox struct {
	Rect
	Vertical bool
	Lines    []*TextLine
	// contains filtered or unexported fields
}

TextBox is a block of lines, such as a paragraph.

func (*TextBox) Box

func (b *TextBox) Box() Rect

func (*TextBox) Text

func (b *TextBox) Text() string

Text is the box's lines' text.

type TextLine

type TextLine struct {
	Rect
	Vertical bool
	Chars    []*Char
	// contains filtered or unexported fields
}

TextLine is a line of characters, with spaces and a final newline added by the analysis.

func (*TextLine) Box

func (l *TextLine) Box() Rect

func (*TextLine) Text

func (l *TextLine) Text() string

Text is the line's text, ending in a newline once analyzed.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL