pdf

package
v0.0.0-...-6d64815 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2023 License: GPL-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnsupportedChars = errors.New("unsupported chars")
	ErrDstTooShort      = errors.New("destination buffer is too short")
)
View Source
var (
	ErrValueOutOfRange = errors.New("value out of range")

	ErrNotImplemented = errors.New("not implemented")

	ErrCannotConvertColor = errors.New("cannot convert color")
)
View Source
var ErrUnsupportedVersion = errors.New("unsupported pdf version")

Functions

func CheckEOL

func CheckEOL(e1, e2 byte) bool

func CheckValidUTF8ToPDFDocEncoding

func CheckValidUTF8ToPDFDocEncoding(text []byte) (isValid, isASCIIEqual bool)

func CheckXRefEntryType

func CheckXRefEntryType(c byte) bool

func ConvertUTF8ToPDFDocEncoding

func ConvertUTF8ToPDFDocEncoding(text []byte) ([]byte, error)

func IndexLast

func IndexLast(r io.ReadSeeker, what []byte) (pos int64, err error)

func IsPDFDocEncotingConcidentToUTF8

func IsPDFDocEncotingConcidentToUTF8(text []byte) bool

func IsWhitespace

func IsWhitespace(r rune) bool

func ResizeSlice

func ResizeSlice[T any](slice []T, size int) []T

Types

type AcroForm

type AcroForm struct{}

type Array

type Array struct{}

func (*Array) Copy

func (arr *Array) Copy() (Object, error)

func (*Array) Dictionary

func (arr *Array) Dictionary() *Dictionary

func (*Array) Document

func (arr *Array) Document() *Document

func (*Array) GetIndirectReference

func (arr *Array) GetIndirectReference() *Reference

func (*Array) Kind

func (arr *Array) Kind() ObjectKind

func (*Array) MarshalPDF

func (arr *Array) MarshalPDF(_ *Writer) error

MarshalPDF encodes the receiver a PDF bytes.

func (*Array) Parent

func (arr *Array) Parent() Object

func (*Array) SetParent

func (arr *Array) SetParent(_ Object)

type ArrayElement

type ArrayElement struct{ Element }

func (*ArrayElement) Array

func (e *ArrayElement) Array() *Array

type BaseObject

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

func (*BaseObject) Copy

func (obj *BaseObject) Copy() (BaseObject, error)

func (*BaseObject) DelayedLoadStream

func (obj *BaseObject) DelayedLoadStream() error

func (*BaseObject) Document

func (obj *BaseObject) Document() *Document

func (*BaseObject) GetIndirectReference

func (obj *BaseObject) GetIndirectReference() *Reference

func (*BaseObject) Parent

func (obj *BaseObject) Parent() Object

func (*BaseObject) SetParent

func (obj *BaseObject) SetParent(parent Object)

type CMYKColor

type CMYKColor color.CMYK

func ConvertToCMYK

func ConvertToCMYK(inColor Color) (cmyk CMYKColor, err error)

func (CMYKColor) ColorSpace

func (cmyk CMYKColor) ColorSpace() ColorSpace

func (CMYKColor) RGBA

func (cmyk CMYKColor) RGBA() (r, g, b, a uint32)

func (*CMYKColor) UnmarshalText

func (cmyk *CMYKColor) UnmarshalText(text []byte) error

func (CMYKColor) Validate

func (cmyk CMYKColor) Validate() error

type Catalog

type Catalog struct {
	DictionaryElement
}

func (*Catalog) GetOrCreateMetadataObject

func (c *Catalog) GetOrCreateMetadataObject() Object

func (*Catalog) Lang

func (c *Catalog) Lang() Object

func (*Catalog) MarkInfo

func (c *Catalog) MarkInfo() Object

func (*Catalog) Metadata

func (c *Catalog) Metadata() Object

func (*Catalog) MetadataStream

func (c *Catalog) MetadataStream() (stream []byte, err error)

func (*Catalog) PageMode

func (c *Catalog) PageMode() PageMode

func (*Catalog) Root

func (c *Catalog) Root() Object

func (*Catalog) SetMetadataStream

func (c *Catalog) SetMetadataStream(value []byte) error

func (*Catalog) SetPageLayout

func (c *Catalog) SetPageLayout(layout PageLayout)

func (*Catalog) SetPageMode

func (c *Catalog) SetPageMode(mode PageMode)

type CieLabColor

type CieLabColor struct {
	// CieL indicates lightness.
	CieL float64
	// CieA indicates A color value.
	CieA float64
	// CieB  indicates B color value.
	CieB float64
}

func (CieLabColor) ColorSpace

func (lab CieLabColor) ColorSpace() ColorSpace

func (CieLabColor) Validate

func (lab CieLabColor) Validate() error

type Color

type Color interface {
	ColorSpace() ColorSpace
	Validate() error
}

func ColorFromObject

func ColorFromObject(obj Object) (Color, error)

func ParseColor

func ParseColor(text []byte) (color Color, err error)

func TransparentColor

func TransparentColor() Color

type ColorSpace

type ColorSpace uint8

ColorSpace is an enum for the colorspaces supported by PDF.

const (
	// ColorSpaceUnknown is an uknown colorspace.
	ColorSpaceUnknown ColorSpace = iota
	ColorSpaceDeviceGray
	ColorSpaceDeviceRGB
	ColorSpaceDeviceCMYK
	ColorSpaceCalGray
	ColorSpaceCalRGB
	ColorSpaceLab ///< CIE-Lab
	ColorSpaceICCBased
	ColorSpaceIndexed
	ColorSpacePattern
	ColorSpaceSeparation
	ColorSpaceDeviceN
)

type Dictionary

type Dictionary struct{}

func (*Dictionary) AddKeyIndirect

func (dict *Dictionary) AddKeyIndirect(name Name, obj Object)

func (*Dictionary) Copy

func (dict *Dictionary) Copy() (Object, error)

func (*Dictionary) Document

func (dict *Dictionary) Document() *Document

func (*Dictionary) GetIndirectReference

func (dict *Dictionary) GetIndirectReference() *Reference

func (*Dictionary) Key

func (dict *Dictionary) Key(name Name) Object

func (*Dictionary) Kind

func (dict *Dictionary) Kind() ObjectKind

func (*Dictionary) MarshalPDF

func (dict *Dictionary) MarshalPDF(_ *Writer) error

MarshalPDF encodes the receiver a PDF bytes.

func (*Dictionary) Parent

func (dict *Dictionary) Parent() Object

func (*Dictionary) SetParent

func (dict *Dictionary) SetParent(_ Object)

type DictionaryElement

type DictionaryElement struct{ Element }

func (*DictionaryElement) Dictionary

func (e *DictionaryElement) Dictionary() *Dictionary

type Document

type Document struct {
	Objects []Object
}

func NewDocument

func NewDocument() *Document

type Element

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

func (*Element) Document

func (e *Element) Document() *Document

func (*Element) Object

func (e *Element) Object() Object

type Encrypt

type Encrypt interface{}

func NewEncrypt

func NewEncrypt() Encrypt

type FileSpec

type FileSpec struct{}

type FontManager

type FontManager struct{}

type Generation

type Generation uint16
const FirstGeneration Generation = 1

type GrayColor

type GrayColor color.Gray16

func ConvertToGrayScale

func ConvertToGrayScale(inColor Color) (gray GrayColor, err error)

func (GrayColor) ColorSpace

func (gray GrayColor) ColorSpace() ColorSpace

func (GrayColor) RGBA

func (gray GrayColor) RGBA() (r, g, b, a uint32)

func (*GrayColor) UnmarshalText

func (gray *GrayColor) UnmarshalText(text []byte) error

func (GrayColor) Validate

func (gray GrayColor) Validate() error

type IndirectObjectList

type IndirectObjectList struct{}

type Info

type Info struct{}

type Marshaler

type Marshaler interface {
	// MarshalPDF encodes the receiver a PDF bytes.
	MarshalPDF(*Writer) error
}

Marshaler is the interface implemented by PDF objects that can marshal themselves into valid PDF stream.

type MetaData

type MetaData struct{}

type Name

type Name string
const (
	KeyNull     Name = ""
	KeyContents Name = "Contents"
	KeyCount    Name = "Count"
	KeyEncrypt  Name = "Encrypt"
	KeyFilter   Name = "Filter"
	KeyFlags    Name = "Flags"
	KeyID       Name = "ID"
	KeyInfo     Name = "Info"
	KeyLength   Name = "Length"
	KeyRect     Name = "Rect"
	KeyRoot     Name = "Root"
	KeySize     Name = "Size"
	KeySubtype  Name = "Subtype"
	KeyType     Name = "Type"
	KeyMetadata Name = "Metadata"
	KeyTreeRoot Name = "StructTreeRoot"
	KeyMarkInfo Name = "MarkInfo"
	KeyLang     Name = "Lang"
	KeyPageMode Name = "PageMode"

	NameXRef Name = "XRef"
)

type NameObject

type NameObject struct {
	BaseObject

	Name Name
}

func (*NameObject) Copy

func (name *NameObject) Copy() (Object, error)

func (*NameObject) Document

func (name *NameObject) Document() *Document

func (*NameObject) GetIndirectReference

func (name *NameObject) GetIndirectReference() *Reference

func (*NameObject) Kind

func (name *NameObject) Kind() ObjectKind

func (*NameObject) MarshalPDF

func (name *NameObject) MarshalPDF(w *Writer) error

func (*NameObject) Parent

func (name *NameObject) Parent() Object

func (*NameObject) SetParent

func (name *NameObject) SetParent(parent Object)

type NameTree

type NameTree struct{}

type Number

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

func (*Number) Copy

func (num *Number) Copy() (Object, error)

func (*Number) Dictionary

func (num *Number) Dictionary() *Dictionary

func (*Number) Document

func (num *Number) Document() *Document

func (Number) Float64

func (num Number) Float64() float64

func (*Number) GetIndirectReference

func (num *Number) GetIndirectReference() *Reference

func (Number) Int

func (num Number) Int() int

func (Number) Int64

func (num Number) Int64() int64

func (*Number) Kind

func (num *Number) Kind() ObjectKind

func (*Number) MarshalPDF

func (num *Number) MarshalPDF(_ *Writer) error

MarshalPDF encodes the receiver a PDF bytes.

func (*Number) Parent

func (num *Number) Parent() Object

func (*Number) SetParent

func (num *Number) SetParent(_ Object)

type Object

type Object interface {
	Marshaler

	SetParent(Object)
	Parent() Object

	Kind() ObjectKind
	Copy() (Object, error)
	Document() *Document
	Dictionary() *Dictionary
	GetIndirectReference() *Reference
}

type ObjectKind

type ObjectKind uint8
const (
	// ObjectKindUnknown
	ObjectKindUnknown ObjectKind = iota
	// ObjectKindBool
	ObjectKindBool
	// ObjectKindNumber
	ObjectKindNumber
	// ObjectKindString
	ObjectKindString
	// ObjectKindName
	ObjectKindName
	// ObjectKindArray
	ObjectKindArray
	// ObjectKindDictionary
	ObjectKindDictionary
	// ObjectKindNull
	ObjectKindNull
	// ObjectKindReference
	ObjectKindReference
	// ObjectKindRawData
	ObjectKindRawData
)

type Outlines

type Outlines struct{}

type Page

type Page struct{}

type PageCollection

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

func NewPageCollection

func NewPageCollection(document *Document) *PageCollection

func (*PageCollection) AddPage

func (pc *PageCollection) AddPage(size Rect) *Page

func (*PageCollection) AddPageAt

func (pc *PageCollection) AddPageAt(index int, size Rect) (*Page, error)

func (*PageCollection) AppendDocumentPages

func (pc *PageCollection) AppendDocumentPages(
	document *Document, pageIndex int, count int,
) error

func (*PageCollection) Index

func (pc *PageCollection) Index(i int) (*Page, bool)

func (*PageCollection) InsertDocumentPages

func (pc *PageCollection) InsertDocumentPages(
	index int, document *Document, pageIndex int, count int,
) error

func (*PageCollection) Len

func (pc *PageCollection) Len() int

func (*PageCollection) RemovePage

func (pc *PageCollection) RemovePage(index int) bool

type PageLayout

type PageLayout uint8
const (
	PageLayoutIgnore PageLayout = iota
	PageLayoutDefault
	PageLayoutSinglePage
	PageLayoutOneColumn
	PageLayoutTwoColumnLeft
	PageLayoutTwoColumnRight
	PageLayoutTwoPageLeft
	PageLayoutTwoPageRight
)

type PageMode

type PageMode Name
const (
	PageModeDontCare       PageMode = ""
	PageModeUseNone        PageMode = "UseNone"
	PageModeUseThumbs      PageMode = "UseThumbs"
	PageModeUseBookmarks   PageMode = "UseBookmarks"
	PageModeFullScreen     PageMode = "FullScreen"
	PageModeUseOC          PageMode = "UseOC"
	PageModeUseAttachments PageMode = "UseAttachments"
)

type PageSize

type PageSize interface{ PageSize() Rect }

type PageSizeFunc

type PageSizeFunc func() Rect

func (PageSizeFunc) PageSize

func (f PageSizeFunc) PageSize() Rect

type Pos

type Pos struct {
	X float64
	Y float64
}

type RGBColor

type RGBColor color.NRGBA64

func ConvertToRGB

func ConvertToRGB(inColor Color) (rgb RGBColor, err error)

func (RGBColor) ColorSpace

func (rgb RGBColor) ColorSpace() ColorSpace

func (RGBColor) RGBA

func (rgb RGBColor) RGBA() (r, g, b, a uint32)

func (*RGBColor) UnmarshalText

func (rgb *RGBColor) UnmarshalText(text []byte) error

func (RGBColor) Validate

func (rgb RGBColor) Validate() error

type Rect

type Rect struct {
	Pos
	Size
}

func PageSizeA0

func PageSizeA0() Rect

func PageSizeA1

func PageSizeA1() Rect

func PageSizeA2

func PageSizeA2() Rect

func PageSizeA3

func PageSizeA3() Rect

func PageSizeA4

func PageSizeA4() Rect

func PageSizeA5

func PageSizeA5() Rect

func PageSizeA6

func PageSizeA6() Rect

func PageSizeLegal

func PageSizeLegal() Rect

func PageSizeLetter

func PageSizeLetter() Rect

func PageSizeTabloid

func PageSizeTabloid() Rect

type Reference

type Reference struct {
	ObjectNo     uint32
	GenerationNo Generation
}

func (Reference) IsIndirect

func (ref Reference) IsIndirect() bool

func (Reference) MarshalPDF

func (ref Reference) MarshalPDF(w *Writer) error

func (Reference) String

func (ref Reference) String() string

type SeparationColor

type SeparationColor struct {
	Name           string
	Density        float64
	AlternateColor Color
}

func SeparationColorAll

func SeparationColorAll() SeparationColor

func SeparationColorNone

func SeparationColorNone() SeparationColor

func (SeparationColor) ColorSpace

func (sep SeparationColor) ColorSpace() ColorSpace

func (SeparationColor) Validate

func (sep SeparationColor) Validate() error

type Size

type Size struct {
	Width  float64
	Height float64
}

type Trailer

type Trailer struct{}

type UTF8ToPDFDocEncoder

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

func NewUTF8ToDocEncoder

func NewUTF8ToDocEncoder(w io.Writer) *UTF8ToPDFDocEncoder

func (*UTF8ToPDFDocEncoder) Close

func (enc *UTF8ToPDFDocEncoder) Close() error

func (*UTF8ToPDFDocEncoder) Reset

func (enc *UTF8ToPDFDocEncoder) Reset(w io.Writer)

func (*UTF8ToPDFDocEncoder) Write

func (enc *UTF8ToPDFDocEncoder) Write(p []byte) (n int, err error)

type Variant

type Variant any

type Version

type Version string

Version is an enumeration for supported PDF versions.

const (
	// Version10 PDF 1.0.
	Version10 Version = "1.0"
	// Version11 PDF 1.1.
	Version11 Version = "1.1"
	// Version12 PDF 1.2.
	Version12 Version = "1.2"
	// Version13 PDF 1.3.
	Version13 Version = "1.3"
	// Version14 PDF 1.4.
	Version14 Version = "1.4"
	// Version15 PDF 1.5.
	Version15 Version = "1.5"
	// Version16 PDF 1.6.
	Version16 Version = "1.6"
	// Version17 PDF 1.7.
	Version17 Version = "1.7"
	// Version20 PDF 2.0
	Version20 Version = "2.0"
)

func (Version) Validate

func (ver Version) Validate() error

type WriteFlag

type WriteFlag uint16

WriteFlag is the flag that is used by the pdf.Writer.

const (
	// WriteFlagClean is used to created a PDF
	// that is readable in a text editor, i.e.
	// isert spaces and linebreaks between tokens.
	WriteFlagClean WriteFlag = 1 << iota
	// WriteFlagNoInlineLiteral is used to prevent writing spaces before literal types
	// (numerical, references, null).
	WriteFlagNoInlineLiteral
	// WriteFlagNoFlateCompress is used to write
	// PDF with Flate compression.
	WriteFlagNoFlateCompress
	// WriteFlagNoPDFAPreserve is used to write
	// compact (WriteFlagsClean is unsed) code,
	// preserving PDF/A compliance is not required.
	WriteFlagNoPDFAPreserve WriteFlag = 256
)

type Writer

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

func NewWriter

func NewWriter(w io.Writer, options ...WriterOptionFunc) *Writer

func (*Writer) HasFlag

func (w *Writer) HasFlag(flag WriteFlag) bool

func (*Writer) IsCleanWrite

func (w *Writer) IsCleanWrite() bool

func (*Writer) Write

func (w *Writer) Write(p []byte) (n int, err error)

func (*Writer) WriteByte

func (w *Writer) WriteByte(x byte) (err error)

type WriterOptionFunc

type WriterOptionFunc func(*Writer)

func WriteClean

func WriteClean() WriterOptionFunc

func WriteEncryptor

func WriteEncryptor(encrypt *Encrypt) WriterOptionFunc

func WriteNoCompress

func WriteNoCompress() WriterOptionFunc

func WriteNoInlineLiteral

func WriteNoInlineLiteral() WriterOptionFunc

func WriteNoPDFAPreserve

func WriteNoPDFAPreserve() WriterOptionFunc

Jump to

Keyboard shortcuts

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