PAGE XML format: what Tesseract and Kraken write

PAGE XML stores a scanned page: regions, lines and words, each with an outline and text.

414

schema errors, Tesseract's word-level PAGE XML

Just the text? OCR Actor, $0.006 a scanned page

Runs on Apify's servers: files leave your computer.

What a PAGE XML file holds

Tesseract's file for one book page, cut down to its first line:

<PcGts xmlns="http://schema.primaresearch.org/PAGE/gts/pagecontent/2019-07-15" ...>
  <Metadata> ... </Metadata>
  <Page imageFilename="b00-p0088.jpg" imageWidth="1920" imageHeight="3079">
    <ReadingOrder> ... </ReadingOrder>
    <TextRegion id="r0" ...>
      <Coords points="225,378 1466,378 1466,447 225,447"/>
      <TextLine id="r0l0" ...>
        <Coords points="225,383 261,382 ... 225,434"/>
        <Baseline points="225,434 684,432 1191,431 1466,431"/>
        <TextEquiv index="1" conf="0.9502">
          <Unicode>86 The Boy Scouts of the Air

Two free tools write PAGE XML

Tesseract, version 5.4.0 or later:

tesseract scan.jpg out -l eng page

Kraken, with the CATMuS-Print Large model:

kraken get 10.5281/zenodo.10592716
kraken -x -i scan.jpg out.page.xml segment -bl ocr -m catmus-print-fondue-large.mlmodel

Mind the -x: before the command it means --pagexml. After segment it means --boxes, the old segmenter, so type segment -bl.

2.9 to 4.1 s a page, Tesseract, any format

31.9 to 32.7 s a page, Kraken, PAGE XML

Same words, 5 formats, different extras

One Tesseract run a page, 2 pages, the same 414 words in all 5:

Format Bytes Also keeps
PAGE XML 53,040 Line outlines, baselines, reading order, conf per line, 0 to 1
ALTO v3 65,409 Word boxes, conf per word, 0 to 1
hOCR 52,412 Word boxes, baselines, conf per word, 0 to 100
TSV 20,478 Word boxes, line numbers, conf per word, 0 to 100
TXT 2,223 Text only

Only PAGE has a reading order and polygons. More on hOCR: Tesseract hOCR.

Word-level Tesseract PAGE XML fails the schema

tesseract scan.jpg out -l eng -c page_xml_level=1 page

This puts a Baseline inside every Word. The PRImA schema allows none there, in 2019-07-15 or the newer 2024-07-15. xmllint flags each one (namespace URIs cut here):

b00-p0088.page.xml:22: element Baseline: Schemas validity error : Element 'Baseline': This element is not expected. Expected is one of ( Glyph, TextEquiv, TextStyle, UserDefined, Labels ).

Kraken's PAGE XML: 13.6 times Tesseract's size

Setup, speed and its ¬ marks: Kraken OCR, tested.

Read PAGE XML in Python, stdlib only

Save as read_page.py and run python3 read_page.py out.page.xml:

import sys
import xml.etree.ElementTree as ET

root = ET.parse(sys.argv[1]).getroot()
ns = {"p": root.tag[1:].split("}")[0]}
regions = {r.get("id"): r for r in root.iterfind(".//p:TextRegion", ns)}
order = [r.get("regionRef") for r in root.iterfind(".//p:ReadingOrder//*[@regionRef]", ns)]
order = [i for i in order if i in regions] + [i for i in regions if i not in order]
for rid in order:
    for line in regions[rid].iterfind("p:TextLine", ns):
        text = line.findtext("p:TextEquiv/p:Unicode", "", ns).strip()
        words = line.iterfind("p:Word/p:TextEquiv/p:Unicode", ns)
        print(text or " ".join(w.text or "" for w in words))

Any PAGE version should work (tested on 2019-07-15). For files from strangers, use defusedxml.

392 of 399 words, Tesseract's file

389 of 399, Kraken's file

Convert PAGE XML to ALTO or hOCR

Three open-source converters. I read their docs, but did not run them.

What I did not test

How I tested it
  • 2 pages from 2 scanned books, proofread on Wikisource, 399 true words, 1,920-pixel JPEGs.
  • Score: true words found in order, page by page.
  • Tesseract 5.5.4 from Homebrew, English. One run wrote all 5 formats. Each PAGE setting had a run of its own.
  • Kraken 7.1.1, baseline segmenter, CATMuS-Print Large, on the Mac GPU, with the network off.
  • Validation: xmllint with the 2019-07-15 XSD from PRImA's GitHub, tag 2019-07-15_3.
  • Tesseract and Kraken are Apache-2.0. The CATMuS-Print Large model is CC BY 4.0.
  • Our Actor's own code ran on this Mac, not on Apify.
  • Scripts and results stay in our private repo, in research/bench/page-xml-2026-11-24/.
Sources

Questions people ask

What is the PAGE XML format?

PAGE means Page Analysis and Ground-Truth Elements. It is an XML format for one page image: regions, lines, words and glyphs, each with an outline, and their text. PRImA Research Lab at the University of Salford made it, and described it in a 2010 paper.

Who uses PAGE XML?

Tesseract's manual names Transkribus and eScriptorium. OCR-D calls PAGE its primary exchange format. Transkribus and eScriptorium both export it, and Kraken can train from it.

Which PAGE XML schema version should I validate against?

The one in the file's namespace. Tesseract and Kraken both write 2019-07-15, so use the 2019-07-15 XSD. PRImA's newest is 2024-07-15, and its GitHub master now holds that one.

PAGE XML or ALTO: which should I use?

The one your next tool reads. Here, Tesseract's ALTO kept word boxes and conf, with no baselines or reading order. Its PAGE XML kept line outlines, baselines and a reading order. The Library of Congress maintains ALTO.

Need only the text?

Run our Actor. It turns scanned PDFs and photos into Markdown or plain text, with no PAGE XML or word positions. Its code found 393 of 399 words here, run on this Mac.

Try the Actor

Or send us the scan. Tack, our AI, does the job for $29, up to 50 pages. First page free.

Get one page free