1. A non-transitory machine readable medium storing a program which when executed by at least one processing unit analyzes a document, the program comprising sets of instructions for: receiving a document that comprises a plurality of primitive graphic elements defined separately within the document, the document having a drawing order that indicates the order in which the primitive graphic elements are drawn when the document is displayed; calculating a first value for a first primitive graphic element and a second primitive graphic element that is subsequent to the first primitive graphic element in the drawing order by using bounds of the first and second primitive graphic elements; based on a comparison of the first value to other values calculated for additional primitive graphic elements that are subsequent in the drawing order, defining a cluster comprising at least the first and second primitive graphic elements; and when the bounds of the first and second primitive graphic elements at least partially overlap, defining a single structural graphic element within the document from the first and second primitive graphic elements.