pear:packages:opendocument

OpenDocument

Package home: http://pear.php.net/package/OpenDocument
Current version: 0.2.0 (alpha) was released on 2009-07-28
Source repository: https://github.com/pear/OpenDocument
Bug tracker: http://pear.php.net/bugs/search.php?cmd=display&package_name[]=OpenDocument

OpenDocument is a package to create, read and update Open Document Format files. ODF is an XML-based file format for office documents such as spreadsheets, charts, presentations and word processing documents, with a standardised specification as an OASIS Committee Specification (v.1.2) and ISO/IEC 26300:2006 (v.1.0 with v.1.1 currently a Draft Amendment). The former specification is the most recently updated, is publicly available, and is the one we're working from for this PEAR package.

This wiki page coordinates the development of OpenDocument. It's not the documentation; just ideas about what we want and how we'll do it.

Development of the OpenDocument package was part of a Google Summer of Code project (anyone know which year?).

Other PHP ODF APIs

API Design

The current (26db346) OpenDocument class layout looks like this:

Super-class Class Sub-class Sub-sub-class
OpenDocument
OpenDocument_Document OpenDocument_Document_Text OpenDocument_Debug_Text
OpenDocument_Manifest
OpenDocument_Style OpenDocument_ElementStyle
PEAR_Exception OpenDocument_Exception
OpenDocument_Element OpenDocument_StyledElement OpenDocument_Element_Span
OpenDocument_Element_Paragraph
OpenDocument_Element_Hyperlink
OpenDocument_Element_Heading
OpenDocument_Element_Text
OpenDocument_Element_Bookmark
OpenDocument_Storage OpenDocument_Storage_Single
OpenDocument_Storage_Zip

Specification Structure

The specification has the following structure:

Namespaces: animation, chart, config, database, dr3d, drawing, form, manifest, meta, data style, office, presentation, script, table, text, style, xsl-fo-compatible, svg-compatible, smil-compatible, of, & odf.

ODF documents have two file-level organisational paradigms: the most common one is a packaged zip file containing a number of XML and other files; the second is a stand-alone single XML file. Both follow the standard file extension nomenclature: .odt for word processing (text) documents; .ods for spreadsheets; .odp for presentations; .odb for databases; .odg for graphics; .odf for formulae, mathematical equations.

Within these various XML files are the following elements:

Filename Root Element Child Elements
Stand-alone XML file:
filename.ext office:document office:automatic-styles
office:body
office:font-face-decls
office:master-styles
office:meta
office:scripts
office:settings
office:styles
Packaged file (4 root elements):
content.xml office:document-content office:automatic-styles
office:body
office:font-face-decls
office:scripts
styles.xml office:document-styles office:automatic-styles
office:font-face-decls
office:master-styles
office:styles
meta.xml office:document-meta office:meta
settings.xml office:document-settings office:settings

The <office:body> element contains what we think of as the actual different document types: <office:chart>, <office:database>, <office:drawing>, <office:image>, <office:presentation>, <office:spreadsheet>, <office:text>.

Examples

Future Development

Some notes about possibilities for the further development of this package...

  • OpenDocument_Element to be a sub-class of DOMElement;
  • All elements to be sub-classes of OpenDocument_Element, grouped by namespace;
  • The five root elements to be subclasses of DOMDOcument (these get used only by the storage class, usually);
  • Each of the seven ODF document types to be represented by OpenDocument sub-classes (these are the primary means of using the API).
  • The OpenDocument class is the means of interacting with the eight second-level elements (office:automatic-styles, office:body, office:font-face-decls, office:master-styles, office:meta, office:scripts, office:settings, and office:styles)
  • A couple of use cases:
    •       // A new text document, saved.
            $textDoc = new OpenDocument_Text();
            $heading = new OpenDocument_Element_Text_H();
            $heading->textContent = 'Hello World';
            $textDoc->getBody()->insertBefore($heading, null);
            $textDoc->save('hello.odt');
       
    •       // An existing spreadsheet, as a stand-alone file.
            $spreadsheet = new OpenDocument_Spreadsheet('existing.ods');
            $spreadsheet->setStorage(new OpenDocument_Storage_Single());
            $spreadsheet->save();
       
    • There will be additional convenience methods at various levels, things like $spreadsheet->getTable(1)->addRows($dataArray) and $textDoc->toHtml().

The (incomplete) hierarchy would then be along these lines:

Super-class Class Sub-class
OpenDocument OpenDocument_Chart
OpenDocument_Database
OpenDocument_Drawing
OpenDocument_Image
OpenDocument_Presentation
OpenDocument_Spreadsheet
OpenDocument_Text
OpenDocument_Storage OpenDocument_Storage_Single
OpenDocument_Storage_Zip
OpenDocument_Storage_ZipManifest
DOMDocument OpenDocument_Element_Office_Document
OpenDocument_Element_Office_DocumentContent
OpenDocument_Element_Office_DocumentStyles
OpenDocument_Element_Office_DocumentMeta
OpenDocument_Element_Office_DocumentSettings
PEAR_Exception OpenDocument_Exception
DOMElement OpenDocument_Element OpenDocument_Element_Office_AutomaticStyles
OpenDocument_Element_Office_FontFaceDecls
OpenDocument_Element_Office_MasterStyles
OpenDocument_Element_Office_Meta
OpenDocument_Element_Office_Scripts
OpenDocument_Element_Office_Settings
OpenDocument_Element_Office_Styles
OpenDocument_Element_Office_Chart
OpenDocument_Element_Office_Database
OpenDocument_Element_Office_Drawing
OpenDocument_Element_Office_Image
OpenDocument_Element_Office_Presentation
OpenDocument_Element_Office_Spreadsheet
OpenDocument_Element_Office_Text
OpenDocument_Element_Office_Forms
OpenDocument_Element_Dr3d_Scene
OpenDocument_Element_Draw_A
OpenDocument_Element_Draw_Caption
OpenDocument_Element_Draw_Circle
OpenDocument_Element_Draw_Connector
OpenDocument_Element_Draw_Control
OpenDocument_Element_Draw_Custom-shape
OpenDocument_Element_Draw_Ellipse
OpenDocument_Element_Draw_Frame
OpenDocument_Element_Draw_G
OpenDocument_Element_Draw_Line
OpenDocument_Element_Draw_Measure
OpenDocument_Element_Draw_PageThumbnail
OpenDocument_Element_Draw_Path
OpenDocument_Element_Draw_Polygon
OpenDocument_Element_Draw_Polyline
OpenDocument_Element_Draw_Rect
OpenDocument_Element_Draw_RegularPolygon
OpenDocument_Element_Table_CalculationSettings
OpenDocument_Element_Table_Consolidation
OpenDocument_Element_Table_ContentValidations
OpenDocument_Element_Table_DatabaseRanges
OpenDocument_Element_Table_DataPilotTables
OpenDocument_Element_Table_DdeLinks
OpenDocument_Element_Table_LabelRanges
OpenDocument_Element_Table_namedExpressions
OpenDocument_Element_Table_Table
OpenDocument_Element_Text_AlphabeticalIndex
OpenDocument_Element_Text_AlphabeticalIndexAutoMarkFile
OpenDocument_Element_Text_Bibliography
OpenDocument_Element_Text_Change
OpenDocument_Element_Text_ChangeEnd
OpenDocument_Element_Text_ChangeStart
OpenDocument_Element_Text_DdeConnectionDecls
OpenDocument_Element_Text_H
OpenDocument_Element_Text_IllustrationIndex
OpenDocument_Element_Text_List
OpenDocument_Element_Text_NumberedParagraph
OpenDocument_Element_Text_ObjectIndex
OpenDocument_Element_Text_P
OpenDocument_Element_Text_PageSequence
OpenDocument_Element_Text_Section
OpenDocument_Element_Text_SequenceDecls
OpenDocument_Element_Text_SoftPageBreak
OpenDocument_Element_Text_TableIndex
OpenDocument_Element_Text_TableOfContent
OpenDocument_Element_Text_TrackedChanges
OpenDocument_Element_Text_UserFieldDecls
OpenDocument_Element_Text_UserIndex
OpenDocument_Element_Text_VariableDecls
And so on, for all elements...
pear/packages/opendocument.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1