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
- A Page holds TextRegions, which hold TextLines, then Words, then Glyphs. Each needs Coords, a polygon in pixels.
- TextEquiv holds the text, and a conf from 0 to 1 if there is one.
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 ).
- The default line level passes, with 0 errors.
-
page_xml_level=2falls back to line level, with a warning. -
page_xml_polygon=0writes boxes, not polygons: 20,910 bytes, not 53,040, and still valid.
Kraken's PAGE XML: 13.6 times Tesseract's size
- Every space between words is a Word of its own: 363 of 780 Words. Count Words, and you get almost double.
- Each character is a Glyph, with an outline and a conf.
- No ReadingOrder, so the reader below keeps file order.
- 2 pages came to 722,563 bytes, against Tesseract's 53,040.
-
--no-subline-segmentationcuts that to 59,762 bytes, but drops every conf. - Valid against the 2019-07-15 schema.
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.
- page-to-alto 2.2.12 from OCR-D, Apache-2.0: PAGE to ALTO 2.0 up to 4.2.
- PageConverter 1.5.05 from PRImA, Java, Apache-2.0: ALTO, hOCR and FineReader to PAGE, and PAGE to ALTO.
- ocr-fileformat 0.8.1 from UB Mannheim, MIT: PAGE to ALTO or hOCR and back. It needs Docker, or Java and Python.
What I did not test
- ALTO files against the ALTO schema.
- PAGE 2024-07-15 files: neither tool writes them.
- Kraken on CPU, its ABBYY XML, or other Kraken models.
- Transkribus, eScriptorium and OCR-D themselves.
- Pages in columns, other scripts, or PAGE read back into Kraken.
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
- PRImA PAGE-XML: the schemas, Apache-2.0
- The PAGE paper, ICPR 2010
- Tesseract 5.4.0 release notes: the new PAGE XML renderer
- pagerenderer.cpp: Tesseract's PAGE writer at 5.5.4
-
kraken.py
at 7.2 (the same in 7.1.1): the
-xoption - CATMuS-Print Large: the Kraken model
- OCR-D METS spec: PAGE as its exchange format
- Transkribus downloads: its export formats
- eScriptorium export.py: PAGE and ALTO export
- We make the Apify Actor, and none of the tools here.
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.
Or send us the scan. Tack, our AI, does the job for $29, up to 50 pages. First page free.