unidoc: github.com/unidoc/unidoc/pdf/core Index | Files

package core

import "github.com/unidoc/unidoc/pdf/core"

Package core defines and implements the primitive PDF object types in golang, and provides functionality for parsing those from a PDF file stream. This includes I/O handling, cross references, repairs, encryption, encoding and other core capabilities.

Index

Package Files

const.go crossrefs.go crypt.go crypt_filters.go doc.go ecb.go encoding.go io.go parser.go primitives.go repairs.go stream.go symbols.go utils.go

Constants

const (
    // XREF_TABLE_ENTRY indicates a normal xref table entry.
    XREF_TABLE_ENTRY = iota

    // XREF_OBJECT_STREAM indicates an xref entry in an xref object stream.
    XREF_OBJECT_STREAM = iota
)

TODO (v3): Create a new type xrefType which can be an integer and can be used for improved type checking. TODO (v3): Unexport these constants and rename with camelCase.

const (
    CryptFilterNone  = "None"  // do not decrypt data
    CryptFilterV2    = "V2"    // RC4-based filter
    CryptFilterAESV2 = "AESV2" // AES-based filter (128 bit key, PDF 1.6)
    CryptFilterAESV3 = "AESV3" // AES-based filter (256 bit key, PDF 2.0)
)

Encryption filters names. Table 25, CFM (page 92)

const (
    StreamEncodingFilterNameFlate     = "FlateDecode"
    StreamEncodingFilterNameLZW       = "LZWDecode"
    StreamEncodingFilterNameDCT       = "DCTDecode"
    StreamEncodingFilterNameRunLength = "RunLengthDecode"
    StreamEncodingFilterNameASCIIHex  = "ASCIIHexDecode"
    StreamEncodingFilterNameASCII85   = "ASCII85Decode"
    StreamEncodingFilterNameCCITTFax  = "CCITTFaxDecode"
    StreamEncodingFilterNameJBIG2     = "JBIG2Decode"
    StreamEncodingFilterNameJPX       = "JPXDecode"
    StreamEncodingFilterNameRaw       = "Raw"
)
const (
    DefaultJPEGQuality = 75
)
const StandardCryptFilter = "StdCF"

StandardCryptFilter is a default name for a standard crypt filter.

const TraceMaxDepth = 20

TraceMaxDepth specifies the maximum recursion depth allowed.

Variables

var (
    // ErrUnsupportedEncodingParameters error indicates that encoding/decoding was attempted with unsupported
    // encoding parameters.
    // For example when trying to encode with an unsupported Predictor (flate).
    ErrUnsupportedEncodingParameters = errors.New("Unsupported encoding parameters")
    ErrNoCCITTFaxDecode              = errors.New("CCITTFaxDecode encoding is not yet implemented")
    ErrNoJBIG2Decode                 = errors.New("JBIG2Decode encoding is not yet implemented")
    ErrNoJPXDecode                   = errors.New("JPXDecode encoding is not yet implemented")
)

func DecodeStream Uses

func DecodeStream(streamObj *PdfObjectStream) ([]byte, error)

DecodeStream decodes the stream data and returns the decoded data. An error is returned upon failure.

func EncodeStream Uses

func EncodeStream(streamObj *PdfObjectStream) error

EncodeStream encodes the stream data using the encoded specified by the stream's dictionary.

func IsDecimalDigit Uses

func IsDecimalDigit(c byte) bool

IsDecimalDigit checks if the character is a part of a decimal number string. TODO (v3): Unexport.

func IsDelimiter Uses

func IsDelimiter(char byte) bool

IsDelimiter checks if a character represents a delimiter. TODO (v3): Unexport.

func IsFloatDigit Uses

func IsFloatDigit(c byte) bool

IsFloatDigit checks if a character can be a part of a float number string. TODO (v3): Unexport.

func IsOctalDigit Uses

func IsOctalDigit(c byte) bool

IsOctalDigit checks if a character can be part of an octal digit string. TODO (v3): Unexport.

func IsPrintable Uses

func IsPrintable(char byte) bool

IsPrintable checks if a character is printable. Regular characters that are outside the range EXCLAMATION MARK(21h) (!) to TILDE (7Eh) (~) should be written using the hexadecimal notation. TODO (v3): Unexport.

func IsWhiteSpace Uses

func IsWhiteSpace(ch byte) bool

IsWhiteSpace checks if byte represents a white space character. TODO (v3): Unexport.

type ASCII85Encoder Uses

type ASCII85Encoder struct {
}

ASCII85 encoder/decoder.

func NewASCII85Encoder Uses

func NewASCII85Encoder() *ASCII85Encoder

Make a new ASCII85 encoder.

func (*ASCII85Encoder) DecodeBytes Uses

func (this *ASCII85Encoder) DecodeBytes(encoded []byte) ([]byte, error)

5 ASCII characters -> 4 raw binary bytes

func (*ASCII85Encoder) DecodeStream Uses

func (this *ASCII85Encoder) DecodeStream(streamObj *PdfObjectStream) ([]byte, error)

ASCII85 stream decoding.

func (*ASCII85Encoder) EncodeBytes Uses

func (this *ASCII85Encoder) EncodeBytes(data []byte) ([]byte, error)

Encode data into ASCII85 encoded format.

func (*ASCII85Encoder) GetFilterName Uses

func (this *ASCII85Encoder) GetFilterName() string

func (*ASCII85Encoder) MakeDecodeParams Uses

func (this *ASCII85Encoder) MakeDecodeParams() PdfObject

func (*ASCII85Encoder) MakeStreamDict Uses

func (this *ASCII85Encoder) MakeStreamDict() *PdfObjectDictionary

Make a new instance of an encoding dictionary for a stream object.

type ASCIIHexEncoder Uses

type ASCIIHexEncoder struct {
}

/// ASCII hex encoder/decoder.

func NewASCIIHexEncoder Uses

func NewASCIIHexEncoder() *ASCIIHexEncoder

Make a new ASCII hex encoder.

func (*ASCIIHexEncoder) DecodeBytes Uses

func (this *ASCIIHexEncoder) DecodeBytes(encoded []byte) ([]byte, error)

func (*ASCIIHexEncoder) DecodeStream Uses

func (this *ASCIIHexEncoder) DecodeStream(streamObj *PdfObjectStream) ([]byte, error)

ASCII hex decoding.

func (*ASCIIHexEncoder) EncodeBytes Uses

func (this *ASCIIHexEncoder) EncodeBytes(data []byte) ([]byte, error)

func (*ASCIIHexEncoder) GetFilterName Uses

func (this *ASCIIHexEncoder) GetFilterName() string

func (*ASCIIHexEncoder) MakeDecodeParams Uses

func (this *ASCIIHexEncoder) MakeDecodeParams() PdfObject

func (*ASCIIHexEncoder) MakeStreamDict Uses

func (this *ASCIIHexEncoder) MakeStreamDict() *PdfObjectDictionary

Make a new instance of an encoding dictionary for a stream object.

type AccessPermissions Uses

type AccessPermissions struct {
    Printing        bool
    Modify          bool
    ExtractGraphics bool
    Annotate        bool

    // Allow form filling, if annotation is disabled?  If annotation enabled, is not looked at.
    FillForms         bool
    DisabilityExtract bool // not clear what this means!

    // Allow rotating, editing page order.
    RotateInsert bool

    // Limit print quality (lowres), assuming Printing is true.
    FullPrintQuality bool
}

AccessPermissions is a list of access permissions for a PDF file.

func (AccessPermissions) GetP Uses

func (perms AccessPermissions) GetP() int32

GetP returns the P entry to be used in Encrypt dictionary based on AccessPermissions settings.

type CCITTFaxEncoder Uses

type CCITTFaxEncoder struct{}

CCITTFax encoder/decoder (dummy, for now)

func NewCCITTFaxEncoder Uses

func NewCCITTFaxEncoder() *CCITTFaxEncoder

func (*CCITTFaxEncoder) DecodeBytes Uses

func (this *CCITTFaxEncoder) DecodeBytes(encoded []byte) ([]byte, error)

func (*CCITTFaxEncoder) DecodeStream Uses

func (this *CCITTFaxEncoder) DecodeStream(streamObj *PdfObjectStream) ([]byte, error)

func (*CCITTFaxEncoder) EncodeBytes Uses

func (this *CCITTFaxEncoder) EncodeBytes(data []byte) ([]byte, error)

func (*CCITTFaxEncoder) GetFilterName Uses

func (this *CCITTFaxEncoder) GetFilterName() string

func (*CCITTFaxEncoder) MakeDecodeParams Uses

func (this *CCITTFaxEncoder) MakeDecodeParams() PdfObject

func (*CCITTFaxEncoder) MakeStreamDict Uses

func (this *CCITTFaxEncoder) MakeStreamDict() *PdfObjectDictionary

Make a new instance of an encoding dictionary for a stream object.

type CryptFilter Uses

type CryptFilter struct {
    Cfm    string
    Length int
    // contains filtered or unexported fields
}

CryptFilter represents information from a CryptFilter dictionary. TODO (v3): Replace with cryptFilterMethod interface.

func NewCryptFilterAESV2 Uses

func NewCryptFilterAESV2() CryptFilter

NewCryptFilterAESV2 creates an AES-based filter with a 128 bit key (AESV2).

func NewCryptFilterAESV3 Uses

func NewCryptFilterAESV3() CryptFilter

NewCryptFilterAESV3 creates an AES-based filter with a 256 bit key (AESV3).

func NewCryptFilterV2 Uses

func NewCryptFilterV2(length int) CryptFilter

NewCryptFilterV2 creates a RC4-based filter with a specified key length (in bytes).

type CryptFilters Uses

type CryptFilters map[string]CryptFilter

CryptFilters is a map of crypt filter name and underlying CryptFilter info. TODO (v3): Unexport.

type DCTEncoder Uses

type DCTEncoder struct {
    ColorComponents  int // 1 (gray), 3 (rgb), 4 (cmyk)
    BitsPerComponent int // 8 or 16 bit
    Width            int
    Height           int
    Quality          int
}

DCT (JPG) encoding/decoding functionality for images.

func NewDCTEncoder Uses

func NewDCTEncoder() *DCTEncoder

Make a new DCT encoder with default parameters.

func (*DCTEncoder) DecodeBytes Uses

func (this *DCTEncoder) DecodeBytes(encoded []byte) ([]byte, error)

func (*DCTEncoder) DecodeStream Uses

func (this *DCTEncoder) DecodeStream(streamObj *PdfObjectStream) ([]byte, error)

func (*DCTEncoder) EncodeBytes Uses

func (this *DCTEncoder) EncodeBytes(data []byte) ([]byte, error)

func (*DCTEncoder) GetFilterName Uses

func (this *DCTEncoder) GetFilterName() string

func (*DCTEncoder) MakeDecodeParams Uses

func (this *DCTEncoder) MakeDecodeParams() PdfObject

func (*DCTEncoder) MakeStreamDict Uses

func (this *DCTEncoder) MakeStreamDict() *PdfObjectDictionary

Make a new instance of an encoding dictionary for a stream object. Has the Filter set. Some other parameters are generated elsewhere.

type DrawableImage Uses

type DrawableImage interface {
    ColorModel() gocolor.Model
    Bounds() goimage.Rectangle
    At(x, y int) gocolor.Color
    Set(x, y int, c gocolor.Color)
}

type FlateEncoder Uses

type FlateEncoder struct {
    Predictor        int
    BitsPerComponent int
    // For predictors
    Columns int
    Colors  int
}

Flate encoding.

func NewFlateEncoder Uses

func NewFlateEncoder() *FlateEncoder

Make a new flate encoder with default parameters, predictor 1 and bits per component 8.

func (*FlateEncoder) DecodeBytes Uses

func (this *FlateEncoder) DecodeBytes(encoded []byte) ([]byte, error)

func (*FlateEncoder) DecodeStream Uses

func (this *FlateEncoder) DecodeStream(streamObj *PdfObjectStream) ([]byte, error)

Decode a FlateEncoded stream object and give back decoded bytes.

func (*FlateEncoder) EncodeBytes Uses

func (this *FlateEncoder) EncodeBytes(data []byte) ([]byte, error)

Encode a bytes array and return the encoded value based on the encoder parameters.

func (*FlateEncoder) GetFilterName Uses

func (this *FlateEncoder) GetFilterName() string

func (*FlateEncoder) MakeDecodeParams Uses

func (this *FlateEncoder) MakeDecodeParams() PdfObject

func (*FlateEncoder) MakeStreamDict Uses

func (this *FlateEncoder) MakeStreamDict() *PdfObjectDictionary

Make a new instance of an encoding dictionary for a stream object. Has the Filter set and the DecodeParms.

func (*FlateEncoder) SetPredictor Uses

func (this *FlateEncoder) SetPredictor(columns int)

Set the predictor function. Specify the number of columns per row. The columns indicates the number of samples per row. Used for grouping data together for compression.

type JBIG2Encoder Uses

type JBIG2Encoder struct{}

JBIG2 encoder/decoder (dummy, for now)

func NewJBIG2Encoder Uses

func NewJBIG2Encoder() *JBIG2Encoder

func (*JBIG2Encoder) DecodeBytes Uses

func (this *JBIG2Encoder) DecodeBytes(encoded []byte) ([]byte, error)

func (*JBIG2Encoder) DecodeStream Uses

func (this *JBIG2Encoder) DecodeStream(streamObj *PdfObjectStream) ([]byte, error)

func (*JBIG2Encoder) EncodeBytes Uses

func (this *JBIG2Encoder) EncodeBytes(data []byte) ([]byte, error)

func (*JBIG2Encoder) GetFilterName Uses

func (this *JBIG2Encoder) GetFilterName() string

func (*JBIG2Encoder) MakeDecodeParams Uses

func (this *JBIG2Encoder) MakeDecodeParams() PdfObject

func (*JBIG2Encoder) MakeStreamDict Uses

func (this *JBIG2Encoder) MakeStreamDict() *PdfObjectDictionary

Make a new instance of an encoding dictionary for a stream object.

type JPXEncoder Uses

type JPXEncoder struct{}

JPX encoder/decoder (dummy, for now)

func NewJPXEncoder Uses

func NewJPXEncoder() *JPXEncoder

func (*JPXEncoder) DecodeBytes Uses

func (this *JPXEncoder) DecodeBytes(encoded []byte) ([]byte, error)

func (*JPXEncoder) DecodeStream Uses

func (this *JPXEncoder) DecodeStream(streamObj *PdfObjectStream) ([]byte, error)

func (*JPXEncoder) EncodeBytes Uses

func (this *JPXEncoder) EncodeBytes(data []byte) ([]byte, error)

func (*JPXEncoder) GetFilterName Uses

func (this *JPXEncoder) GetFilterName() string

func (*JPXEncoder) MakeDecodeParams Uses

func (this *JPXEncoder) MakeDecodeParams() PdfObject

func (*JPXEncoder) MakeStreamDict Uses

func (this *JPXEncoder) MakeStreamDict() *PdfObjectDictionary

Make a new instance of an encoding dictionary for a stream object.

type LZWEncoder Uses

type LZWEncoder struct {
    Predictor        int
    BitsPerComponent int
    // For predictors
    Columns int
    Colors  int
    // LZW algorithm setting.
    EarlyChange int
}

LZW encoding/decoding functionality.

func NewLZWEncoder Uses

func NewLZWEncoder() *LZWEncoder

Make a new LZW encoder with default parameters.

func (*LZWEncoder) DecodeBytes Uses

func (this *LZWEncoder) DecodeBytes(encoded []byte) ([]byte, error)

func (*LZWEncoder) DecodeStream Uses

func (this *LZWEncoder) DecodeStream(streamObj *PdfObjectStream) ([]byte, error)

func (*LZWEncoder) EncodeBytes Uses

func (this *LZWEncoder) EncodeBytes(data []byte) ([]byte, error)

Support for encoding LZW. Currently not supporting predictors (raw compressed data only). Only supports the Early change = 1 algorithm (compress/lzw) as the other implementation does not have a write method. TODO: Consider refactoring compress/lzw to allow both.

func (*LZWEncoder) GetFilterName Uses

func (this *LZWEncoder) GetFilterName() string

func (*LZWEncoder) MakeDecodeParams Uses

func (this *LZWEncoder) MakeDecodeParams() PdfObject

func (*LZWEncoder) MakeStreamDict Uses

func (this *LZWEncoder) MakeStreamDict() *PdfObjectDictionary

Make a new instance of an encoding dictionary for a stream object. Has the Filter set and the DecodeParms.

type MultiEncoder Uses

type MultiEncoder struct {
    // contains filtered or unexported fields
}

Multi encoder: support serial encoding.

func NewMultiEncoder Uses

func NewMultiEncoder() *MultiEncoder

func (*MultiEncoder) AddEncoder Uses

func (this *MultiEncoder) AddEncoder(encoder StreamEncoder)

func (*MultiEncoder) DecodeBytes Uses

func (this *MultiEncoder) DecodeBytes(encoded []byte) ([]byte, error)

func (*MultiEncoder) DecodeStream Uses

func (this *MultiEncoder) DecodeStream(streamObj *PdfObjectStream) ([]byte, error)

func (*MultiEncoder) EncodeBytes Uses

func (this *MultiEncoder) EncodeBytes(data []byte) ([]byte, error)

func (*MultiEncoder) GetFilterName Uses

func (this *MultiEncoder) GetFilterName() string

func (*MultiEncoder) MakeDecodeParams Uses

func (this *MultiEncoder) MakeDecodeParams() PdfObject

func (*MultiEncoder) MakeStreamDict Uses

func (this *MultiEncoder) MakeStreamDict() *PdfObjectDictionary

type ObjectCache Uses

type ObjectCache map[int]PdfObject

ObjectCache defines a map between object numbers and corresponding PdfObject. Serves as a cache for PdfObjects that have already been parsed. TODO (v3): Unexport.

type ObjectStream Uses

type ObjectStream struct {
    N int // TODO (v3): Unexport.
    // contains filtered or unexported fields
}

ObjectStream represents an object stream's information which can contain multiple indirect objects. The information specifies the number of objects and has information about offset locations for each object. TODO (v3): Unexport.

type ObjectStreams Uses

type ObjectStreams map[int]ObjectStream

ObjectStreams defines a map between object numbers (object streams only) and underlying ObjectStream information.

type PdfCrypt Uses

type PdfCrypt struct {
    Filter           string
    Subfilter        string
    V                int
    Length           int
    R                int
    O                []byte
    U                []byte
    OE               []byte // R=6
    UE               []byte // R=6
    P                int    // TODO (v3): uint32
    Perms            []byte // R=6
    EncryptMetadata  bool
    Id0              string
    EncryptionKey    []byte
    DecryptedObjects map[PdfObject]bool
    EncryptedObjects map[PdfObject]bool
    Authenticated    bool
    // Crypt filters (V4).
    CryptFilters CryptFilters
    StreamFilter string
    StringFilter string
    // contains filtered or unexported fields
}

PdfCrypt provides PDF encryption/decryption support. The PDF standard supports encryption of strings and streams (Section 7.6). TODO (v3): Consider unexporting.

func PdfCryptMakeNew Uses

func PdfCryptMakeNew(parser *PdfParser, ed, trailer *PdfObjectDictionary) (PdfCrypt, error)

PdfCryptMakeNew makes the document crypt handler based on the encryption dictionary and trailer dictionary. Returns an error on failure to process.

func (*PdfCrypt) Alg2 Uses

func (crypt *PdfCrypt) Alg2(pass []byte) []byte

Alg2 computes an encryption key. TODO (v3): Unexport.

func (*PdfCrypt) Alg3 Uses

func (crypt *PdfCrypt) Alg3(upass, opass []byte) (PdfObjectString, error)

Alg3 computes the encryption dictionary’s O (owner password) value. TODO (v3): Unexport.

func (*PdfCrypt) Alg4 Uses

func (crypt *PdfCrypt) Alg4(upass []byte) (PdfObjectString, []byte, error)

Alg4 computes the encryption dictionary’s U (user password) value (Security handlers of revision 2). TODO (v3): Unexport.

func (*PdfCrypt) Alg5 Uses

func (crypt *PdfCrypt) Alg5(upass []byte) (PdfObjectString, []byte, error)

Alg5 computes the encryption dictionary’s U (user password) value (Security handlers of revision 3 or greater). TODO (v3): Unexport.

func (*PdfCrypt) Alg6 Uses

func (crypt *PdfCrypt) Alg6(upass []byte) (bool, error)

Alg6 authenticates the user password. TODO (v3): Unexport.

func (*PdfCrypt) Alg7 Uses

func (crypt *PdfCrypt) Alg7(opass []byte) (bool, error)

Alg7 authenticates the owner password. TODO (v3): Unexport.

func (*PdfCrypt) Decrypt Uses

func (crypt *PdfCrypt) Decrypt(obj PdfObject, parentObjNum, parentGenNum int64) error

Decrypt an object with specified key. For numbered objects, the key argument is not used and a new one is generated based on the object and generation number. Traverses through all the subobjects (recursive).

Does not look up references.. That should be done prior to calling.

func (*PdfCrypt) Encrypt Uses

func (crypt *PdfCrypt) Encrypt(obj PdfObject, parentObjNum, parentGenNum int64) error

Encrypt an object with specified key. For numbered objects, the key argument is not used and a new one is generated based on the object and generation number. Traverses through all the subobjects (recursive).

Does not look up references.. That should be done prior to calling.

func (*PdfCrypt) GenerateParams Uses

func (crypt *PdfCrypt) GenerateParams(upass, opass []byte) error

GenerateParams generates encryption parameters for specified passwords. Can be called only for R>=5.

func (*PdfCrypt) GetAccessPermissions Uses

func (crypt *PdfCrypt) GetAccessPermissions() AccessPermissions

GetAccessPermissions returns the PDF access permissions as an AccessPermissions object.

func (*PdfCrypt) LoadCryptFilters Uses

func (crypt *PdfCrypt) LoadCryptFilters(ed *PdfObjectDictionary) error

LoadCryptFilters loads crypt filter information from the encryption dictionary (V>=4). TODO (v3): Unexport.

func (*PdfCrypt) SaveCryptFilters Uses

func (crypt *PdfCrypt) SaveCryptFilters(ed *PdfObjectDictionary) error

SaveCryptFilters saves crypt filter information to the encryption dictionary (V>=4). TODO (v3): Unexport.

type PdfIndirectObject Uses

type PdfIndirectObject struct {
    PdfObjectReference
    PdfObject
}

PdfIndirectObject represents the primitive PDF indirect object.

func MakeIndirectObject Uses

func MakeIndirectObject(obj PdfObject) *PdfIndirectObject

MakeIndirectObject creates an PdfIndirectObject with a specified direct object PdfObject.

func (*PdfIndirectObject) DefaultWriteString Uses

func (ind *PdfIndirectObject) DefaultWriteString() string

DefaultWriteString outputs the object as it is to be written to file.

func (*PdfIndirectObject) String Uses

func (ind *PdfIndirectObject) String() string

type PdfObject Uses

type PdfObject interface {
    // Output a string representation of the primitive (for debugging).
    String() string

    // Output the PDF primitive as written to file as expected by the standard.
    DefaultWriteString() string
}

PdfObject is an interface which all primitive PDF objects must implement.

func TraceToDirectObject Uses

func TraceToDirectObject(obj PdfObject) PdfObject

TraceToDirectObject traces a PdfObject to a direct object. For example direct objects contained in indirect objects (can be double referenced even).

Note: This function does not trace/resolve references. That needs to be done beforehand.

type PdfObjectArray Uses

type PdfObjectArray []PdfObject

PdfObjectArray represents the primitive PDF array object.

func MakeArray Uses

func MakeArray(objects ...PdfObject) *PdfObjectArray

MakeArray creates an PdfObjectArray from a list of PdfObjects.

func MakeArrayFromFloats Uses

func MakeArrayFromFloats(vals []float64) *PdfObjectArray

MakeArrayFromFloats creates an PdfObjectArray from a slice of float64s, where each array element is an PdfObjectFloat.

func MakeArrayFromIntegers Uses

func MakeArrayFromIntegers(vals []int) *PdfObjectArray

MakeArrayFromIntegers creates an PdfObjectArray from a slice of ints, where each array element is an PdfObjectInteger.

func MakeArrayFromIntegers64 Uses

func MakeArrayFromIntegers64(vals []int64) *PdfObjectArray

MakeArrayFromIntegers64 creates an PdfObjectArray from a slice of int64s, where each array element is an PdfObjectInteger.

func (*PdfObjectArray) Append Uses

func (array *PdfObjectArray) Append(obj PdfObject)

Append adds an PdfObject to the array.

func (*PdfObjectArray) DefaultWriteString Uses

func (array *PdfObjectArray) DefaultWriteString() string

DefaultWriteString outputs the object as it is to be written to file.

func (*PdfObjectArray) GetAsFloat64Slice Uses

func (array *PdfObjectArray) GetAsFloat64Slice() ([]float64, error)

GetAsFloat64Slice returns the array as []float64 slice. Returns an error if not entirely numeric (only PdfObjectIntegers, PdfObjectFloats).

func (*PdfObjectArray) String Uses

func (array *PdfObjectArray) String() string

func (*PdfObjectArray) ToFloat64Array Uses

func (array *PdfObjectArray) ToFloat64Array() ([]float64, error)

ToFloat64Array returns a slice of all elements in the array as a float64 slice. An error is returned if the array contains non-numeric objects (each element can be either PdfObjectInteger or PdfObjectFloat).

func (*PdfObjectArray) ToIntegerArray Uses

func (array *PdfObjectArray) ToIntegerArray() ([]int, error)

ToIntegerArray returns a slice of all array elements as an int slice. An error is returned if the array contains non-integer objects. Each element can only be PdfObjectInteger.

type PdfObjectBool Uses

type PdfObjectBool bool

PdfObjectBool represents the primitive PDF boolean object.

func MakeBool Uses

func MakeBool(val bool) *PdfObjectBool

MakeBool creates an PdfObjectBool from a bool.

func (*PdfObjectBool) DefaultWriteString Uses

func (bool *PdfObjectBool) DefaultWriteString() string

DefaultWriteString outputs the object as it is to be written to file.

func (*PdfObjectBool) String Uses

func (bool *PdfObjectBool) String() string

type PdfObjectDictionary Uses

type PdfObjectDictionary struct {
    // contains filtered or unexported fields
}

PdfObjectDictionary represents the primitive PDF dictionary/map object.

func MakeDict Uses

func MakeDict() *PdfObjectDictionary

MakeDict creates and returns an empty PdfObjectDictionary.

func (*PdfObjectDictionary) DefaultWriteString Uses

func (d *PdfObjectDictionary) DefaultWriteString() string

DefaultWriteString outputs the object as it is to be written to file.

func (*PdfObjectDictionary) Get Uses

func (d *PdfObjectDictionary) Get(key PdfObjectName) PdfObject

Get returns the PdfObject corresponding to the specified key. Returns a nil value if the key is not set.

The design is such that we only return 1 value. The reason is that, it will be easy to do type casts such as name, ok := dict.Get("mykey").(*PdfObjectName) if !ok ....

func (*PdfObjectDictionary) Keys Uses

func (d *PdfObjectDictionary) Keys() []PdfObjectName

Keys returns the list of keys in the dictionary.

func (*PdfObjectDictionary) Merge Uses

func (d *PdfObjectDictionary) Merge(another *PdfObjectDictionary)

Merge merges in key/values from another dictionary. Overwriting if has same keys.

func (*PdfObjectDictionary) Remove Uses

func (d *PdfObjectDictionary) Remove(key PdfObjectName)

Remove removes an element specified by key.

func (*PdfObjectDictionary) Set Uses

func (d *PdfObjectDictionary) Set(key PdfObjectName, val PdfObject)

Set sets the dictionary's key -> val mapping entry. Overwrites if key already set.

func (*PdfObjectDictionary) SetIfNotNil Uses

func (d *PdfObjectDictionary) SetIfNotNil(key PdfObjectName, val PdfObject)

SetIfNotNil sets the dictionary's key -> val mapping entry -IF- val is not nil. Note that we take care to perform a type switch. Otherwise if we would supply a nil value of another type, e.g. (PdfObjectArray*)(nil), then it would not be a PdfObject(nil) and thus would get set.

func (*PdfObjectDictionary) String Uses

func (d *PdfObjectDictionary) String() string

type PdfObjectFloat Uses

type PdfObjectFloat float64

PdfObjectFloat represents the primitive PDF floating point numerical object.

func MakeFloat Uses

func MakeFloat(val float64) *PdfObjectFloat

MakeFloat creates an PdfObjectFloat from a float64.

func (*PdfObjectFloat) DefaultWriteString Uses

func (float *PdfObjectFloat) DefaultWriteString() string

DefaultWriteString outputs the object as it is to be written to file.

func (*PdfObjectFloat) String Uses

func (float *PdfObjectFloat) String() string

type PdfObjectInteger Uses

type PdfObjectInteger int64

PdfObjectInteger represents the primitive PDF integer numerical object.

func MakeInteger Uses

func MakeInteger(val int64) *PdfObjectInteger

MakeInteger creates a PdfObjectInteger from an int64.

func (*PdfObjectInteger) DefaultWriteString Uses

func (int *PdfObjectInteger) DefaultWriteString() string

DefaultWriteString outputs the object as it is to be written to file.

func (*PdfObjectInteger) String Uses

func (int *PdfObjectInteger) String() string

type PdfObjectName Uses

type PdfObjectName string

PdfObjectName represents the primitive PDF name object.

func MakeName Uses

func MakeName(s string) *PdfObjectName

MakeName creates a PdfObjectName from a string.

func (*PdfObjectName) DefaultWriteString Uses

func (name *PdfObjectName) DefaultWriteString() string

DefaultWriteString outputs the object as it is to be written to file.

func (*PdfObjectName) String Uses

func (name *PdfObjectName) String() string

type PdfObjectNull Uses

type PdfObjectNull struct{}

PdfObjectNull represents the primitive PDF null object.

func MakeNull Uses

func MakeNull() *PdfObjectNull

MakeNull creates an PdfObjectNull.

func (*PdfObjectNull) DefaultWriteString Uses

func (null *PdfObjectNull) DefaultWriteString() string

DefaultWriteString outputs the object as it is to be written to file.

func (*PdfObjectNull) String Uses

func (null *PdfObjectNull) String() string

type PdfObjectReference Uses

type PdfObjectReference struct {
    ObjectNumber     int64
    GenerationNumber int64
}

PdfObjectReference represents the primitive PDF reference object.

func (*PdfObjectReference) DefaultWriteString Uses

func (ref *PdfObjectReference) DefaultWriteString() string

DefaultWriteString outputs the object as it is to be written to file.

func (*PdfObjectReference) String Uses

func (ref *PdfObjectReference) String() string

type PdfObjectStream Uses

type PdfObjectStream struct {
    PdfObjectReference
    *PdfObjectDictionary
    Stream []byte
}

PdfObjectStream represents the primitive PDF Object stream.

func MakeStream Uses

func MakeStream(contents []byte, encoder StreamEncoder) (*PdfObjectStream, error)

MakeStream creates an PdfObjectStream with specified contents and encoding. If encoding is nil, then raw encoding will be used (i.e. no encoding applied).

func (*PdfObjectStream) DefaultWriteString Uses

func (stream *PdfObjectStream) DefaultWriteString() string

DefaultWriteString outputs the object as it is to be written to file.

func (*PdfObjectStream) String Uses

func (stream *PdfObjectStream) String() string

type PdfObjectString Uses

type PdfObjectString string

PdfObjectString represents the primitive PDF string object. TODO (v3): Change to a struct and add a flag for hex/plaintext.

func MakeString Uses

func MakeString(s string) *PdfObjectString

MakeString creates an PdfObjectString from a string.

func (*PdfObjectString) DefaultWriteString Uses

func (str *PdfObjectString) DefaultWriteString() string

DefaultWriteString outputs the object as it is to be written to file.

func (*PdfObjectString) String Uses

func (str *PdfObjectString) String() string

type PdfParser Uses

type PdfParser struct {
    ObjCache ObjectCache // TODO: Unexport (v3).
    // contains filtered or unexported fields
}

PdfParser parses a PDF file and provides access to the object structure of the PDF.

func NewParser Uses

func NewParser(rs io.ReadSeeker) (*PdfParser, error)

NewParser creates a new parser for a PDF file via ReadSeeker. Loads the cross reference stream and trailer. An error is returned on failure.

func NewParserFromString Uses

func NewParserFromString(txt string) *PdfParser

For testing purposes. TODO: Unexport (v3) or move to test files, if needed by external test cases.

func (*PdfParser) CheckAccessRights Uses

func (parser *PdfParser) CheckAccessRights(password []byte) (bool, AccessPermissions, error)

CheckAccessRights checks access rights and permissions for a specified password. If either user/owner password is specified, full rights are granted, otherwise the access rights are specified by the Permissions flag.

The bool flag indicates that the user can access and view the file. The AccessPermissions shows what access the user has for editing etc. An error is returned if there was a problem performing the authentication.

func (*PdfParser) Decrypt Uses

func (parser *PdfParser) Decrypt(password []byte) (bool, error)

Decrypt attempts to decrypt the PDF file with a specified password. Also tries to decrypt with an empty password. Returns true if successful, false otherwise. An error is returned when there is a problem with decrypting.

func (*PdfParser) GetCrypter Uses

func (parser *PdfParser) GetCrypter() *PdfCrypt

GetCrypter returns the PdfCrypt instance which has information about the PDFs encryption.

func (*PdfParser) GetFileOffset Uses

func (parser *PdfParser) GetFileOffset() int64

Get the current file offset, accounting for buffered position. TODO (v3): Unexport.

func (*PdfParser) GetObjectNums Uses

func (parser *PdfParser) GetObjectNums() []int

GetObjectNums returns a sorted list of object numbers of the PDF objects in the file.

func (*PdfParser) GetTrailer Uses

func (parser *PdfParser) GetTrailer() *PdfObjectDictionary

GetTrailer returns the PDFs trailer dictionary. The trailer dictionary is typically the starting point for a PDF, referencing other key objects that are important in the document structure.

func (*PdfParser) Inspect Uses

func (parser *PdfParser) Inspect() (map[string]int, error)

Inspect analyzes the document object structure.

func (*PdfParser) IsAuthenticated Uses

func (parser *PdfParser) IsAuthenticated() bool

IsAuthenticated returns true if the PDF has already been authenticated for accessing.

func (*PdfParser) IsEncrypted Uses

func (parser *PdfParser) IsEncrypted() (bool, error)

IsEncrypted checks if the document is encrypted. A bool flag is returned indicating the result. First time when called, will check if the Encrypt dictionary is accessible through the trailer dictionary. If encrypted, prepares a crypt datastructure which can be used to authenticate and decrypt the document. On failure, an error is returned.

func (*PdfParser) LookupByNumber Uses

func (parser *PdfParser) LookupByNumber(objNumber int) (PdfObject, error)

LookupByNumber looks up a PdfObject by object number. Returns an error on failure. TODO (v3): Unexport.

func (*PdfParser) LookupByReference Uses

func (parser *PdfParser) LookupByReference(ref PdfObjectReference) (PdfObject, error)

LookupByReference looks up a PdfObject by a reference.

func (*PdfParser) ParseDict Uses

func (parser *PdfParser) ParseDict() (*PdfObjectDictionary, error)

Reads and parses a PDF dictionary object enclosed with '<<' and '>>' TODO: Unexport (v3).

func (*PdfParser) ParseIndirectObject Uses

func (parser *PdfParser) ParseIndirectObject() (PdfObject, error)

Parse an indirect object from the input stream. Can also be an object stream. Returns the indirect object (*PdfIndirectObject) or the stream object (*PdfObjectStream). TODO: Unexport (v3).

func (*PdfParser) ReadAtLeast Uses

func (parser *PdfParser) ReadAtLeast(p []byte, n int) (int, error)

ReadAtLeast reads at least n bytes into slice p. Returns the number of bytes read (should always be == n), and an error on failure. TODO (v3): Unexport.

func (*PdfParser) SetFileOffset Uses

func (parser *PdfParser) SetFileOffset(offset int64)

Seek the file to an offset position. TODO (v3): Unexport.

func (*PdfParser) Trace Uses

func (parser *PdfParser) Trace(obj PdfObject) (PdfObject, error)

Trace traces a PdfObject to direct object, looking up and resolving references as needed (unlike TraceToDirect). TODO (v3): Unexport.

type RawEncoder Uses

type RawEncoder struct{}

Raw encoder/decoder (no encoding, pass through)

func NewRawEncoder Uses

func NewRawEncoder() *RawEncoder

func (*RawEncoder) DecodeBytes Uses

func (this *RawEncoder) DecodeBytes(encoded []byte) ([]byte, error)

func (*RawEncoder) DecodeStream Uses

func (this *RawEncoder) DecodeStream(streamObj *PdfObjectStream) ([]byte, error)

func (*RawEncoder) EncodeBytes Uses

func (this *RawEncoder) EncodeBytes(data []byte) ([]byte, error)

func (*RawEncoder) GetFilterName Uses

func (this *RawEncoder) GetFilterName() string

func (*RawEncoder) MakeDecodeParams Uses

func (this *RawEncoder) MakeDecodeParams() PdfObject

func (*RawEncoder) MakeStreamDict Uses

func (this *RawEncoder) MakeStreamDict() *PdfObjectDictionary

Make a new instance of an encoding dictionary for a stream object.

type RunLengthEncoder Uses

type RunLengthEncoder struct {
}

Run length encoding.

func NewRunLengthEncoder Uses

func NewRunLengthEncoder() *RunLengthEncoder

Make a new run length encoder

func (*RunLengthEncoder) DecodeBytes Uses

func (this *RunLengthEncoder) DecodeBytes(encoded []byte) ([]byte, error)

7.4.5 RunLengthDecode Filter The RunLengthDecode filter decodes data that has been encoded in a simple byte-oriented format based on run length. The encoded data shall be a sequence of runs, where each run shall consist of a length byte followed by 1 to 128 bytes of data. If the length byte is in the range 0 to 127, the following length + 1 (1 to 128) bytes shall be copied literally during decompression. If length is in the range 129 to 255, the following single byte shall be copied 257 - length (2 to 128) times during decompression. A length value of 128 shall denote EOD.

func (*RunLengthEncoder) DecodeStream Uses

func (this *RunLengthEncoder) DecodeStream(streamObj *PdfObjectStream) ([]byte, error)

Decode RunLengthEncoded stream object and give back decoded bytes.

func (*RunLengthEncoder) EncodeBytes Uses

func (this *RunLengthEncoder) EncodeBytes(data []byte) ([]byte, error)

Encode a bytes array and return the encoded value based on the encoder parameters.

func (*RunLengthEncoder) GetFilterName Uses

func (this *RunLengthEncoder) GetFilterName() string

func (*RunLengthEncoder) MakeDecodeParams Uses

func (this *RunLengthEncoder) MakeDecodeParams() PdfObject

func (*RunLengthEncoder) MakeStreamDict Uses

func (this *RunLengthEncoder) MakeStreamDict() *PdfObjectDictionary

Make a new instance of an encoding dictionary for a stream object.

type StreamEncoder Uses

type StreamEncoder interface {
    GetFilterName() string
    MakeDecodeParams() PdfObject
    MakeStreamDict() *PdfObjectDictionary

    EncodeBytes(data []byte) ([]byte, error)
    DecodeBytes(encoded []byte) ([]byte, error)
    DecodeStream(streamObj *PdfObjectStream) ([]byte, error)
}

func NewEncoderFromStream Uses

func NewEncoderFromStream(streamObj *PdfObjectStream) (StreamEncoder, error)

NewEncoderFromStream creates a StreamEncoder based on the stream's dictionary.

type XrefObject Uses

type XrefObject struct {
    // contains filtered or unexported fields
}

XrefObject defines a cross reference entry which is a map between object number (with generation number) and the location of the actual object, either as a file offset (xref table entry), or as a location within an xref stream object (xref object stream). TODO (v3): Unexport.

type XrefTable Uses

type XrefTable map[int]XrefObject

XrefTable is a map between object number and corresponding XrefObject. TODO (v3): Unexport. TODO: Consider changing to a slice, so can maintain the object order without sorting when analyzing.

Package core imports 28 packages (graph) and is imported by 24 packages. Updated 2018-10-26. Refresh now. Tools for package owners.