COG Extractor

Steven R. Bagley · 2006

The Component Object Graphic (COG) model describes documents as a series of distinct, encapsulated graphical blocks (termed COGs) that are positioned on the page rather than the traditional approach (taken by formats such as PostScript, PDF and SVG) of describing each page as one monolithic block of drawing operators that create marks on the page to form the content. Previous work [1, 2] has demonstrated how this paradigm can be implemented on top of both PDF and SVG.Tools have previously been created which allow the creation of COG documents [1, 3] and manipulation of existing COGs to form new documents [1, 4]. Missing from the COG toolkit has been a method of producing COGs from already existing content. The proposed solution is a new tool entitled 'COG Extractor' that allows the user to select an area of an existing document to be extracted and converted to be a COG in PDF or SVG form.The first process is to get the documents into a format that can easily be understood. The most sensible choice is PDF since there are several tools that can convert other formats into PDF.It is then necessary to parse the PDF content stream for the page to be extracted and to derive the meaning of the operators in the page's content stream. PDF's operators can be divided into two classes: those that image content, and those that define the state (such as fill colour, line width) that content is imaged with. This causes problems since each imaging operators depends on the cumulative effect of all previous state operators. It is therefore necessary to work out exactly which operators are responsible for drawing the content.This is achieved by combining consecutive state operators together to form a state-change object, which encapsulates all changes in state at that point. Everything following the state-change object in the PDF content stream then become children of that state-change object. This produces a tree representation of the document where the drawing operators form the leaf nodes. The state of any drawing operator can then be calculated by walking back along its parents in the tree.From this tree it is then possible to calculate the bounding box of each drawing operator and see if it intersects with the area to be extracted. If they do not intersect, then that drawing operator can be pruned from the tree.An optimization phase can remove any state-change nodes that are no longer required (e.g nodes for which all children have been removed). This tree can then be exported as a COG in PDF or SVG format for future use.

Read the paper · More papers on PaperTik