filter

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2026 License: Apache-2.0 Imports: 15 Imported by: 38

Documentation

Overview

Package filter contains PDF filter implementations.

Index

Constants

View Source
const (
	ASCII85   = "ASCII85Decode"
	ASCIIHex  = "ASCIIHexDecode"
	RunLength = "RunLengthDecode"
	LZW       = "LZWDecode"
	Flate     = "FlateDecode"
	CCITTFax  = "CCITTFaxDecode"
	JBIG2     = "JBIG2Decode" // TODO
	DCT       = "DCTDecode"
	JPX       = "JPXDecode" // TODO
)

PDF defines the following filters. See also 7.4 in the PDF spec.

View Source
const (
	// PredictorNo disables prediction.
	PredictorNo = 1

	// PredictorTIFF applies TIFF prediction to every row.
	PredictorTIFF = 2

	// PredictorNone applies the PNG none filter to every row.
	PredictorNone = 10

	// PredictorSub applies the PNG sub filter to every row.
	PredictorSub = 11

	// PredictorUp applies the PNG up filter to every row.
	PredictorUp = 12

	// PredictorAverage applies the PNG average filter to every row.
	PredictorAverage = 13

	// PredictorPaeth applies the PNG Paeth filter to every row.
	PredictorPaeth = 14

	// PredictorOptimum selects the optimum PNG filter for each row.
	PredictorOptimum = 15
)

PDF allows a prediction step prior to compression applying TIFF or PNG prediction. Predictor algorithm.

View Source
const (
	// PNGNone identifies the PNG none filter.
	PNGNone = 0x00

	// PNGSub identifies the PNG sub filter.
	PNGSub = 0x01

	// PNGUp identifies the PNG up filter.
	PNGUp = 0x02

	// PNGAverage identifies the PNG average filter.
	PNGAverage = 0x03

	// PNGPaeth identifies the PNG Paeth filter.
	PNGPaeth = 0x04
)

For predictor > 2 PNG filters (see RFC 2083) get applied and the first byte of each pixelrow defines the prediction algorithm used for all pixels of this row.

View Source
const DefaultMaxDecodeBytes int64 = 512 << 20 // 512 MiB

Variables

View Source
var ErrDecodeLimitExceeded = errors.New("filter decode limit exceeded")

ErrDecodeLimitExceeded signals that decoded filter output exceeds the configured decode limit.

View Source
var ErrUnsupportedFilter = errors.New("filter not supported")

ErrUnsupportedFilter signals unsupported filter encountered.

Functions

func IsCorruptFlateInput added in v0.14.0

func IsCorruptFlateInput(err error) bool

IsCorruptFlateInput reports whether err contains a Flate corrupt-input error.

func List

func List() []string

List return the list of all supported PDF filters.

func SupportsDecodeParms added in v0.9.0

func SupportsDecodeParms(f string) bool

SupportsDecodeParms returns true if filterName supports decode parameters.

Types

type Filter

type Filter interface {
	Encode(r io.Reader) (io.Reader, error)
	Decode(r io.Reader) (io.Reader, error)
	// DecodeLength will decode at least maxLen bytes. For filters where decoding
	// parts doesn't make sense (e.g. DCT), the whole stream is decoded.
	// If maxLen < 0 is passed, the whole stream is decoded.
	DecodeLength(r io.Reader, maxLen int64) (io.Reader, error)
}

Filter defines an interface for encoding/decoding PDF object streams.

func NewFilter

func NewFilter(filterName string, parms map[string]int, maxDecodeBytes ...int64) (filter Filter, err error)

NewFilter returns a filter for given filterName and an optional parameter dictionary.

Jump to

Keyboard shortcuts

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