Documentation
¶
Overview ¶
Package pdfscan reads a PDF back: its objects, its pages, and the text, paths and images its content streams draw.
It exists so that a rendered document can be checked against the printout it came from -- glyph positions, line widths, link rectangles, outline structure -- which no printout-level test can see. It is a verification tool, deliberately independent of the writer: it parses the cross reference table rather than trusting object order, and it recovers text through each font's own ToUnicode map rather than through anything the writer remembers.
It reads the subset of PDF this project writes. It is not a general reader: no encryption, no object streams, no filters but FlateDecode.
Index ¶
- func Text(object Object) string
- type Annot
- type Array
- type Dict
- type Draw
- type File
- func (file *File) Catalog() Dict
- func (file *File) Data(stream *Stream) ([]byte, error)
- func (file *File) Fonts(page Dict) (map[string]*Font, error)
- func (file *File) Get(dict Dict, key Name) Object
- func (file *File) Info() Dict
- func (file *File) Number(dict Dict, key Name) (float64, bool)
- func (file *File) PageContent(page Dict) ([]byte, error)
- func (file *File) Pages() []Dict
- func (file *File) ReadPages() ([]*Page, error)
- func (file *File) Resolve(object Object) Object
- type Font
- type Name
- type Object
- type Page
- type Rect
- type Ref
- type Run
- type Segment
- type Stream
- type String
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Annot ¶
type Annot struct {
Subtype string
Left, Top, Width, Height float64
URI string
// DestPage is the index of the page a destination points at,
// -1 for a link that has none.
DestPage int
DestLeft, DestTop float64
Contents string
}
Annot is a link annotation.
type File ¶
type File struct {
Trailer Dict
// contains filtered or unexported fields
}
File is a parsed PDF.
func (*File) Fonts ¶
Fonts reads every font a page's resources offer, which is what a test comparing the file's widths against the original tables needs.
func (*File) PageContent ¶
PageContent returns a page's decoded content stream.
type Font ¶
type Font struct {
// Resource is the name a content stream selects it by.
Resource string
// BaseFont is the /BaseFont name, subset tag included.
BaseFont string
// Composite reports Identity-H encoding, whose codes are two bytes.
Composite bool
// Widths are in thousandths of an em, by character code.
Widths map[uint16]float64
// Unicode maps a code to the characters it stands for.
Unicode map[uint16]string
// Descriptor is the font descriptor dictionary.
Descriptor Dict
// FontFile is the embedded font program.
FontFile []byte
}
Font is a font as the file describes it: the widths a reader advances the pen by, and the map back from codes to characters.
type Object ¶
type Object any
Object is any PDF value: nil, bool, float64, String, Name, Ref, Array, Dict, or *Stream.
type Page ¶
type Page struct {
Number int
Width, Height float64
Runs []Run
Rects []Rect
Segments []Segment
Draws []Draw
Annots []Annot
}
Page is one page as read back.
type Rect ¶
type Rect struct {
Left, Top, Width, Height float64
// Painted is "fill", "stroke", "fillstroke", or "clip".
Painted string
Fill [3]float64
Stroke [3]float64
LineWidth float64
Dash []float64
}
Rect is a rectangle the content stream painted.
type Run ¶
type Run struct {
Font string
Size float64
Left float64
Baseline float64
Text string
// Width is the advance the file itself says the string has, summed
// from the font dictionary's W array. It is what a reader would move
// the pen by, which is not necessarily what the engine measured.
Width float64
}
Run is one shown string, with where the reader's pen was when it was shown and how far the string advances it.
Left and Baseline are in the printout's coordinates -- origin top left, Y down -- so they compare directly against a text mark.
type Segment ¶
type Segment struct {
FromLeft, FromTop float64
ToLeft, ToTop float64
Stroke [3]float64
LineWidth float64
Dash []float64
}
Segment is a stroked straight line.