Documentation ¶
Overview ¶
Package pdf signs PDF documents and provides some processing utilities.
Index ¶
- func FillInSignature(document []byte, signOff, signLen int, key crypto.PrivateKey, ...) error
- func PKCS12Parse(p12 []byte, password string) (crypto.PrivateKey, []*x509.Certificate, error)
- func Sign(document []byte, key crypto.PrivateKey, certs []*x509.Certificate, ...) ([]byte, error)
- type BytesWriter
- type Lexer
- type Object
- func New(kind ObjectKind) Object
- func NewArray(a []Object) Object
- func NewBool(b bool) Object
- func NewComment(c string) Object
- func NewDate(ts time.Time) Object
- func NewDict(d map[string]Object) Object
- func NewIndirect(o Object, n, generation uint) Object
- func NewKeyword(k string) Object
- func NewName(n string) Object
- func NewNumeric(n float64) Object
- func NewReference(n, generation uint) Object
- func NewStream(d map[string]Object, s []byte) Object
- func NewString(s string) Object
- type ObjectKind
- type Updater
- func (u *Updater) Allocate() uint
- func (u *Updater) Dereference(o Object) (Object, error)
- func (u *Updater) FlushUpdates()
- func (u *Updater) Get(n, generation uint) (Object, error)
- func (u *Updater) GetFirstPage(node Object) Object
- func (u *Updater) GetStreamData(stream Object) ([]byte, error)
- func (u *Updater) ListIndirect() []Object
- func (u *Updater) Update(n uint, fill func(buf BytesWriter))
- func (u *Updater) Version(root *Object) int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FillInSignature ¶
func FillInSignature(document []byte, signOff, signLen int, key crypto.PrivateKey, certs []*x509.Certificate) error
FillInSignature signs PDF contents and writes the signature into the given window that has been reserved for this specific purpose. This is a very low-level function.
func PKCS12Parse ¶
func PKCS12Parse(p12 []byte, password string) ( crypto.PrivateKey, []*x509.Certificate, error)
PKCS12Parse parses and verifies PKCS#12 data.
func Sign ¶
func Sign(document []byte, key crypto.PrivateKey, certs []*x509.Certificate, reservation int) ([]byte, error)
Sign signs the given document, growing and returning the passed-in slice. There must be at least one certificate, matching the private key. The certificates must form a chain.
A good default for the reservation is around 4096 (the value is in bytes).
The presumption here is that the document is valid and that it doesn't employ cross-reference streams from PDF 1.5, or at least constitutes a hybrid-reference file. The results with PDF 2.0 (2017) are currently unknown as the standard costs money.
Types ¶
type BytesWriter ¶
type BytesWriter interface { Bytes() []byte Len() int Write(p []byte) (n int, err error) WriteByte(c byte) error WriteRune(r rune) (n int, err error) WriteString(s string) (n int, err error) }
BytesWriter is an interface over a subset of bytes.Buffer methods.
type Lexer ¶
type Lexer struct {
P []byte // input buffer
}
Lexer is a basic lexical analyser for the Portable Document Format, giving limited error information.
type Object ¶
type Object struct { Kind ObjectKind String string // Comment/Keyword/Name/String Number float64 // Bool, Numeric Array []Object // Array, Indirect Dict map[string]Object // Dict, Stream Stream []byte // Stream N, Generation uint // Indirect, Reference }
Object is a PDF token/object thingy. Objects may be composed either from one or a sequence of tokens. The PDF Reference doesn't actually speak of tokens, though ISO 32000-1:2008 does.
func New ¶
func New(kind ObjectKind) Object
New returns a new Object of the given kind, with default values.
func NewComment ¶
func NewIndirect ¶
func NewKeyword ¶
func NewNumeric ¶
func NewReference ¶
type ObjectKind ¶
type ObjectKind int
const ( End ObjectKind = iota NL Comment Nil Bool Numeric Keyword Name String // simple tokens BArray EArray BDict EDict // higher-level objects Array Dict Stream Indirect Reference )
type Updater ¶
type Updater struct { // PDF document data Document []byte // the new trailer dictionary to be written, initialized with the old one Trailer map[string]Object // contains filtered or unexported fields }
Updater is a utility class to help read and possibly incrementally update PDF files.
func NewUpdater ¶
NewUpdater initializes an Updater, building the cross-reference table and preparing a new trailer dictionary.
func (*Updater) Dereference ¶
Derefence dereferences Reference objects, and passes the other kinds through.
func (*Updater) FlushUpdates ¶
func (u *Updater) FlushUpdates()
FlushUpdates writes an updated cross-reference table and trailer, or stream.
func (*Updater) Get ¶
Get retrieves an object by its number and generation--may return Nil or End with an error.
func (*Updater) GetFirstPage ¶
GetFirstPage retrieves the first page of the given page (sub)tree reference, or returns a Nil object if unsuccessful.
func (*Updater) GetStreamData ¶
GetStreamData returns the actual data stored in a stream object, applying any filters.
func (*Updater) ListIndirect ¶
ListIndirect returns the whole cross-reference table as Reference Objects.
func (*Updater) Update ¶
func (u *Updater) Update(n uint, fill func(buf BytesWriter))
Update appends an updated object to the end of the document. The fill callback must write exactly one PDF object.