pure nim reader for apple keynote, pages, and numbers documents.
everything a user needs is importable from plain import iwork: open a document with openDocument, then use getText on any kind, slides for keynote, sheets/tables for numbers, and bodyText for pages.
Example: cmd: -r:off
import src/iwork let doc = openDocument("deck.key") # auto-detects keynote/pages/numbers echo doc.kind # dkKeynote echo doc.getText() # all text, in reading order for slide in doc.slides: # keynote only echo slide.title, " | ", slide.presenterNotes let book = openDocument("budget.numbers") for table in book.tables: # numbers only for row in table.rows: for cell in row: echo cell.asString
Types
IworkDocument = ref object container*: IworkContainer ## the underlying container, for low-level use
- an opened iwork document with a lazily built object index Source Edit
Procs
proc bodyText(doc: IworkDocument): seq[string] {....raises: [IworkError, KeyError, IworkFormatError, Exception, IworkContainerError], tags: [RootEffect], forbids: [].}
- the body paragraphs of a pages document, in order; raises IworkError for keynote and numbers documents Source Edit
proc getText(doc: IworkDocument): string {. ...raises: [IworkContainerError, KeyError, Exception, IworkFormatError], tags: [RootEffect], forbids: [].}
-
all of the document's text in reading order - headers, body, footers, text boxes, presenter notes and table rows - joined with newlines. falls back to plainText for documents whose structure doesn't decode, so there's always something to index
Example: cmd: -r:off
echo openDocument("report.pages").getText()
Source Edit proc index(doc: IworkDocument): ObjectIndex {. ...raises: [IworkFormatError, Exception, IworkContainerError, KeyError], tags: [RootEffect], forbids: [].}
- Source Edit
proc kind(doc: IworkDocument): DocKind {....raises: [], tags: [], forbids: [].}
- which application the document belongs to Source Edit
proc openDocument(path: string): IworkDocument {....raises: [IworkContainerError, OSError, IOError, ZippyError, KeyError, IworkUnsupportedError, Exception], tags: [ ReadDirEffect, ReadIOEffect, ReadEnvEffect, WriteIOEffect, WriteDirEffect, RootEffect], forbids: [].}
-
opens a keynote, pages, or numbers document, auto-detecting the application from extension or content
Example: cmd: -r:off
let doc = openDocument("report.pages") echo doc.kind # dkPages
Source Edit proc plainText(doc: IworkDocument): string {. ...raises: [IworkFormatError, KeyError, Exception, IworkContainerError], tags: [RootEffect], forbids: [].}
- all document text, storages joined with newlines Source Edit
proc sheets(doc: IworkDocument): seq[Sheet] {....raises: [IworkError, IworkFormatError, KeyError, Exception, IworkContainerError], tags: [RootEffect], forbids: [].}
- the sheets of a numbers document with their decoded tables; raises IworkError for keynote and pages documents Source Edit
proc slides(doc: IworkDocument): seq[Slide] {....raises: [IworkError, IworkFormatError, KeyError, Exception, IworkContainerError], tags: [RootEffect], forbids: [].}
- the presented slides of a keynote document, in deck order; raises IworkError for pages and numbers documents Source Edit
proc tables(doc: IworkDocument): seq[numbers.Table] {....raises: [IworkError, IworkFormatError, KeyError, Exception, IworkContainerError], tags: [RootEffect], forbids: [].}
- every table across all sheets, flattened in sheet order Source Edit
proc textBlocks(doc: IworkDocument): seq[TextBlock] {. ...raises: [IworkFormatError, KeyError, Exception, IworkContainerError], tags: [RootEffect], forbids: [].}
-
every piece of text in the document in reading order, each labeled with what it is (header, body, footer, text box, notes, table row) and which slide or sheet it came from
Example: cmd: -r:off
let doc = openDocument("deck.key") for blk in doc.textBlocks: echo blk.section, " ", blk.kind, ": ", blk.text
Source Edit
Exports
-
CellKind, decodeCellAt, asString, cellOffsets, CellValue, IworkError, ContainerKind, openContainer, IworkContainerError, metadataPlist, IworkUnsupportedError, DocKind, IworkContainer, readEntry, IworkFormatError, iwaEntries, TextBlockKind, textBlocks, TextBlock, IworkContainerError, IworkUnsupportedError, IworkError, IworkFormatError, Slide, keynoteSlides, Sheet, rows, numbersSheets, Table, cell, toCsv, buildIndex, message, IworkObject, ObjectIndex, derefAll, deref, pagesTextBoxes, pagesHeadersFooters, pagesBodyText, IworkUnsupportedError, decodeIwa, IworkError, IworkFormatError, IworkContainerError, extractText, storageText, knDocumentArchive, knPlaceholderArchive, tstTileArchive, tswpShapeInfoArchive, tpHeadersFootersArchive, tpSectionArchive, tswpStorageArchive, tstTableInfoArchive, knSlideArchive, tstTableDataList, knNoteArchive, tstTableModelArchive, tnDocumentArchive, knSlideNodeArchive, tnSheetArchive, knShowArchive, tpDocumentArchive, getUint, getMessage, WireKind, getInt, getFloat, getString, readVarint, getRepeatedInt, WireValue, getRepeatedMessage, getRepeatedString, getRepeatedDouble, getRepeatedUint, getDouble, decodeMessage, WireMessage, getRepeatedFloat