msdoc

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 28 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package msdoc opens the Word documents of Word 97 to Word 2003: .doc files and .dot templates (MS-DOC). It also reads the text of a document of Word 6 or Word 95, with the properties of its characters and its paragraphs.

A Word document is a Compound File, which the package cfb of magic reads. The package reads the File Information Block, the piece table and the text of the main document, with the bold, the italic, the underline, the size, the color, the border and the font of each run, the alignment, the indents, the spacing and the tab stops of each paragraph, and the headings of the style sheet. It converts the text into HTML, with each table as an HTML table, for the layout of ivy (D10). Each section has pages of its own size and margins, with its headers, its footers and its columns. The layout makes the margins of a page larger for a header or a footer that needs it. A section break starts a new page, unless the next section is continuous on a page of the same size. The tables have the borders, the shading and the merged cells of their rows. The lists have their numbers and their bullets, with the indents and the tab stops of their levels. A table or a frame that floats is at its position, and the text wraps around it when it leaves room beside it. Its vertical position from the margin or from the page holds only when it starts a page, because the layout places a float at the line of its paragraph. The pictures of the stream Data and the shapes of Office Drawing that float on the page show. internal/odraw draws the shapes, as it draws those of msppt and msxls (D51): the preset shapes, the freeforms, the lines with their arrowheads, the groups, the pictures with their crops and turns, and the WordArt. Each shape goes into the layout as a box whose content is a display list. A text box shows its text over the box of its shape, and the text of a shape of a group shows over the box of the group. A footnote goes at the foot of its page, and the endnotes go at the end of the document. A run gives its East Asian font after its font, and the language of its East Asian text.

The package leaves out the comments. A WordArt that bends its text, such as an arch, shows its text straight. The codes of the fields are left out, and their results stay, but the page numbers of the fields PAGE and NUMPAGES come from the layout. Of a document of Word 6 or Word 95, the package leaves out the headers, the footers, the footnotes, the text boxes, the lists, the pictures and the properties of the tables.

A document gives its thumbnail and its properties from the stream "\x05SummaryInformation". A document that a password protects with RC4, RC4 CryptoAPI or the XOR obfuscation asks for the password as D12 says. The package returns an error that wraps ivy.ErrUnsupported for a document of Word 6 or Word 95 that a password protects.

Index

Constants

This section is empty.

Variables

View Source
var Format = ivy.Format{
	Name:  "msdoc",
	Mimes: []string{"application/msword", "application/vnd.ms-word", "application/x-msword"},
	Exts:  []string{"doc", "dot"},
	Open: func(ctx context.Context, src ivy.Source, cfg ivy.Config) (ivy.Document, error) {
		return Open(ctx, src, WithConfig(cfg))
	},
}

Format describes the package for the registry of a program.

Functions

This section is empty.

Types

type Document

type Document struct {
	// contains filtered or unexported fields
}

Document is an open Word document.

func Open

func Open(ctx context.Context, src ivy.Source, opts ...Option) (d *Document, err error)

Open opens a Word document. It reads the summary information, the FIB, the piece table, the style sheet and the formatted disk pages, and decrypts the document if a password protects it. It returns an error that wraps ivy.ErrFormat if src is not a Word document, one that wraps ivy.ErrPassword if the password is missing or wrong, and one that wraps ivy.ErrUnsupported for a document of Word 6 or Word 95 with a password, or for a FIB of Word 97 with the nFib of an older version.

func (*Document) Close

func (d *Document) Close() error

Close satisfies the ivy.Document interface.

func (*Document) Describe

func (d *Document) Describe(ctx context.Context) (ivy.Info, error)

Describe satisfies the ivy.Describer interface. It returns the properties of the summary information, and the language of the FIB.

func (*Document) Page

func (d *Document) Page(ctx context.Context, n int) (ivy.Page, error)

Page satisfies the ivy.Pager interface. It lays out the document only as far as page n.

func (*Document) PageCount

func (d *Document) PageCount(ctx context.Context) (int, error)

PageCount satisfies the ivy.Pager interface. It lays out the whole document on its first call.

func (*Document) Previews

func (d *Document) Previews(ctx context.Context) iter.Seq2[ivy.Preview, error]

Previews satisfies the ivy.Previewer interface. It lists the thumbnail of the summary information, which Word writes when a person asks for a preview picture.

func (*Document) Template

func (d *Document) Template() bool

Template reports whether the document is a template, a .dot file.

type Option

type Option func(*options)

Option is an option of Open.

func WithConfig

func WithConfig(cfg ivy.Config) Option

WithConfig sets the configuration that every format shares.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL