Documentation
¶
Overview ¶
Package syntax reads the PDF file format: objects, cross references, object streams, damaged file recovery, the stream filters and encryption.
Index ¶
- Constants
- Variables
- type Array
- type BitReader
- type Bool
- type Dict
- type File
- func (f *File) Catalog() Dict
- func (f *File) Close() error
- func (f *File) DecodeImageData(dict Dict, data []byte) ([]byte, Name, Dict, error)
- func (f *File) Err() []error
- func (f *File) GetArray(o Object) Array
- func (f *File) GetBool(o Object, def bool) bool
- func (f *File) GetBytes(o Object) []byte
- func (f *File) GetDict(o Object) Dict
- func (f *File) GetFloat(o Object, def float64) float64
- func (f *File) GetFloats(o Object) []float64
- func (f *File) GetInt(o Object, def int64) int64
- func (f *File) GetName(o Object) Name
- func (f *File) GetNames(o Object) []Name
- func (f *File) GetStream(o Object) *Stream
- func (f *File) Lookup(dict Dict, keys ...Name) Object
- func (f *File) NameTreeLookup(root Object, key string) Object
- func (f *File) NumPages() int
- func (f *File) NumberTreeEach(root Object, fn func(int64, Object) bool)
- func (f *File) Page(i int) Dict
- func (f *File) PageIndex(r Ref) int
- func (f *File) PageRef(i int) Ref
- func (f *File) Repaired() bool
- func (f *File) Resolve(o Object) Object
- func (f *File) Trailer() Dict
- type Integer
- type Keyword
- type Lexer
- type MQ
- type Name
- type Object
- type Operand
- type Parser
- type Real
- type Ref
- type Stream
- type String
Constants ¶
const DefaultStreamCacheBytes = 1 << 26
DefaultStreamCacheBytes is the default bound of a file's decoded stream cache.
Variables ¶
var ( ErrInvalid = errors.New("pdf: invalid file") ErrUnsupported = errors.New("pdf: unsupported file") ErrPassword = errors.New("pdf: wrong password") )
ErrInvalid is returned for a file that is not a PDF or cannot be recovered, ErrUnsupported for a well formed file this package cannot handle.
Functions ¶
This section is empty.
Types ¶
type BitReader ¶
type BitReader struct {
// contains filtered or unexported fields
}
BitReader reads MSB-first fields.
type Dict ¶
Dict is a PDF dictionary; a null value is a missing key, ISO 32000-1 7.3.9.
type File ¶
type File struct {
// StreamCacheBytes bounds the decoded stream data kept: zero is
// DefaultStreamCacheBytes, negative is none.
StreamCacheBytes int
// contains filtered or unexported fields
}
File is an open PDF file.
func NewReaderPassword ¶
NewReaderPassword reads size bytes from r, decrypting with password.
func OpenPassword ¶
OpenPassword reads the named file, which is encrypted with password.
func (*File) Close ¶
Close releases the file. It must not be called while anything is still reading it.
func (*File) DecodeImageData ¶
DecodeImageData applies the byte filters dict names to data and returns the bytes, the remaining image filter and its parameters.
func (*File) Err ¶
Err returns the errors recorded while reading the file. It is safe to call while other goroutines are reading the same file.
func (*File) GetDict ¶
GetDict resolves o and returns it, or a stream's dictionary, as a dictionary, or nil.
func (*File) NameTreeLookup ¶
NameTreeLookup finds a key in a name tree, ISO 32000-1 7.9.6, and returns nil for one that is not there.
func (*File) NumberTreeEach ¶
NumberTreeEach calls fn for every entry of a number tree in order, ISO 32000-1 7.9.7, and stops when fn returns false.
func (*File) Page ¶
Page returns the dictionary of page i, counting from zero, with the inheritable attributes of its ancestors filled in.
type Keyword ¶
type Keyword string
Keyword is a bare token: an operator, or one of the structural words such as obj, endobj, stream or R. It is not a PDF object type.
type Lexer ¶
type Lexer struct {
// contains filtered or unexported fields
}
Lexer tokenizes PDF syntax. The whole file is in memory, so a token is a slice of it and scanning is a pointer walk.
func NewLexer ¶
NewLexer reads the tokens of a PDF out of a buffer. The content stream interpreter tokenizes with the same code, which is why this is exported.
type MQ ¶
type MQ struct {
// contains filtered or unexported fields
}
MQ decodes a decision at a time against a caller supplied context array, in which each entry packs the state index in its high seven bits and the more probable symbol in its low one. JBIG2 and JPEG 2000 both read it.
type Object ¶
type Object interface {
// contains filtered or unexported methods
}
Object is a PDF object. The concrete types are Bool, Integer, Real, String, Name, Array, Dict, Ref and *Stream. A nil Object is the null object.
type Operand ¶
type Operand struct {
// Num is the value when Obj is nil.
Num float64
// Whole is the exact value of an integer, which Num only rounds once it
// runs past what a float64 counts one by one.
Whole int64
// IsInt reports that the number was written without a fraction, which is
// what tells an object number from a coordinate.
IsInt bool
// IsNum says the operand is the number rather than Obj. It is not the same
// question as whether Obj is nil, because nil is the null object.
IsNum bool
// Obj is the token when it is anything but a number.
Obj Object
}
An Operand is one token, a number left as a number rather than boxed into an Object, because a content stream is almost all numbers and boxing costs.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser turns tokens into objects with two tokens of lookahead.
func NewParser ¶
NewParser reads objects from a lexer, resolving references against f, which may be nil.
func (*Parser) AllowStreams ¶
AllowStreams sets whether a stream keyword may follow a dictionary.
func (*Parser) Operand ¶
Operand reads one item of a content stream's operand list, a number unboxed.
type Stream ¶
Stream is a PDF stream: a dictionary and the bytes that follow it.
func (*Stream) ImageData ¶
ImageData returns the stream contents with every byte filter applied, plus the image filter that remains and its parameters, if any.
func (*Stream) ImageDataLimit ¶ added in v0.2.8
ImageDataLimit is ImageData decoding no more than limit bytes, and not cached.
func (*Stream) ImageReader ¶ added in v0.3.0
func (s *Stream) ImageReader(limit int) (io.ReadCloser, bool)
ImageReader is ImageDataLimit as a reader, for a stream whose last filter is FlateDecode or LZWDecode and that leaves no image filter: it holds the compressed bytes and no more. It declines any other stream, and one whose inflation fails before it yields a byte, which ImageDataLimit then reports.