types

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package valueobjects contains value objects used across the domain.

Package valueobjects provides immutable value objects for the PDF domain.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// ErrEmptyImageData is returned when image data is empty.
	ErrEmptyImageData = errors.New("image data cannot be empty")

	// ErrInvalidImageDimensions is returned when image dimensions are invalid.
	ErrInvalidImageDimensions = errors.New("image dimensions must be positive")

	// ErrInvalidBitsPerComponent is returned when bits per component is invalid.
	ErrInvalidBitsPerComponent = errors.New("bits per component must be between 1 and 16")
)

Domain errors

View Source
var (
	// A4 represents A4 page size (210mm x 297mm = 595pt x 842pt).
	A4 = MustRectangle(0, 0, 595.276, 841.890)

	// Letter represents US Letter size (8.5in x 11in = 612pt x 792pt).
	Letter = MustRectangle(0, 0, 612, 792)

	// Legal represents US Legal size (8.5in x 14in = 612pt x 1008pt).
	Legal = MustRectangle(0, 0, 612, 1008)

	// A3 represents A3 page size (297mm x 420mm = 842pt x 1191pt).
	A3 = MustRectangle(0, 0, 841.890, 1190.551)

	// A5 represents A5 page size (148mm x 210mm = 420pt x 595pt).
	A5 = MustRectangle(0, 0, 419.528, 595.276)
)

Common page sizes as constants.

View Source
var (
	// PDF10 represents PDF 1.0 (1993).
	PDF10 = Version{1, 0}

	// PDF11 represents PDF 1.1 (1996).
	PDF11 = Version{1, 1}

	// PDF12 represents PDF 1.2 (1996).
	PDF12 = Version{1, 2}

	// PDF13 represents PDF 1.3 (2000).
	PDF13 = Version{1, 3}

	// PDF14 represents PDF 1.4 (2001).
	PDF14 = Version{1, 4}

	// PDF15 represents PDF 1.5 (2003).
	PDF15 = Version{1, 5}

	// PDF16 represents PDF 1.6 (2004).
	PDF16 = Version{1, 6}

	// PDF17 represents PDF 1.7 (2008) - ISO 32000-1.
	PDF17 = Version{1, 7}

	// PDF20 represents PDF 2.0 (2017) - ISO 32000-2.
	PDF20 = Version{2, 0}
)

Common PDF versions.

View Source
var (
	// ErrInvalidRectangle is returned when rectangle dimensions are invalid.
	ErrInvalidRectangle = errors.New("invalid rectangle: upper-right must be greater than lower-left")
)
View Source
var (
	// ErrInvalidVersion is returned when a PDF version string is malformed.
	ErrInvalidVersion = errors.New("invalid PDF version")
)

Functions

This section is empty.

Types

type Image

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

Image represents an extracted PDF image with metadata.

This is a value object containing image data and properties. Images are immutable once created.

Example:

img := NewImage(data, width, height, "DeviceRGB", 8, "/DCTDecode")
img.SaveToFile("output.jpg")
goImg, _ := img.ToGoImage()

func NewImage

func NewImage(data []byte, width, height int, colorSpace string, bitsPerComponent int, filter string) (*Image, error)

NewImage creates a new Image value object.

Parameters:

  • data: Raw image data (decoded or compressed)
  • width: Image width in pixels
  • height: Image height in pixels
  • colorSpace: PDF color space name
  • bitsPerComponent: Bits per color component (typically 8)
  • filter: Original PDF filter (e.g., "/DCTDecode")

Returns error if parameters are invalid.

func (*Image) BitsPerComponent

func (img *Image) BitsPerComponent() int

BitsPerComponent returns bits per color component.

func (*Image) ColorSpace

func (img *Image) ColorSpace() string

ColorSpace returns the PDF color space name.

func (*Image) Data

func (img *Image) Data() []byte

Data returns the raw image data.

func (*Image) Equals

func (img *Image) Equals(other *Image) bool

Equals checks if two images are equal.

Two images are equal if they have the same dimensions, color space, bits per component, and data.

func (*Image) Filter

func (img *Image) Filter() string

Filter returns the original PDF filter.

func (*Image) Height

func (img *Image) Height() int

Height returns the image height in pixels.

func (*Image) Name

func (img *Image) Name() string

Name returns the XObject name.

func (*Image) SaveToFile

func (img *Image) SaveToFile(path string) error

SaveToFile saves the image to a file.

The file format is determined by the extension:

  • .jpg, .jpeg: JPEG format (best for DCTDecode images)
  • .png: PNG format (best for lossless images)

For DCTDecode images, the original data is saved directly. For other formats, the image is encoded to the target format.

Parameters:

  • path: Output file path

Returns error if file cannot be written.

func (*Image) SetName

func (img *Image) SetName(name string)

SetName sets the XObject name (for internal use).

func (*Image) String

func (img *Image) String() string

String returns a string representation of the image.

func (*Image) ToGoImage

func (img *Image) ToGoImage() (image.Image, error)

ToGoImage converts the image to Go's image.Image.

This is useful for further processing or saving in different formats.

Returns error if conversion fails.

func (*Image) Width

func (img *Image) Width() int

Width returns the image width in pixels.

type Rectangle

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

Rectangle represents an immutable PDF rectangle. In PDF, a rectangle is defined by two points: lower-left (llx, lly) and upper-right (urx, ury). This is a Value Object in DDD terms - immutable and compared by value.

func MustRectangle

func MustRectangle(llx, lly, urx, ury float64) Rectangle

MustRectangle creates a Rectangle and panics on error. Use only when you're certain the dimensions are valid (e.g., constants).

func NewRectangle

func NewRectangle(llx, lly, urx, ury float64) (Rectangle, error)

NewRectangle creates a new Rectangle with validation. Returns error if dimensions are invalid (urx <= llx or ury <= lly).

func (Rectangle) Contains

func (r Rectangle) Contains(x, y float64) bool

Contains checks if a point (x, y) is within the rectangle.

func (Rectangle) Equals

func (r Rectangle) Equals(other Rectangle) bool

Equals checks if two rectangles are equal (value comparison).

func (Rectangle) Height

func (r Rectangle) Height() float64

Height returns the height of the rectangle.

func (Rectangle) LowerLeft

func (r Rectangle) LowerLeft() (x, y float64)

LowerLeft returns the lower-left corner coordinates.

func (Rectangle) String

func (r Rectangle) String() string

String returns a string representation of the rectangle.

func (Rectangle) UpperRight

func (r Rectangle) UpperRight() (x, y float64)

UpperRight returns the upper-right corner coordinates.

func (Rectangle) Width

func (r Rectangle) Width() float64

Width returns the width of the rectangle.

Example

Example test (doubles as documentation).

rect := A4
width := rect.Width()
println(width) // Approximately 595.276

func (Rectangle) WithOffset

func (r Rectangle) WithOffset(dx, dy float64) Rectangle

WithOffset returns a new Rectangle offset by (dx, dy). This maintains immutability - returns new instance instead of modifying.

type Version

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

Version represents a PDF version (e.g., 1.4, 1.7, 2.0). This is a Value Object - immutable and compared by value.

func NewVersion

func NewVersion(major, minor int) (Version, error)

NewVersion creates a new Version from major and minor numbers.

func ParseVersion

func ParseVersion(s string) (Version, error)

ParseVersion parses a PDF version string (e.g., "1.4", "PDF-1.7", "2.0").

func (Version) AtLeast

func (v Version) AtLeast(major, minor int) bool

AtLeast checks if this version is at least the specified version.

func (Version) Compare

func (v Version) Compare(other Version) int

Compare compares two versions. Returns -1 if v < other, 0 if v == other, 1 if v > other.

func (Version) Equals

func (v Version) Equals(other Version) bool

Equals checks if two versions are equal.

func (Version) Major

func (v Version) Major() int

Major returns the major version number.

func (Version) Minor

func (v Version) Minor() int

Minor returns the minor version number.

func (Version) String

func (v Version) String() string

String returns the version as a string (e.g., "1.7").

Jump to

Keyboard shortcuts

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