filters

package
v1.6.6 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package filters provides PDF stream decompression filters.

PDF streams can be compressed using various algorithms. This package implements the standard PDF decompression filters.

Supported Filters

FlateDecode (zlib/deflate):

decoded, err := filters.FlateDecode(data, params)

FlateDecode supports PNG predictors for improved compression of image data. The Predictor parameter specifies the algorithm:

  • 1: No prediction (default)
  • 2: TIFF Predictor 2
  • 10-15: PNG predictors (None, Sub, Up, Average, Paeth)

ASCIIHexDecode:

decoded, err := filters.ASCIIHexDecode(data)

Decodes hexadecimal-encoded data. Whitespace is ignored.

ASCII85Decode:

decoded, err := filters.ASCII85Decode(data)

Decodes ASCII base-85 encoded data (also known as Ascii85).

Decode Parameters

Filters accept a Params map for additional parameters:

params := filters.Params{
    "Predictor": 12,
    "Columns":   100,
    "Colors":    3,
}
decoded, err := filters.FlateDecode(data, params)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ASCII85Decode

func ASCII85Decode(data []byte) ([]byte, error)

ASCII85Decode decodes ASCII base-85 (Ascii85) encoded data. Each group of 5 ASCII characters (! to u, values 33-117) represents 4 bytes. The special character 'z' represents four zero bytes. The sequence ~> marks end of data.

func ASCIIHexDecode

func ASCIIHexDecode(data []byte) ([]byte, error)

ASCIIHexDecode decodes ASCII hexadecimal encoded data. Each pair of hexadecimal digits (0-9, A-F, a-f) represents one byte. Whitespace is ignored, and > marks end of data.

func CCITTFaxDecode added in v1.6.0

func CCITTFaxDecode(data []byte, params Params) ([]byte, error)

CCITTFaxDecode decodes CCITT Group 3/4 fax compressed data. This is commonly used for bi-level (black and white) images in PDFs, particularly for scanned documents.

Parameters from the PDF decode parameters dictionary:

  • K: Group selector (-1=Group4, 0=Group3 1D, >0=Group3 2D)
  • Columns: Image width in pixels (default 1728)
  • Rows: Image height in pixels (default 0, uses AutoDetectHeight)
  • BlackIs1: Bit interpretation (default false, maps to ccitt.Options.Invert)

func FlateDecode

func FlateDecode(data []byte, params Params) ([]byte, error)

FlateDecode decompresses Flate (zlib/deflate) compressed data. This is the most common compression filter in PDFs. It optionally applies a predictor algorithm for image data decompression.

Types

type Params

type Params map[string]interface{}

Params represents decode parameters from PDF stream dictionaries. Common parameters include Predictor, Columns, Colors, and BitsPerComponent.

Jump to

Keyboard shortcuts

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