pdfstruct

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2025 License: BSD-3-Clause Imports: 12 Imported by: 1

Documentation

Overview

Package pdfstruct provides methods for reading and updating the basic structure of a PDF. It doesn't understand the semantics of the PDF at all; it just knows how to locate, parse, update, add, and remove objects.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Array

type Array []Object

An Array is an array of objects.

type Dict

type Dict map[Name]Object

A Dict is a map from Name to Object.

type Name

type Name string

A Name is a PDF/Postscript name, without the leading slash.

type Object

type Object any

An Object is an object as defined by the PDF specification. While an Object is defined as "any", it will in fact be one of the following:

  • nil (a null object)
  • bool
  • int
  • float64
  • string
  • []byte (a hex string)
  • Name
  • Array
  • Dict
  • Stream
  • Reference

type PDF

type PDF struct {
	Info    Dict
	Catalog Dict
	// contains filtered or unexported fields
}

A PDF is a reference to a PDF file.

func Open

func Open(fh Reader) (p *PDF, err error)

Open opens a PDF file. The supplied file handle must honor io.ReadSeeker, but if Write is going to be called, it must also honor io.Writer.

func (*PDF) CreateObject

func (p *PDF) CreateObject(obj Object) (ref Reference)

CreateObject creates a new object with the specified content, and returns a reference to it. The new content will be written if Write is called.

func (*PDF) Get

func (p *PDF) Get(r Reference) (obj Object, err error)

Get returns the object specified by the reference.

func (*PDF) GetArray

func (p *PDF) GetArray(r Reference) (array Array, err error)

GetArray gets the array object specified by the reference.

func (*PDF) GetDict

func (p *PDF) GetDict(r Reference) (dict Dict, err error)

GetDict gets the dict object specified by the reference.

func (*PDF) GetStream

func (p *PDF) GetStream(r Reference) (stream Stream, err error)

GetStream gets the stream object specified by the reference.

func (*PDF) GetString

func (p *PDF) GetString(r Reference) (str string, err error)

GetString gets the string object specified by the reference.

func (*PDF) UpdateObject

func (p *PDF) UpdateObject(ref Reference, obj Object)

UpdateObject registers new content for the object with the specified reference. The new content will be written if Write is called.

func (*PDF) Write

func (p *PDF) Write() (err error)

Write updates the PDF in place to save the updated objects previously passed to UpdateObject. For this to work, the file handle passed to Open must support io.WriteSeeker. The caller needs to close the file when finished.

type Reader

type Reader interface {
	io.Seeker
	io.ReaderAt
}

Reader is the interface that must be satisfied by any file passed to Open.

type Reference

type Reference struct {
	Number     int
	Generation int
}

A Reference is an indirect reference to an Object.

type Stream

type Stream struct {
	Dict Dict
	Data []byte
}

A Stream is a Dict followed by a block of arbitrary data. Note that when retrieved from the pdfstruct library, stream data has been decompressed and decoded.

func (*Stream) Decompress

func (s *Stream) Decompress(rowsize int) error

Decompress removes any compression and/or encoding from the stream data. Some encoding methods need to know the size (in bytes) of a "row" in the data for decoding, so that is a parameter.

Jump to

Keyboard shortcuts

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