Documentation
¶
Overview ¶
Package valueobjects contains value objects used across the domain.
Package valueobjects provides immutable value objects for the PDF domain.
Index ¶
- Variables
- type Image
- func (img *Image) BitsPerComponent() int
- func (img *Image) ColorSpace() string
- func (img *Image) Data() []byte
- func (img *Image) Equals(other *Image) bool
- func (img *Image) Filter() string
- func (img *Image) Height() int
- func (img *Image) Name() string
- func (img *Image) SaveToFile(path string) error
- func (img *Image) SetName(name string)
- func (img *Image) String() string
- func (img *Image) ToGoImage() (image.Image, error)
- func (img *Image) Width() int
- type Rectangle
- func (r Rectangle) Contains(x, y float64) bool
- func (r Rectangle) Equals(other Rectangle) bool
- func (r Rectangle) Height() float64
- func (r Rectangle) LowerLeft() (x, y float64)
- func (r Rectangle) String() string
- func (r Rectangle) UpperRight() (x, y float64)
- func (r Rectangle) Width() float64
- func (r Rectangle) WithOffset(dx, dy float64) Rectangle
- type Version
Examples ¶
Constants ¶
This section is empty.
Variables ¶
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
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.
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.
var ( // ErrInvalidRectangle is returned when rectangle dimensions are invalid. ErrInvalidRectangle = errors.New("invalid rectangle: upper-right must be greater than lower-left") )
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 ¶
BitsPerComponent returns bits per color component.
func (*Image) ColorSpace ¶
ColorSpace returns the PDF color space name.
func (*Image) Equals ¶
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) SaveToFile ¶
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.
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 ¶
MustRectangle creates a Rectangle and panics on error. Use only when you're certain the dimensions are valid (e.g., constants).
func NewRectangle ¶
NewRectangle creates a new Rectangle with validation. Returns error if dimensions are invalid (urx <= llx or ury <= lly).
func (Rectangle) UpperRight ¶
UpperRight returns the upper-right corner coordinates.
func (Rectangle) Width ¶
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 ¶
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 ¶
NewVersion creates a new Version from major and minor numbers.
func ParseVersion ¶
ParseVersion parses a PDF version string (e.g., "1.4", "PDF-1.7", "2.0").
func (Version) Compare ¶
Compare compares two versions. Returns -1 if v < other, 0 if v == other, 1 if v > other.