Documentation
¶
Overview ¶
Package pdf reads the object structure of PDF files: objects, cross reference tables and streams, object streams, stream filters, encryption, and the page tree. It is the syntax layer under text extraction, after pdfminer.six's psparser, pdfparser, pdfdocument, pdftypes and pdfpage.
It is built for reading files from anywhere: it repairs what it can (a broken cross reference table, a wrong stream length, a truncated zlib stream), bounds what it allocates, and reports what it cannot read as an error rather than a panic.
Index ¶
- Constants
- Variables
- func Format(o Object) string
- func Int(o Object) (int, bool)
- func Num(o Object) (float64, bool)
- func Ops(content []byte, yield func(Op) bool)
- type Array
- type Dict
- type Document
- func (d *Document) Array(o Object) Array
- func (d *Document) ContentOf(o Object) []byte
- func (d *Document) Dict(o Object) Dict
- func (d *Document) Int(o Object) (int, bool)
- func (d *Document) Name(o Object) Name
- func (d *Document) Num(o Object) (float64, bool)
- func (d *Document) Pages() []*Page
- func (d *Document) Resolve(o Object) Object
- func (d *Document) Stream(o Object) *Stream
- func (d *Document) Trailer() Dict
- type Keyword
- type Name
- type Object
- type Op
- type Page
- type Ref
- type Stream
- type String
Constants ¶
const MaxFile = 512 << 20
MaxFile bounds the size of a PDF Open reads into memory.
const MaxStream = 256 << 20
MaxStream bounds how large one stream may decode to, so a small compressed stream cannot exhaust memory.
Variables ¶
var ErrImageData = errors.New("pdf: image-encoded stream")
ErrImageData is returned when a stream is encoded with an image filter, whose data this package does not decode.
var ErrPassword = errors.New("pdf: incorrect password")
ErrPassword is returned when an encrypted document opens with neither the empty password nor the one given.
Functions ¶
Types ¶
type Document ¶
type Document struct {
// Repaired says the cross reference data was unreadable and objects were
// found by scanning the file instead.
Repaired bool
// contains filtered or unexported fields
}
Document is an opened PDF.
func Open ¶
Open reads a PDF. Password is tried as the user and then the owner password; most encrypted files open with the empty one.
func (*Document) ContentOf ¶
ContentOf decodes and joins a Contents value: one stream or an array of them. Streams that fail to decode contribute what decoded.
func (*Document) Dict ¶
Dict resolves o and returns it as a dictionary, or nil. A stream yields its dictionary.
func (*Document) Pages ¶
Pages returns the document's pages in order. A page tree too damaged to walk falls back to every page object in the file, as pdfminer does.
func (*Document) Resolve ¶
Resolve follows references until it reaches a direct object. A missing or unreadable object resolves to nil, as PDF readers must treat it.
type Object ¶
type Object any
Object is a PDF object: nil (null), bool, int, float64, String, Name, Array, Dict, *Stream, Ref, or, in content streams only, Keyword.
type Op ¶
type Op struct {
Name Keyword
Args []Object
// Inline is the dictionary of an inline image (operator "BI"), whose
// data has been skipped.
Inline Dict
}
Op is one operator in a content stream, with its operands.
type Page ¶
type Page struct {
Dict Dict
Resources Dict
MediaBox [4]float64
CropBox [4]float64
Rotate int // 0, 90, 180 or 270
// contains filtered or unexported fields
}
Page is one page of a document, with its inherited attributes resolved.
type Ref ¶
type Ref struct{ Num, Gen int }
Ref is an indirect reference to object Num, generation Gen.
type Stream ¶
type Stream struct {
Dict Dict
// contains filtered or unexported fields
}
Stream is a stream object: its dictionary and its still-encoded data.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package extract runs a page's content streams and collects every character drawn, positioned and sized, as layout input.
|
Package extract runs a page's content streams and collects every character drawn, positioned and sized, as layout input. |
|
Package font maps the bytes a PDF shows to text and glyph geometry: it decodes character codes, maps them to Unicode (ToUnicode CMaps, simple encodings with Differences, embedded font tables), and supplies widths, descent and vertical displacement.
|
Package font maps the bytes a PDF shows to text and glyph geometry: it decodes character codes, maps them to Unicode (ToUnicode CMaps, simple encodings with Differences, embedded font tables), and supplies widths, descent and vertical displacement. |
|
Package layout groups positioned characters into words, lines and text boxes, and orders the boxes for reading.
|
Package layout groups positioned characters into words, lines and text boxes, and orders the boxes for reading. |
|
Package table finds ruled tables on a PDF page: tables whose cells are drawn with lines or rectangles.
|
Package table finds ruled tables on a PDF page: tables whose cells are drawn with lines or rectangles. |