core

package
v0.0.0-...-692e68a Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2021 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
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.

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

TraceMaxDepth specifies the maximum recursion depth allowed.

Variables

View Source
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")
)

Functions

func DecodeStream

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

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

func EncodeStream

func EncodeStream(streamObj *PdfObjectStream) error

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

func GetNumberAsFloat

func GetNumberAsFloat(obj PdfObject) (float64, error)

func IsDecimalDigit

func IsDecimalDigit(c byte) bool

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

func IsDelimiter

func IsDelimiter(char byte) bool

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

func IsFloatDigit

func IsFloatDigit(c byte) bool

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

func IsOctalDigit

func IsOctalDigit(c byte) bool

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

func IsPrintable

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

func IsWhiteSpace(ch byte) bool

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

Types

type ASCII85Encoder

type ASCII85Encoder struct {
}

ASCII85 encoder/decoder.

func NewASCII85Encoder

func NewASCII85Encoder() *ASCII85Encoder

Make a new ASCII85 encoder.

func (*ASCII85Encoder) DecodeBytes

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

5 ASCII characters -> 4 raw binary bytes

func (*ASCII85Encoder) DecodeStream

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

ASCII85 stream decoding.

func (*ASCII85Encoder) EncodeBytes

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

Encode data into ASCII85 encoded format.

func (*ASCII85Encoder) GetFilterName

func (this *ASCII85Encoder) GetFilterName() string

func (*ASCII85Encoder) MakeDecodeParams

func (this *ASCII85Encoder) MakeDecodeParams() PdfObject

func (*ASCII85Encoder) MakeStreamDict

func (this *ASCII85Encoder) MakeStreamDict() *PdfObjectDictionary

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

type ASCIIHexEncoder

type ASCIIHexEncoder struct {
}

/// ASCII hex encoder/decoder.

func NewASCIIHexEncoder

func NewASCIIHexEncoder() *ASCIIHexEncoder

Make a new ASCII hex encoder.

func (*ASCIIHexEncoder) DecodeBytes

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

func (*ASCIIHexEncoder) DecodeStream

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

ASCII hex decoding.

func (*ASCIIHexEncoder) EncodeBytes

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

func (*ASCIIHexEncoder) GetFilterName

func (this *ASCIIHexEncoder) GetFilterName() string

func (*ASCIIHexEncoder) MakeDecodeParams

func (this *ASCIIHexEncoder) MakeDecodeParams() PdfObject

func (*ASCIIHexEncoder) MakeStreamDict

func (this *ASCIIHexEncoder) MakeStreamDict() *PdfObjectDictionary

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

type AccessPermissions

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

func (perms AccessPermissions) GetP() int32

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

type CCITTFaxEncoder

type CCITTFaxEncoder struct{}

CCITTFax encoder/decoder (dummy, for now)

func NewCCITTFaxEncoder

func NewCCITTFaxEncoder() *CCITTFaxEncoder

func (*CCITTFaxEncoder) DecodeBytes

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

func (*CCITTFaxEncoder) DecodeStream

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

func (*CCITTFaxEncoder) EncodeBytes

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

func (*CCITTFaxEncoder) GetFilterName

func (this *CCITTFaxEncoder) GetFilterName() string

func (*CCITTFaxEncoder) MakeDecodeParams

func (this *CCITTFaxEncoder) MakeDecodeParams() PdfObject

func (*CCITTFaxEncoder) MakeStreamDict

func (this *CCITTFaxEncoder) MakeStreamDict() *PdfObjectDictionary

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

type CryptFilter

type CryptFilter struct {
	Cfm    string
	Length int
}

CryptFilter represents information from a CryptFilter dictionary. TODO (v3): Unexport.

type CryptFilters

type CryptFilters map[string]CryptFilter

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

type DCTEncoder

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

func NewDCTEncoder() *DCTEncoder

Make a new DCT encoder with default parameters.

func (*DCTEncoder) DecodeBytes

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

func (*DCTEncoder) DecodeStream

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

func (*DCTEncoder) EncodeBytes

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

func (*DCTEncoder) GetFilterName

func (this *DCTEncoder) GetFilterName() string

func (*DCTEncoder) MakeDecodeParams

func (this *DCTEncoder) MakeDecodeParams() PdfObject

func (*DCTEncoder) MakeStreamDict

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

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

type FlateEncoder

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

Flate encoding.

func NewFlateEncoder

func NewFlateEncoder() *FlateEncoder

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

func (*FlateEncoder) DecodeBytes

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

func (*FlateEncoder) DecodeStream

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

Decode a FlateEncoded stream object and give back decoded bytes.

func (*FlateEncoder) EncodeBytes

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

func (this *FlateEncoder) GetFilterName() string

func (*FlateEncoder) MakeDecodeParams

func (this *FlateEncoder) MakeDecodeParams() PdfObject

func (*FlateEncoder) MakeStreamDict

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

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

type JBIG2Encoder struct{}

JBIG2 encoder/decoder (dummy, for now)

func NewJBIG2Encoder

func NewJBIG2Encoder() *JBIG2Encoder

func (*JBIG2Encoder) DecodeBytes

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

func (*JBIG2Encoder) DecodeStream

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

func (*JBIG2Encoder) EncodeBytes

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

func (*JBIG2Encoder) GetFilterName

func (this *JBIG2Encoder) GetFilterName() string

func (*JBIG2Encoder) MakeDecodeParams

func (this *JBIG2Encoder) MakeDecodeParams() PdfObject

func (*JBIG2Encoder) MakeStreamDict

func (this *JBIG2Encoder) MakeStreamDict() *PdfObjectDictionary

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

type JPXEncoder

type JPXEncoder struct{}

JPX encoder/decoder (dummy, for now)

func NewJPXEncoder

func NewJPXEncoder() *JPXEncoder

func (*JPXEncoder) DecodeBytes

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

func (*JPXEncoder) DecodeStream

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

func (*JPXEncoder) EncodeBytes

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

func (*JPXEncoder) GetFilterName

func (this *JPXEncoder) GetFilterName() string

func (*JPXEncoder) MakeDecodeParams

func (this *JPXEncoder) MakeDecodeParams() PdfObject

func (*JPXEncoder) MakeStreamDict

func (this *JPXEncoder) MakeStreamDict() *PdfObjectDictionary

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

type LZWEncoder

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

LZW encoding/decoding functionality.

func NewLZWEncoder

func NewLZWEncoder() *LZWEncoder

Make a new LZW encoder with default parameters.

func (*LZWEncoder) DecodeBytes

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

func (*LZWEncoder) DecodeStream

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

func (*LZWEncoder) EncodeBytes

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

func (this *LZWEncoder) GetFilterName() string

func (*LZWEncoder) MakeDecodeParams

func (this *LZWEncoder) MakeDecodeParams() PdfObject

func (*LZWEncoder) MakeStreamDict

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

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

Multi encoder: support serial encoding.

func NewMultiEncoder

func NewMultiEncoder() *MultiEncoder

func (*MultiEncoder) AddEncoder

func (this *MultiEncoder) AddEncoder(encoder StreamEncoder)

func (*MultiEncoder) DecodeBytes

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

func (*MultiEncoder) DecodeStream

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

func (*MultiEncoder) EncodeBytes

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

func (*MultiEncoder) GetFilterName

func (this *MultiEncoder) GetFilterName() string

func (*MultiEncoder) MakeDecodeParams

func (this *MultiEncoder) MakeDecodeParams() PdfObject

func (*MultiEncoder) MakeStreamDict

func (this *MultiEncoder) MakeStreamDict() *PdfObjectDictionary

type ObjectCache

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

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

type ObjectStreams map[int]ObjectStream

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

type PdfCrypt

type PdfCrypt struct {
	Filter           string
	Subfilter        string
	V                int
	Length           int
	R                int
	O                []byte
	U                []byte
	P                int
	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

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

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

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

func (*PdfCrypt) Alg3

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

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

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

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

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

func (*PdfCrypt) Alg7

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

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

func (*PdfCrypt) Decrypt

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

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) GetAccessPermissions

func (crypt *PdfCrypt) GetAccessPermissions() AccessPermissions

GetAccessPermissions returns the PDF access permissions as an AccessPermissions object.

func (*PdfCrypt) LoadCryptFilters

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

LoadCryptFilters loads crypt filter information from the encryption dictionary (V4 only). TODO (v3): Unexport.

type PdfIndirectObject

type PdfIndirectObject struct {
	PdfObjectReference
	PdfObject
}

PdfIndirectObject represents the primitive PDF indirect object.

func MakeIndirectObject

func MakeIndirectObject(obj PdfObject) *PdfIndirectObject

MakeIndirectObject creates an PdfIndirectObject with a specified direct object PdfObject.

func (*PdfIndirectObject) DefaultWriteString

func (ind *PdfIndirectObject) DefaultWriteString() string

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

func (*PdfIndirectObject) String

func (ind *PdfIndirectObject) String() string

type PdfObject

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

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

type PdfObjectArray []PdfObject

PdfObjectArray represents the primitive PDF array object.

func MakeArray

func MakeArray(objects ...PdfObject) *PdfObjectArray

MakeArray creates an PdfObjectArray from a list of PdfObjects.

func MakeArrayFromFloats

func MakeArrayFromFloats(vals []float64) *PdfObjectArray

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

func MakeArrayFromIntegers

func MakeArrayFromIntegers(vals []int) *PdfObjectArray

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

func MakeArrayFromIntegers64

func MakeArrayFromIntegers64(vals []int64) *PdfObjectArray

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

func (*PdfObjectArray) Append

func (array *PdfObjectArray) Append(obj PdfObject)

Append adds an PdfObject to the array.

func (*PdfObjectArray) DefaultWriteString

func (array *PdfObjectArray) DefaultWriteString() string

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

func (*PdfObjectArray) GetAsFloat64Slice

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

func (array *PdfObjectArray) String() string

func (*PdfObjectArray) ToFloat64Array

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

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

type PdfObjectBool bool

PdfObjectBool represents the primitive PDF boolean object.

func (*PdfObjectBool) DefaultWriteString

func (bool *PdfObjectBool) DefaultWriteString() string

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

func (*PdfObjectBool) String

func (bool *PdfObjectBool) String() string

type PdfObjectDictionary

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

PdfObjectDictionary represents the primitive PDF dictionary/map object.

func MakeDict

func MakeDict() *PdfObjectDictionary

MakeDict creates and returns an empty PdfObjectDictionary.

func (*PdfObjectDictionary) DefaultWriteString

func (d *PdfObjectDictionary) DefaultWriteString() string

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

func (*PdfObjectDictionary) Dict

Dict returns the dict in the dictionary.

func (*PdfObjectDictionary) Get

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

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

Keys returns the list of keys in the dictionary.

func (*PdfObjectDictionary) Merge

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

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

func (*PdfObjectDictionary) Remove

func (d *PdfObjectDictionary) Remove(key PdfObjectName)

Remove removes an element specified by key.

func (*PdfObjectDictionary) Set

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

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

func (d *PdfObjectDictionary) String() string

type PdfObjectFloat

type PdfObjectFloat float64

PdfObjectFloat represents the primitive PDF floating point numerical object.

func MakeFloat

func MakeFloat(val float64) *PdfObjectFloat

MakeFloat creates an PdfObjectFloat from a float64.

func (*PdfObjectFloat) DefaultWriteString

func (float *PdfObjectFloat) DefaultWriteString() string

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

func (*PdfObjectFloat) String

func (float *PdfObjectFloat) String() string

type PdfObjectInteger

type PdfObjectInteger int64

PdfObjectInteger represents the primitive PDF integer numerical object.

func MakeInteger

func MakeInteger(val int64) *PdfObjectInteger

MakeInteger creates a PdfObjectInteger from an int64.

func (*PdfObjectInteger) DefaultWriteString

func (int *PdfObjectInteger) DefaultWriteString() string

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

func (*PdfObjectInteger) String

func (int *PdfObjectInteger) String() string

type PdfObjectName

type PdfObjectName string

PdfObjectName represents the primitive PDF name object.

func MakeName

func MakeName(s string) *PdfObjectName

MakeName creates a PdfObjectName from a string.

func (*PdfObjectName) DefaultWriteString

func (name *PdfObjectName) DefaultWriteString() string

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

func (*PdfObjectName) String

func (name *PdfObjectName) String() string

type PdfObjectNull

type PdfObjectNull struct{}

PdfObjectNull represents the primitive PDF null object.

func MakeNull

func MakeNull() *PdfObjectNull

MakeNull creates an PdfObjectNull.

func (*PdfObjectNull) DefaultWriteString

func (null *PdfObjectNull) DefaultWriteString() string

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

func (*PdfObjectNull) String

func (null *PdfObjectNull) String() string

type PdfObjectReference

type PdfObjectReference struct {
	ObjectNumber     int64
	GenerationNumber int64
}

PdfObjectReference represents the primitive PDF reference object.

func (*PdfObjectReference) DefaultWriteString

func (ref *PdfObjectReference) DefaultWriteString() string

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

func (*PdfObjectReference) String

func (ref *PdfObjectReference) String() string

type PdfObjectStream

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

PdfObjectStream represents the primitive PDF Object stream.

func MakeStream

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

func (stream *PdfObjectStream) DefaultWriteString() string

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

func (*PdfObjectStream) String

func (stream *PdfObjectStream) String() string

type PdfObjectString

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

func MakeString(s string) *PdfObjectString

MakeString creates an PdfObjectString from a string.

func (*PdfObjectString) DefaultWriteString

func (str *PdfObjectString) DefaultWriteString() string

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

func (*PdfObjectString) String

func (str *PdfObjectString) String() string

type PdfParser

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

func NewParser

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 (*PdfParser) Decrypt

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

func (parser *PdfParser) GetCrypter() *PdfCrypt

func (*PdfParser) GetFileOffset

func (parser *PdfParser) GetFileOffset() int64

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

func (*PdfParser) GetRootDict

func (parser *PdfParser) GetRootDict() *PdfObjectDictionary

func (*PdfParser) GetTrailer

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) IsAuthenticated

func (parser *PdfParser) IsAuthenticated() bool

func (*PdfParser) IsEncrypted

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

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

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

LookupByReference looks up a PdfObject by a reference.

func (*PdfParser) ParseDict

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

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

func (*PdfParser) ParseIndirectObject

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

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

func (parser *PdfParser) SetFileOffset(offset int64)

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

func (*PdfParser) Trace

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

type RawEncoder struct{}

Raw encoder/decoder (no encoding, pass through)

func NewRawEncoder

func NewRawEncoder() *RawEncoder

func (*RawEncoder) DecodeBytes

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

func (*RawEncoder) DecodeStream

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

func (*RawEncoder) EncodeBytes

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

func (*RawEncoder) GetFilterName

func (this *RawEncoder) GetFilterName() string

func (*RawEncoder) MakeDecodeParams

func (this *RawEncoder) MakeDecodeParams() PdfObject

func (*RawEncoder) MakeStreamDict

func (this *RawEncoder) MakeStreamDict() *PdfObjectDictionary

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

type RunLengthEncoder

type RunLengthEncoder struct {
}

Run length encoding.

func NewRunLengthEncoder

func NewRunLengthEncoder() *RunLengthEncoder

Make a new run length encoder

func (*RunLengthEncoder) DecodeBytes

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

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

Decode RunLengthEncoded stream object and give back decoded bytes.

func (*RunLengthEncoder) EncodeBytes

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

func (this *RunLengthEncoder) GetFilterName() string

func (*RunLengthEncoder) MakeDecodeParams

func (this *RunLengthEncoder) MakeDecodeParams() PdfObject

func (*RunLengthEncoder) MakeStreamDict

func (this *RunLengthEncoder) MakeStreamDict() *PdfObjectDictionary

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

type StreamEncoder

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

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

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

type XrefObject

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

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.

Jump to

Keyboard shortcuts

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