1. A machine readable medium storing a program which when executed by at least one processing unit analyzes a document that comprises a plurality of words, each word comprising an associated set of glyphs, each glyph having location coordinates, the program comprising sets of instructions for: identifying a group of words aligned in a first direction based on the location coordinates of a particular glyph in each of the words in the group of aligned words; based on the identified group of aligned words, defining an alignment element for the particular glyphs at a particular location in the first direction, wherein the alignment element that indicates a particular alignment for a plurality of text lines containing the group of aligned words; removing particular locations from the alignment element in a second direction based on an analysis of the group of aligned words, wherein each particular location of the alignment element corresponds to a particular text line; and defining a structured document based on the glyphs and remaining locations of the defined alignment element.