Breaking a paragraph up, and aligning it

A paragraph broken into lines, set four ways: left, right, centred, justified.

Hand the engine a paragraph and the width of a column, and it answers with lines. The same paragraph is set four times over on this page — aligned left, aligned right, centred, justified — so what each alignment does to the same words can be read off one sheet.

Line breaking is where a PDF library either saves you two weeks of work or costs you two. Nothing here counts characters: every possible line is measured in the font that will draw it, at the size it will be drawn at, which is the only way the right edge of a justified column comes out straight.

What this example shows

  • Lines broken to the column width, measured in the font that draws them.
  • Aligned left, right, centred or justified: one call each.
  • The starting point for every other text example on this site.

The code, in full

The same document is written twice, once in each language. Both files are shown in full, with the code coloured on the server, and can be copied in one click.

The document itself

The same document is written in each of these languages. Open the one you want to look at.

Open the document in English Open the document in French

Read the Rust source Read the Python source

First page of Breaking a paragraph up, and aligning it

What this document weighs

Before 108,987 bytes
Now 38,284 bytes
Saved 64.9 %

Not one mark on the page changed. See every document measured.

Examples near this one

Soft hyphens and no-break spaces

A justified column set twice: the long words breaking at their soft hyphens with a hyphen shown, or left whole, and a figure a no-break space keeps together.

Break points after a slash or a hyphen

A justified column set twice: file paths and compounds running past the edge with no break points, then wrapping where a break after a slash or a hyphen is allowed.

Text poured into columns

One long passage poured into three columns, each fitting the lines its height allows and handing the rest to the next.

Every example, by subject