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

package pdf

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

* The PDF standard supports encryption of strings and streams. * Section 7.6.

Index

Package Files

crossrefs.go crypt.go font.go image.go io.go outlines.go page.go pdfobject.go pdfparser.go pdfstream.go reader.go repairs.go utils.go writer.go

Constants

const (
    XREF_TABLE_ENTRY   = iota
    XREF_OBJECT_STREAM = iota
)

Variables

var PdfObjectConverterCache map[PdfObjectConverter]PdfObject = map[PdfObjectConverter]PdfObject{}

Object cache.

func SetImageHandler Uses

func SetImageHandler(imgHandling ImageHandler)

func SetPdfCreator Uses

func SetPdfCreator(creator string)

func SetPdfProducer Uses

func SetPdfProducer(producer string)

type AccessPermissions Uses

type AccessPermissions struct {
    Printing          bool
    Modify            bool
    ExtractGraphics   bool
    Annotate          bool
    FillForms         bool
    DisabilityExtract bool // not clear what this means!
    RotateInsert      bool
    LimitPrintQuality bool
}

func (AccessPermissions) GetP Uses

func (perms AccessPermissions) GetP() int32

type CryptFilter Uses

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

type CryptFilters Uses

type CryptFilters map[string]CryptFilter

type DefaultImageHandler Uses

type DefaultImageHandler struct{}

func (DefaultImageHandler) Compress Uses

func (this DefaultImageHandler) Compress(input *Image, quality int64) (*Image, error)

To be implemented.

func (DefaultImageHandler) Read Uses

func (this DefaultImageHandler) Read(reader io.Reader) (*Image, error)

type EncryptOptions Uses

type EncryptOptions struct {
    Permissions AccessPermissions
}

type Image Uses

type Image struct {
    Width  int64
    Height int64
    Data   *bytes.Buffer
}

Basic representation of an image. The images are stored in the JPEG format.

type ImageHandler Uses

type ImageHandler interface {
    // Read any image type and load into a new Image object.
    Read(r io.Reader) (*Image, error)
    // Compress an image.
    Compress(input *Image, quality int64) (*Image, error)
}
var ImageHandling ImageHandler = DefaultImageHandler{}

type ObjectCache Uses

type ObjectCache map[int]PdfObject

type ObjectStream Uses

type ObjectStream struct {
    N int
    // contains filtered or unexported fields
}

type ObjectStreams Uses

type ObjectStreams map[int]ObjectStream

type PdfCrypt Uses

type PdfCrypt struct {
    Filter    string
    Subfilter string
    V         int

    R   int
    O   []byte
    U   []byte
    P   int
    // contains filtered or unexported fields
}

func PdfCryptMakeNew Uses

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

Prepare the document crypt handler based on the encryption dictionary and trailer dictionary.

func (*PdfCrypt) Decrypt Uses

func (this *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 (this *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 Uses

func (this *PdfCrypt) GetAccessPermissions() AccessPermissions

func (*PdfCrypt) LoadCryptFilters Uses

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

Load crypt filter information from the encryption dictionary (V4 only).

type PdfDate Uses

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

A date is a PDF string of the form: (D:YYYYMMDDHHmmSSOHH'mm)

func NewPdfDate Uses

func NewPdfDate(dateStr string) (PdfDate, error)

Make a new PdfDate object from a PDF date string (see 7.9.4 Dates). format: "D: YYYYMMDDHHmmSSOHH'mm"

func (*PdfDate) ToPdfObject Uses

func (date *PdfDate) ToPdfObject() PdfObject

Convert to a PDF string object.

type PdfIndirectObject Uses

type PdfIndirectObject struct {
    PdfObjectReference
    PdfObject
}

func (*PdfIndirectObject) DefaultWriteString Uses

func (this *PdfIndirectObject) DefaultWriteString() string

func (*PdfIndirectObject) String Uses

func (this *PdfIndirectObject) String() string

type PdfObject Uses

type PdfObject interface {
    String() string
    DefaultWriteString() string
}

func TraceToDirectObject Uses

func TraceToDirectObject(obj PdfObject) PdfObject

Handy functions to work with primitive objects. Traces a pdf object to a direct object. For example 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

func (*PdfObjectArray) DefaultWriteString Uses

func (this *PdfObjectArray) DefaultWriteString() string

func (*PdfObjectArray) String Uses

func (this *PdfObjectArray) String() string

type PdfObjectBool Uses

type PdfObjectBool bool

func (*PdfObjectBool) DefaultWriteString Uses

func (this *PdfObjectBool) DefaultWriteString() string

func (*PdfObjectBool) String Uses

func (this *PdfObjectBool) String() string

type PdfObjectConverter Uses

type PdfObjectConverter interface {
    ToPdfObject(updateIfExists bool) PdfObject
}

Convertible to a PDF object interface.

type PdfObjectDictionary Uses

type PdfObjectDictionary map[PdfObjectName]PdfObject

func (*PdfObjectDictionary) DefaultWriteString Uses

func (this *PdfObjectDictionary) DefaultWriteString() string

func (*PdfObjectDictionary) Set Uses

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

func (*PdfObjectDictionary) SetIfNotNil Uses

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

func (*PdfObjectDictionary) String Uses

func (this *PdfObjectDictionary) String() string

type PdfObjectFloat Uses

type PdfObjectFloat float64

func MakeFloat Uses

func MakeFloat(val float64) *PdfObjectFloat

func (*PdfObjectFloat) DefaultWriteString Uses

func (this *PdfObjectFloat) DefaultWriteString() string

func (*PdfObjectFloat) String Uses

func (this *PdfObjectFloat) String() string

type PdfObjectInteger Uses

type PdfObjectInteger int64

func MakeInteger Uses

func MakeInteger(val int64) *PdfObjectInteger

func (*PdfObjectInteger) DefaultWriteString Uses

func (this *PdfObjectInteger) DefaultWriteString() string

func (*PdfObjectInteger) String Uses

func (this *PdfObjectInteger) String() string

type PdfObjectName Uses

type PdfObjectName string

func MakeName Uses

func MakeName(s string) *PdfObjectName

Quick functions to make pdf objects form primitive objects.

func (*PdfObjectName) DefaultWriteString Uses

func (this *PdfObjectName) DefaultWriteString() string

func (*PdfObjectName) String Uses

func (this *PdfObjectName) String() string

type PdfObjectNull Uses

type PdfObjectNull struct{}

func MakeNull Uses

func MakeNull() *PdfObjectNull

func (*PdfObjectNull) DefaultWriteString Uses

func (this *PdfObjectNull) DefaultWriteString() string

func (*PdfObjectNull) String Uses

func (this *PdfObjectNull) String() string

type PdfObjectReference Uses

type PdfObjectReference struct {
    ObjectNumber     int64
    GenerationNumber int64
}

func (*PdfObjectReference) DefaultWriteString Uses

func (this *PdfObjectReference) DefaultWriteString() string

func (*PdfObjectReference) String Uses

func (this *PdfObjectReference) String() string

type PdfObjectStream Uses

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

func (*PdfObjectStream) DefaultWriteString Uses

func (this *PdfObjectStream) DefaultWriteString() string

func (*PdfObjectStream) String Uses

func (this *PdfObjectStream) String() string

type PdfObjectString Uses

type PdfObjectString string

func MakeString Uses

func MakeString(s string) *PdfObjectString

func (*PdfObjectString) DefaultWriteString Uses

func (this *PdfObjectString) DefaultWriteString() string

func (*PdfObjectString) String Uses

func (this *PdfObjectString) String() string

type PdfOutline Uses

type PdfOutline struct {
    PdfOutlineTreeNode
    Count *int64
}

PDF outline dictionary (Table 152 - p. 376).

func NewPdfOutlineTree Uses

func NewPdfOutlineTree() *PdfOutline

func (*PdfOutline) ToPdfObject Uses

func (this *PdfOutline) ToPdfObject(updateIfExists bool) PdfObject

Recursively build the Outline tree PDF object.

type PdfOutlineItem Uses

type PdfOutlineItem struct {
    PdfOutlineTreeNode
    Title  *PdfObjectString
    Parent *PdfOutlineTreeNode
    Prev   *PdfOutlineTreeNode
    Next   *PdfOutlineTreeNode
    Count  *int64
    Dest   PdfObject
    A      PdfObject
    SE     PdfObject
    C      PdfObject
    F      PdfObject
}

Pdf outline item dictionary (Table 153 - pp. 376 - 377).

func NewOutlineBookmark Uses

func NewOutlineBookmark(title string, page *PdfIndirectObject) *PdfOutlineItem

func (*PdfOutlineItem) ToPdfObject Uses

func (this *PdfOutlineItem) ToPdfObject(updateIfExists bool) PdfObject

Outline item. Recursively build the Outline tree PDF object.

type PdfOutlineTreeNode Uses

type PdfOutlineTreeNode struct {
    First *PdfOutlineTreeNode
    Last  *PdfOutlineTreeNode
    // contains filtered or unexported fields
}

func (*PdfOutlineTreeNode) ToPdfObject Uses

func (this *PdfOutlineTreeNode) ToPdfObject(updateIfExists bool) PdfObject

type PdfPage Uses

type PdfPage struct {
    Parent               PdfObject
    LastModified         *PdfDate
    Resources            *PdfPageResources
    CropBox              *PdfRectangle
    MediaBox             *PdfRectangle
    BleedBox             *PdfRectangle
    TrimBox              *PdfRectangle
    ArtBox               *PdfRectangle
    BoxColorInfo         PdfObject
    Contents             PdfObject
    Rotate               *int64
    Group                PdfObject
    Thumb                PdfObject
    B                    PdfObject
    Dur                  PdfObject
    Trans                PdfObject
    Annots               PdfObject
    AA                   PdfObject
    Metadata             PdfObject
    PieceInfo            PdfObject
    StructParents        PdfObject
    ID                   PdfObject
    PZ                   PdfObject
    SeparationInfo       PdfObject
    Tabs                 PdfObject
    TemplateInstantiated PdfObject
    PresSteps            PdfObject
    UserUnit             PdfObject
    VP                   PdfObject
    // contains filtered or unexported fields
}

PDF page object (7.7.3.3 - Table 30).

func NewPdfPage Uses

func NewPdfPage() *PdfPage

func (*PdfPage) AddContentStreamByString Uses

func (this *PdfPage) AddContentStreamByString(contentStr string)

Add content stream by string. Puts the content string into a stream object and points the content stream towards it.

func (*PdfPage) AddExtGState Uses

func (this *PdfPage) AddExtGState(name PdfObjectName, egs *PdfObjectDictionary)

Add a graphics state to the XObject resources.

func (*PdfPage) AddFont Uses

func (this *PdfPage) AddFont(name PdfObjectName, font *PdfObjectDictionary)

Add a font dictionary to the Font resources.

func (*PdfPage) AddImageResource Uses

func (this *PdfPage) AddImageResource(name PdfObjectName, ximg *XObjectImage) error

Add an image to the XObject resources.

func (*PdfPage) AddWatermarkImage Uses

func (this *PdfPage) AddWatermarkImage(ximg *XObjectImage, opt WatermarkImageOptions) error

Add a watermark to the page.

func (*PdfPage) GetMediaBox Uses

func (this *PdfPage) GetMediaBox() (*PdfRectangle, error)

Get the inheritable media box value, either from the page or a higher up page/pages struct.

func (*PdfPage) GetPageAsIndirectObject Uses

func (this *PdfPage) GetPageAsIndirectObject() *PdfIndirectObject

Get the page object as an indirect objects. Wraps the Page dictionary into an indirect object.

func (*PdfPage) GetPageDict Uses

func (this *PdfPage) GetPageDict() *PdfObjectDictionary

Convert the Page to a PDF object dictionary.

type PdfPageResources Uses

type PdfPageResources struct {
    ExtGState  PdfObject
    ColorSpace PdfObject
    Pattern    PdfObject
    Shading    PdfObject
    XObject    PdfObject
    Font       PdfObject
    ProcSet    PdfObject
}

Page resources.

func NewPdfPageResourcesFromDict Uses

func NewPdfPageResourcesFromDict(dict *PdfObjectDictionary) (*PdfPageResources, error)

func (*PdfPageResources) ToPdfObject Uses

func (r *PdfPageResources) ToPdfObject() PdfObject

type PdfPageTreeNode Uses

type PdfPageTreeNode struct {
    Parent *PdfPageTreeNode
    Kids   *PdfPageTreeNode
    Count  *int64
}

type PdfParser Uses

type PdfParser struct {
    ObjCache ObjectCache
    // contains filtered or unexported fields
}

func NewParser Uses

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

Creates a new parser for a PDF file via ReadSeeker. Loads the cross reference stream and trailer.

func (*PdfParser) Decrypt Uses

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

Decrypt the PDF file with a specified password. Also tries to decrypt with an empty password. Returns true if successful, false otherwise.

func (*PdfParser) GetFileOffset Uses

func (this *PdfParser) GetFileOffset() int64

Get the current file offset, accounting for buffered position.

func (*PdfParser) IsEncrypted Uses

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

Check if the document is encrypted. 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.

func (*PdfParser) LookupByNumber Uses

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

Outside interface for lookupByNumberWrapper. Default attempts repairs of bad xref tables.

func (*PdfParser) LookupByReference Uses

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

LookupByReference

func (*PdfParser) ReadAtLeast Uses

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

func (*PdfParser) SetFileOffset Uses

func (this *PdfParser) SetFileOffset(offset int64)

Seek the file to an offset position.

func (*PdfParser) Trace Uses

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

Trace to direct object.

type PdfReader Uses

type PdfReader struct {
    PageList []*PdfPage
    // contains filtered or unexported fields
}

func NewPdfReader Uses

func NewPdfReader(rs io.ReadSeeker) (*PdfReader, error)

func (*PdfReader) Decrypt Uses

func (this *PdfReader) Decrypt(password []byte) (bool, error)

Decrypt the PDF file with a specified password. Also tries to decrypt with an empty password. Returns true if successful, false otherwise.

func (*PdfReader) GetForms Uses

func (this *PdfReader) GetForms() (*PdfObjectDictionary, error)

Get document form data.

func (*PdfReader) GetNumPages Uses

func (this *PdfReader) GetNumPages() (int, error)

Get the number of pages in the document.

func (*PdfReader) GetOutlineTree Uses

func (this *PdfReader) GetOutlineTree() *PdfOutlineTreeNode

Get the outline tree.

func (*PdfReader) GetOutlinesFlattened Uses

func (this *PdfReader) GetOutlinesFlattened() ([]*PdfOutlineTreeNode, []string, error)

Return a flattened list of tree nodes and titles.

func (*PdfReader) GetPage Uses

func (this *PdfReader) GetPage(pageNumber int) (PdfObject, error)

Get a page by the page number. Indirect object with type /Page. Rename to GetPageAsIndirectObject in the future?

func (*PdfReader) GetPageAsPdfPage Uses

func (this *PdfReader) GetPageAsPdfPage(pageNumber int) (*PdfPage, error)

Get a page by the page number. Returns the PdfPage entry.

func (*PdfReader) Inspect Uses

func (this *PdfReader) Inspect() (map[string]int, error)

Inspect analyzes the document object structure.

func (*PdfReader) IsEncrypted Uses

func (this *PdfReader) IsEncrypted() (bool, error)

type PdfRectangle Uses

type PdfRectangle struct {
    Llx float64 // Lower left corner (ll).
    Lly float64
    Urx float64 // Upper right corner (ur).
    Ury float64
}

func NewPdfRectangle Uses

func NewPdfRectangle(arr PdfObjectArray) (*PdfRectangle, error)

Create a PDF rectangle object based on an input array of 4 integers. Defining the lower left (LL) and upper right (UR) corners with floating point numbers.

func (*PdfRectangle) ToPdfObject Uses

func (rect *PdfRectangle) ToPdfObject() PdfObject

Convert to a PDF object.

type PdfWriter Uses

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

func NewPdfWriter Uses

func NewPdfWriter() PdfWriter

func (*PdfWriter) AddForms Uses

func (this *PdfWriter) AddForms(forms *PdfObjectDictionary) error

Add Acroforms to a PDF file.

func (*PdfWriter) AddOutlineTree Uses

func (this *PdfWriter) AddOutlineTree(outlineTree *PdfOutlineTreeNode)

Add outlines to a PDF file.

func (*PdfWriter) AddPage Uses

func (this *PdfWriter) AddPage(pageObj PdfObject) error

Add a page to the PDF file. The new page should be an indirect object.

func (*PdfWriter) Encrypt Uses

func (this *PdfWriter) Encrypt(userPass, ownerPass []byte, options *EncryptOptions) error

Encrypt the output file with a specified user/owner password.

func (*PdfWriter) Write Uses

func (this *PdfWriter) Write(ws io.WriteSeeker) error

Write the pdf out.

type WatermarkImageOptions Uses

type WatermarkImageOptions struct {
    Alpha               float64
    FitToWidth          bool
    PreserveAspectRatio bool
}

type XObjectImage Uses

type XObjectImage struct {
    Width            *int64
    Height           *int64
    ColorSpace       PdfObject
    BitsPerComponent *int64
    Intent           PdfObject
    ImageMask        PdfObject
    Mask             PdfObject
    Decode           PdfObject
    Interpolate      PdfObject
    Alternatives     PdfObject
    SMask            PdfObject
    SMaskInData      PdfObject
    Name             PdfObject
    StructParent     PdfObject
    ID               PdfObject
    OPI              PdfObject
    Metadata         PdfObject
    OC               PdfObject
    Stream           []byte
}

Image XObject (Table 89 in 8.9.5.1).

func NewXObjectImage Uses

func NewXObjectImage(name PdfObjectName, img *Image) (*XObjectImage, error)

Creates a new XObject Image from an image object with default options.

func NewXObjectImageFromStream Uses

func NewXObjectImageFromStream(stream PdfObjectStream) (*XObjectImage, error)

Build the image xobject from a stream object.

func (*XObjectImage) ToPdfObject Uses

func (ximg *XObjectImage) ToPdfObject() PdfObject

Return a stream object.

type XrefObject Uses

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

type XrefTable Uses

type XrefTable map[int]XrefObject

Package pdf imports 25 packages (graph) and is imported by 2 packages. Updated 2016-11-28. Refresh now. Tools for package owners.