Documentation
¶
Overview ¶
Package document provides the domain model for PDF document creation.
This package contains the Document aggregate root and related entities following Domain-Driven Design (DDD) principles.
Index ¶
- Constants
- Variables
- func CMToPoints(cm float64) float64
- func CustomPageSize(widthPt, heightPt float64) types.Rectangle
- func InchesToPoints(inches float64) float64
- func MMToPoints(mm float64) float64
- func PointsToCM(points float64) float64
- func PointsToInches(points float64) float64
- func PointsToMM(points float64) float64
- type AnnotationType
- type Document
- func (d *Document) AddPage(pageSize PageSize) (*Page, error)
- func (d *Document) AddPageWithRect(rect types.Rectangle) (*Page, error)
- func (d *Document) Author() string
- func (d *Document) CreationDate() time.Time
- func (d *Document) Creator() string
- func (d *Document) InsertPage(index int, pageSize PageSize) (*Page, error)
- func (d *Document) Keywords() []string
- func (d *Document) ModificationDate() time.Time
- func (d *Document) Page(index int) (*Page, error)
- func (d *Document) PageCount() int
- func (d *Document) Pages() []*Page
- func (d *Document) Producer() string
- func (d *Document) RemovePage(index int) error
- func (d *Document) SetMetadata(title, author, subject string, keywords ...string)
- func (d *Document) Subject() string
- func (d *Document) Title() string
- func (d *Document) Validate() error
- func (d *Document) Version() types.Version
- type FormField
- func (f *FormField) AlternateText() string
- func (f *FormField) AnnotationFlags() int
- func (f *FormField) Appearance() string
- func (f *FormField) BorderColor() *[3]float64
- func (f *FormField) DefaultValue() string
- func (f *FormField) FieldType() string
- func (f *FormField) FillColor() *[3]float64
- func (f *FormField) Flags() int
- func (f *FormField) MaxLength() int
- func (f *FormField) Name() string
- func (f *FormField) Options() []string
- func (f *FormField) Rect() [4]float64
- func (f *FormField) SetAlternateText(text string)
- func (f *FormField) SetAnnotationFlags(flags int)
- func (f *FormField) SetAppearance(appearance string)
- func (f *FormField) SetBorderColor(r, g, b float64)
- func (f *FormField) SetDefaultValue(value string)
- func (f *FormField) SetFillColor(r, g, b float64)
- func (f *FormField) SetFlags(flags int)
- func (f *FormField) SetMaxLength(length int)
- func (f *FormField) SetOptions(options []string)
- func (f *FormField) SetValue(value string)
- func (f *FormField) Validate() error
- func (f *FormField) Value() string
- type LinkAnnotation
- type MarkupAnnotation
- type Page
- func (p *Page) AddAnnotation(a *LinkAnnotation) errordeprecated
- func (p *Page) AddContent(c content.Content) error
- func (p *Page) AddFormField(f *FormField) error
- func (p *Page) AddLinkAnnotation(a *LinkAnnotation) error
- func (p *Page) AddMarkupAnnotation(a *MarkupAnnotation) error
- func (p *Page) AddStampAnnotation(a *StampAnnotation) error
- func (p *Page) AddTextAnnotation(a *TextAnnotation) error
- func (p *Page) AnnotationCount() int
- func (p *Page) Annotations() []*LinkAnnotationdeprecated
- func (p *Page) ClearAnnotations()
- func (p *Page) ClearContent()
- func (p *Page) ContentCount() int
- func (p *Page) Contents() []content.Content
- func (p *Page) CropBox() *types.Rectangle
- func (p *Page) FormFields() []*FormField
- func (p *Page) Height() float64
- func (p *Page) LinkAnnotations() []*LinkAnnotation
- func (p *Page) MarkupAnnotations() []*MarkupAnnotation
- func (p *Page) MediaBox() types.Rectangle
- func (p *Page) Number() int
- func (p *Page) Rotation() int
- func (p *Page) SetCropBox(box types.Rectangle) error
- func (p *Page) SetRotation(degrees int) error
- func (p *Page) StampAnnotations() []*StampAnnotation
- func (p *Page) TextAnnotations() []*TextAnnotation
- func (p *Page) Validate() error
- func (p *Page) Width() float64
- type PageSize
- type StampAnnotation
- type StampName
- type TextAnnotation
Constants ¶
const ( // PointsPerInch is the number of points in one inch. // 1 inch = 72 points (PostScript/PDF standard) PointsPerInch = 72.0 // PointsPerMM is the number of points in one millimeter. // 1 mm = 72/25.4 ≈ 2.83465 points PointsPerMM = 72.0 / 25.4 // PointsPerCM is the number of points in one centimeter. // 1 cm = 72/2.54 ≈ 28.3465 points PointsPerCM = 72.0 / 2.54 )
Variables ¶
var ( // ErrInvalidAnnotationRect is returned when annotation rect is invalid. ErrInvalidAnnotationRect = errors.New("annotation rectangle must have x1 < x2 and y1 < y2") // ErrInvalidBorderWidth is returned when border width is negative. ErrInvalidBorderWidth = errors.New("border width must be non-negative") // ErrInvalidDestPage is returned when internal link destination is invalid. ErrInvalidDestPage = errors.New("destination page must be >= 0") // ErrEmptyURI is returned when external link has no URI. ErrEmptyURI = errors.New("external link must have a URI") // ErrInvalidColor is returned when color components are out of range. ErrInvalidColor = errors.New("color components must be in range [0.0, 1.0]") // ErrMissingQuadPoints is returned when markup annotation has no QuadPoints. ErrMissingQuadPoints = errors.New("markup annotation must have QuadPoints") // ErrMissingStampName is returned when stamp annotation has no name. ErrMissingStampName = errors.New("stamp annotation must have a name") )
Annotation errors.
var ( // ErrInvalidPageIndex is returned when a page index is out of bounds. ErrInvalidPageIndex = errors.New("invalid page index") // ErrEmptyDocument is returned when validating a document with no pages. ErrEmptyDocument = errors.New("document has no pages") )
Domain errors
var ( // ErrInvalidRotation is returned when rotation is not 0, 90, 180, or 270. ErrInvalidRotation = errors.New("rotation must be 0, 90, 180, or 270") // ErrInvalidPageSize is returned when page dimensions are invalid. ErrInvalidPageSize = errors.New("invalid page size: width and height must be positive") // ErrCropBoxOutOfBounds is returned when crop box exceeds media box. ErrCropBoxOutOfBounds = errors.New("crop box must be within media box bounds") // ErrNilContent is returned when trying to add nil content to a page. ErrNilContent = errors.New("content cannot be nil") // ErrNilAnnotation is returned when trying to add nil annotation to a page. ErrNilAnnotation = errors.New("annotation cannot be nil") // ErrNilFormField is returned when trying to add nil form field to a page. ErrNilFormField = errors.New("form field cannot be nil") )
Domain errors
Functions ¶
func CustomPageSize ¶
CustomPageSize creates a custom page size in points.
Points are 1/72 of an inch.
Example:
// Create a custom 6×9 inch page customSize := document.CustomPageSize(6*72, 9*72)
func InchesToPoints ¶
InchesToPoints converts inches to points.
func PointsToCM ¶
PointsToCM converts points to centimeters.
func PointsToInches ¶
PointsToInches converts points to inches.
func PointsToMM ¶
PointsToMM converts points to millimeters.
Types ¶
type AnnotationType ¶
type AnnotationType int
AnnotationType represents the type of PDF annotation.
const ( // AnnotationTypeLink represents a clickable link annotation. AnnotationTypeLink AnnotationType = iota // AnnotationTypeText represents a sticky note annotation. AnnotationTypeText // AnnotationTypeHighlight represents a highlight markup annotation. AnnotationTypeHighlight // AnnotationTypeUnderline represents an underline markup annotation. AnnotationTypeUnderline // AnnotationTypeStrikeOut represents a strikeout markup annotation. AnnotationTypeStrikeOut // AnnotationTypeStamp represents a rubber stamp annotation. AnnotationTypeStamp )
type Document ¶
type Document struct {
// contains filtered or unexported fields
}
Document is the aggregate root for PDF document creation.
It manages the collection of pages and ensures document-level consistency. All modifications to the document go through this entity (Rich Domain Model).
Example:
doc := document.NewDocument()
doc.SetMetadata("My Document", "Author Name", "Subject")
page, _ := doc.AddPage(document.A4)
doc.Validate()
func NewDocument ¶
func NewDocument() *Document
NewDocument creates a new empty PDF document.
The document is initialized with: - PDF version 1.7 - Creation/modification dates set to now - Creator and producer set to "gxpdf" - Empty pages collection
func (*Document) AddPage ¶
AddPage adds a new page to the document.
Returns the newly created page for method chaining.
Example:
page, err := doc.AddPage(document.A4)
if err != nil {
return err
}
// Use page...
func (*Document) AddPageWithRect ¶ added in v0.4.0
AddPageWithRect adds a new page to the document with explicitly specified dimensions.
widthPt and heightPt are the page dimensions in PDF points (1 pt = 1/72 inch). Use CustomPageSize to build the rectangle, or InchesToPoints/MMToPoints to convert.
Returns the newly created page for method chaining.
Example:
// A custom 6×9 inch page rect := document.CustomPageSize(6*72, 9*72) page, err := doc.AddPageWithRect(rect)
func (*Document) CreationDate ¶
CreationDate returns the document creation date.
func (*Document) InsertPage ¶
InsertPage inserts a page at the specified index.
This will renumber all subsequent pages.
Returns an error if the index is out of bounds.
func (*Document) ModificationDate ¶
ModificationDate returns the last modification date.
func (*Document) Page ¶
Page returns the page at the specified index (0-based).
Returns an error if the index is out of bounds.
func (*Document) Pages ¶
Pages returns all pages in the document.
The returned slice is a copy to prevent external modifications.
func (*Document) RemovePage ¶
RemovePage removes the page at the specified index.
This will renumber all subsequent pages.
Returns an error if the index is out of bounds.
func (*Document) SetMetadata ¶
SetMetadata sets document metadata.
Empty strings are ignored (existing values are kept).
Example:
doc.SetMetadata("My Document", "John Doe", "Annual Report", "2025", "PDF", "Report")
type FormField ¶
type FormField struct {
// contains filtered or unexported fields
}
FormField represents an interactive form field widget annotation.
Form fields are special annotations that allow user input. They are part of the AcroForm (Interactive Form) system in PDF.
This is a value object that represents the PDF Widget annotation combined with the form field dictionary.
PDF Structure:
<< /Type /Annot /Subtype /Widget /FT /Tx % Field Type (Tx=Text, Btn=Button, Ch=Choice, Sig=Signature) /T (fieldName) % Field name /V (value) % Field value /DV (defaultValue) % Default value /Rect [x1 y1 x2 y2] % Position /F 4 % Annotation flags (4 = Print) /Ff 0 % Field flags /DA (/Helv 12 Tf 0 g) % Default appearance /MaxLen 100 % Max length (text fields only) >>
func NewFormField ¶
NewFormField creates a new form field.
Parameters:
- fieldType: PDF field type (Tx, Btn, Ch, Sig)
- name: Unique field name
- rect: Position and size [x1, y1, x2, y2]
Example:
field := NewFormField("Tx", "username", [4]float64{100, 700, 300, 720})
func (*FormField) AlternateText ¶
AlternateText returns the alternate text.
func (*FormField) AnnotationFlags ¶
AnnotationFlags returns the annotation flags.
func (*FormField) Appearance ¶
Appearance returns the default appearance string.
func (*FormField) BorderColor ¶
BorderColor returns the border color (nil if no border).
func (*FormField) DefaultValue ¶
DefaultValue returns the default value.
func (*FormField) SetAlternateText ¶
SetAlternateText sets the alternate text for accessibility.
func (*FormField) SetAnnotationFlags ¶
SetAnnotationFlags sets the annotation flags (F).
func (*FormField) SetAppearance ¶
SetAppearance sets the default appearance string (/DA).
Example appearance strings:
- "/Helv 12 Tf 0 g" - Helvetica 12pt, black
- "/Courier 10 Tf 1 0 0 rg" - Courier 10pt, red
func (*FormField) SetBorderColor ¶
SetBorderColor sets the border color.
func (*FormField) SetDefaultValue ¶
SetDefaultValue sets the default value.
func (*FormField) SetFillColor ¶
SetFillColor sets the fill color.
func (*FormField) SetMaxLength ¶
SetMaxLength sets the maximum text length (text fields only).
func (*FormField) SetOptions ¶
SetOptions sets the choice options (choice fields only).
type LinkAnnotation ¶
type LinkAnnotation struct {
// Rect defines the clickable area [x1, y1, x2, y2] in PDF coordinates.
// (x1, y1) is the lower-left corner, (x2, y2) is the upper-right corner.
Rect [4]float64
// URI is the target URL (for external links).
// Empty for internal links.
URI string
// DestPage is the target page number (for internal links, 0-based).
// -1 for external links.
DestPage int
// IsInternal indicates if this is an internal page link.
// true = internal page link (use DestPage)
// false = external URL link (use URI)
IsInternal bool
// BorderWidth is the width of the border around the clickable area.
// 0 = no visible border (default for most links).
BorderWidth float64
}
LinkAnnotation represents a clickable link in a PDF.
Link annotations create clickable areas (hot spots) on PDF pages. They can point to external URLs or internal page destinations.
Example:
// External link
link := NewLinkAnnotation([4]float64{100, 690, 200, 710}, "https://example.com")
// Internal link to page 3
link := NewInternalLinkAnnotation([4]float64{100, 690, 200, 710}, 2)
func NewInternalLinkAnnotation ¶
func NewInternalLinkAnnotation(rect [4]float64, destPage int) *LinkAnnotation
NewInternalLinkAnnotation creates a new internal page link.
The destPage parameter is 0-based (0 = first page, 1 = second page, etc.).
Example:
link := NewInternalLinkAnnotation([4]float64{100, 690, 200, 710}, 2) // Link to page 3
func NewLinkAnnotation ¶
func NewLinkAnnotation(rect [4]float64, uri string) *LinkAnnotation
NewLinkAnnotation creates a new URL link annotation.
The rect parameter defines the clickable area in PDF coordinates: [x1, y1, x2, y2] where (x1, y1) is lower-left, (x2, y2) is upper-right.
Example:
link := NewLinkAnnotation([4]float64{100, 690, 200, 710}, "https://google.com")
func (*LinkAnnotation) Validate ¶
func (a *LinkAnnotation) Validate() error
Validate checks if the link annotation is valid.
Returns an error if: - Rectangle is invalid (x1 >= x2 or y1 >= y2) - External link has empty URI - Internal link has invalid destination page (< 0) - Border width is negative
type MarkupAnnotation ¶
type MarkupAnnotation struct {
// Type is the markup type (Highlight, Underline, StrikeOut).
Type AnnotationType
// Rect defines the bounding box [x1, y1, x2, y2] in PDF coordinates.
Rect [4]float64
// QuadPoints defines the area to mark up.
// Each quadrilateral is [x1, y1, x2, y2, x3, y3, x4, y4].
// Points go: top-left, top-right, bottom-left, bottom-right.
QuadPoints [][8]float64
// Color is the annotation color in RGB (0.0 to 1.0 range).
Color [3]float64
// Title is the author name (T field in PDF).
Title string
// Contents is the optional note text.
Contents string
}
MarkupAnnotation represents a markup annotation (highlight, underline, strikeout).
Markup annotations highlight, underline, or strike through text. They use QuadPoints to define the area (4 points per quadrilateral).
Example:
// Highlight from (100, 650) to (300, 670)
highlight := NewMarkupAnnotation(
AnnotationTypeHighlight,
[4]float64{100, 650, 300, 670},
[][8]float64{{100, 670, 300, 670, 100, 650, 300, 650}},
)
func NewMarkupAnnotation ¶
func NewMarkupAnnotation(annotType AnnotationType, rect [4]float64, quadPoints [][8]float64) *MarkupAnnotation
NewMarkupAnnotation creates a new markup annotation.
The quadPoints should be in PDF coordinates (top-left, top-right, bottom-left, bottom-right).
Example:
highlight := NewMarkupAnnotation(
AnnotationTypeHighlight,
[4]float64{100, 650, 300, 670},
[][8]float64{{100, 670, 300, 670, 100, 650, 300, 650}},
)
func (*MarkupAnnotation) SetAuthor ¶
func (a *MarkupAnnotation) SetAuthor(author string)
SetAuthor sets the author name.
func (*MarkupAnnotation) SetColor ¶
func (a *MarkupAnnotation) SetColor(color [3]float64)
SetColor sets the markup color.
func (*MarkupAnnotation) SetContents ¶
func (a *MarkupAnnotation) SetContents(contents string)
SetContents sets the note text.
func (*MarkupAnnotation) Validate ¶
func (a *MarkupAnnotation) Validate() error
Validate checks if the markup annotation is valid.
type Page ¶
type Page struct {
// contains filtered or unexported fields
}
Page represents a single page in a PDF document.
Pages contain content elements and have properties like size, rotation, etc. This is an entity within the Document aggregate.
Example:
page := document.NewPage(0, document.A4) page.SetRotation(90) // Landscape width := page.Width()
func NewPage ¶
NewPage creates a new page with the specified size.
The page number is 0-based and should correspond to its position in the document.
Example:
page := document.NewPage(0, document.A4)
func (*Page) AddAnnotation
deprecated
func (p *Page) AddAnnotation(a *LinkAnnotation) error
AddAnnotation adds a link annotation to the page.
Deprecated: Use AddLinkAnnotation instead. This method is kept for backward compatibility.
Returns an error if: - Annotation is nil - Annotation validation fails
Example:
link := NewLinkAnnotation([4]float64{100, 690, 200, 710}, "https://example.com")
err := page.AddAnnotation(link)
func (*Page) AddContent ¶
AddContent adds a content element to the page.
Returns an error if: - Content is nil - Content validation fails
Example:
text := &TextContent{...}
err := page.AddContent(text)
func (*Page) AddFormField ¶
AddFormField adds a form field annotation to the page.
Returns an error if: - Form field is nil - Form field validation fails
Example:
field := NewFormField("Tx", "username", [4]float64{100, 700, 300, 720})
err := page.AddFormField(field)
func (*Page) AddLinkAnnotation ¶
func (p *Page) AddLinkAnnotation(a *LinkAnnotation) error
AddLinkAnnotation adds a link annotation to the page.
Returns an error if: - Annotation is nil - Annotation validation fails
Example:
link := NewLinkAnnotation([4]float64{100, 690, 200, 710}, "https://example.com")
err := page.AddLinkAnnotation(link)
func (*Page) AddMarkupAnnotation ¶
func (p *Page) AddMarkupAnnotation(a *MarkupAnnotation) error
AddMarkupAnnotation adds a markup annotation (highlight, underline, strikeout) to the page.
Returns an error if: - Annotation is nil - Annotation validation fails
Example:
highlight := NewMarkupAnnotation(
AnnotationTypeHighlight,
[4]float64{100, 650, 300, 670},
[][4]float64{{100, 670, 300, 670, 100, 650, 300, 650}},
)
err := page.AddMarkupAnnotation(highlight)
func (*Page) AddStampAnnotation ¶
func (p *Page) AddStampAnnotation(a *StampAnnotation) error
AddStampAnnotation adds a stamp annotation to the page.
Returns an error if: - Annotation is nil - Annotation validation fails
Example:
stamp := NewStampAnnotation([4]float64{300, 700, 400, 750}, StampApproved)
err := page.AddStampAnnotation(stamp)
func (*Page) AddTextAnnotation ¶
func (p *Page) AddTextAnnotation(a *TextAnnotation) error
AddTextAnnotation adds a text (sticky note) annotation to the page.
Returns an error if: - Annotation is nil - Annotation validation fails
Example:
note := NewTextAnnotation([4]float64{100, 700, 120, 720}, "Important!", "Alice")
err := page.AddTextAnnotation(note)
func (*Page) AnnotationCount ¶
AnnotationCount returns the total number of annotations on the page.
func (*Page) Annotations
deprecated
func (p *Page) Annotations() []*LinkAnnotation
Annotations returns all link annotations on the page.
Deprecated: Use LinkAnnotations instead. This method is kept for backward compatibility.
The returned slice is a copy to prevent external modifications.
func (*Page) ClearAnnotations ¶
func (p *Page) ClearAnnotations()
ClearAnnotations removes all annotations from the page.
func (*Page) ClearContent ¶
func (p *Page) ClearContent()
ClearContent removes all content from the page.
func (*Page) ContentCount ¶
ContentCount returns the number of content elements on the page.
func (*Page) Contents ¶
Contents returns all content elements on the page.
The returned slice is a copy to prevent external modifications.
func (*Page) CropBox ¶
CropBox returns the page's crop box (visible area).
Returns nil if no crop box is set (media box is used).
func (*Page) FormFields ¶
FormFields returns all form field annotations on the page.
The returned slice is a copy to prevent external modifications.
func (*Page) Height ¶
Height returns the page height in points.
If the page is rotated 90 or 270 degrees, width and height are swapped.
func (*Page) LinkAnnotations ¶
func (p *Page) LinkAnnotations() []*LinkAnnotation
LinkAnnotations returns all link annotations on the page.
The returned slice is a copy to prevent external modifications.
func (*Page) MarkupAnnotations ¶
func (p *Page) MarkupAnnotations() []*MarkupAnnotation
MarkupAnnotations returns all markup annotations on the page.
The returned slice is a copy to prevent external modifications.
func (*Page) SetCropBox ¶
SetCropBox sets the crop box (visible area of the page).
The crop box must be within or equal to the media box.
func (*Page) SetRotation ¶
SetRotation sets the page rotation (0, 90, 180, 270 degrees).
Rotation is applied clockwise.
Returns an error if the rotation is not one of the valid values.
func (*Page) StampAnnotations ¶
func (p *Page) StampAnnotations() []*StampAnnotation
StampAnnotations returns all stamp annotations on the page.
The returned slice is a copy to prevent external modifications.
func (*Page) TextAnnotations ¶
func (p *Page) TextAnnotations() []*TextAnnotation
TextAnnotations returns all text annotations on the page.
The returned slice is a copy to prevent external modifications.
type PageSize ¶
type PageSize int
PageSize represents standard PDF page sizes.
Standard sizes are provided as constants for convenience. For custom sizes, use CustomPageSize().
const ( // A4 is 210 × 297 mm (8.27 × 11.69 in) - Most common international paper size. A4 PageSize = iota // A3 is 297 × 420 mm (11.69 × 16.54 in) - Twice the area of A4. A3 // A5 is 148 × 210 mm (5.83 × 8.27 in) - Half the area of A4. A5 // B4 is 250 × 353 mm (9.84 × 13.90 in) - Between A3 and A4. B4 // B5 is 176 × 250 mm (6.93 × 9.84 in) - Between A4 and A5. B5 // Letter is 8.5 × 11 in (215.9 × 279.4 mm) - Standard US/Canada paper size. Letter // Legal is 8.5 × 14 in (215.9 × 355.6 mm) - US legal documents. Legal // Tabloid is 11 × 17 in (279.4 × 431.8 mm) - Also known as Ledger. Tabloid // A0 is 841 × 1189 mm (2384 × 3370 pt) - Largest common A-series size. A0 // A1 is 594 × 841 mm (1684 × 2384 pt). A1 // A2 is 420 × 594 mm (1191 × 1684 pt). A2 // A6 is 105 × 148 mm (298 × 420 pt) - Postcard size. A6 // A7 is 74 × 105 mm (210 × 298 pt). A7 // A8 is 52 × 74 mm (147 × 210 pt). A8 // B0 is 1000 × 1414 mm (2835 × 4008 pt). B0 // B1 is 707 × 1000 mm (2004 × 2835 pt). B1 // B2 is 500 × 707 mm (1417 × 2004 pt). B2 // B3 is 353 × 500 mm (1001 × 1417 pt). B3 // B6 is 125 × 176 mm (354 × 499 pt). B6 // C4 is 229 × 324 mm (649 × 918 pt) - A4 envelope. C4 // C5 is 162 × 229 mm (459 × 649 pt) - A5 envelope. C5 // C6 is 114 × 162 mm (323 × 459 pt) - A6 envelope. C6 // DL is 110 × 220 mm (312 × 624 pt) - Long envelope (fits A4 folded in thirds). DL // Executive is 7.25 × 10.5 in (522 × 756 pt) - US executive paper. Executive // HalfLetter is 5.5 × 8.5 in (396 × 612 pt) - Half US letter. HalfLetter // ANSIC is 17 × 22 in (1224 × 1584 pt) - ANSI C engineering drawing. ANSIC // ANSID is 22 × 34 in (1584 × 2448 pt) - ANSI D engineering drawing. ANSID // ANSIE is 34 × 44 in (2448 × 3168 pt) - ANSI E engineering drawing. ANSIE // Photo4x6 is 4 × 6 in (288 × 432 pt) - Standard 4×6 photo print. Photo4x6 // Photo5x7 is 5 × 7 in (360 × 504 pt) - Standard 5×7 photo print. Photo5x7 // Photo8x10 is 8 × 10 in (576 × 720 pt) - Standard 8×10 photo print. Photo8x10 // Digest is 5.5 × 8.5 in (396 × 612 pt) - Digest magazine size. Digest // USTradeBook is 6 × 9 in (432 × 648 pt) - Standard US trade book. USTradeBook // Slide16x9 is a widescreen presentation slide at 16:9 aspect ratio (960 × 540 pt). // Equivalent to 13.33 × 7.5 inches — matches PowerPoint/Keynote widescreen default. // This size is already landscape-oriented (width > height). // When exported at 2× DPI (144 dpi), this produces a 1920 × 1080 pixel image. Slide16x9 // Slide4x3 is a standard presentation slide at 4:3 aspect ratio (720 × 540 pt). // Equivalent to 10 × 7.5 inches — matches the traditional slide format. // This size is already landscape-oriented (width > height). Slide4x3 // Envelope10 is a #10 commercial envelope (4.125 × 9.5 in, 297 × 684 pt). Envelope10 // JISB4 is 257 × 364 mm (729 × 1032 pt) - Japanese B4. JISB4 // JISB5 is 182 × 257 mm (516 × 729 pt) - Japanese B5. JISB5 // Custom indicates a custom page size (use CustomPageSize function). Custom )
func (PageSize) ToRectangle ¶
ToRectangle converts PageSize to Rectangle (in points, 1 point = 1/72 inch).
All standard page sizes are returned in portrait orientation. For landscape, use Creator.NewPageWithSize with the Landscape option.
Example:
rect := document.A4.ToRectangle() // rect is 595×842 points (210×297mm)
type StampAnnotation ¶
type StampAnnotation struct {
// Rect defines the stamp location [x1, y1, x2, y2] in PDF coordinates.
Rect [4]float64
// Name is the stamp name (e.g., "Approved", "Draft", "Confidential").
Name string
// Color is the annotation color in RGB (0.0 to 1.0 range).
Color [3]float64
// Title is the author name (T field in PDF).
Title string
// Contents is the optional note text.
Contents string
}
StampAnnotation represents a rubber stamp annotation (/Subtype /Stamp).
Stamp annotations display predefined stamps like "Approved", "Draft", etc.
Example:
stamp := NewStampAnnotation([4]float64{300, 700, 400, 750}, "Approved")
stamp.SetColor([3]float64{0, 1, 0}) // Green
func NewStampAnnotation ¶
func NewStampAnnotation(rect [4]float64, name StampName) *StampAnnotation
NewStampAnnotation creates a new stamp annotation.
Example:
stamp := NewStampAnnotation([4]float64{300, 700, 400, 750}, StampApproved)
func (*StampAnnotation) SetAuthor ¶
func (a *StampAnnotation) SetAuthor(author string)
SetAuthor sets the author name.
func (*StampAnnotation) SetColor ¶
func (a *StampAnnotation) SetColor(color [3]float64)
SetColor sets the stamp color.
func (*StampAnnotation) SetContents ¶
func (a *StampAnnotation) SetContents(contents string)
SetContents sets the note text.
func (*StampAnnotation) Validate ¶
func (a *StampAnnotation) Validate() error
Validate checks if the stamp annotation is valid.
type StampName ¶
type StampName string
StampName represents predefined stamp names.
const ( // StampApproved represents an "Approved" stamp. StampApproved StampName = "Approved" // StampNotApproved represents a "Not Approved" stamp. StampNotApproved StampName = "NotApproved" // StampDraft represents a "Draft" stamp. StampDraft StampName = "Draft" // StampFinal represents a "Final" stamp. StampFinal StampName = "Final" // StampConfidential represents a "Confidential" stamp. StampConfidential StampName = "Confidential" // StampForComment represents a "For Comment" stamp. StampForComment StampName = "ForComment" // StampForPublicRelease represents a "For Public Release" stamp. StampForPublicRelease StampName = "ForPublicRelease" // StampAsIs represents an "As Is" stamp. StampAsIs StampName = "AsIs" // StampDepartmental represents a "Departmental" stamp. StampDepartmental StampName = "Departmental" // StampExperimental represents an "Experimental" stamp. StampExperimental StampName = "Experimental" // StampExpired represents an "Expired" stamp. StampExpired StampName = "Expired" // StampNotForPublicRelease represents a "Not For Public Release" stamp. StampNotForPublicRelease StampName = "NotForPublicRelease" )
type TextAnnotation ¶
type TextAnnotation struct {
// Rect defines the icon location [x1, y1, x2, y2] in PDF coordinates.
// Typically a small square (e.g., 20x20 points).
Rect [4]float64
// Contents is the text displayed in the pop-up.
Contents string
// Title is the author name (T field in PDF).
Title string
// Color is the annotation color in RGB (0.0 to 1.0 range).
// Default: [1, 1, 0] (yellow).
Color [3]float64
// Open indicates if the pop-up should be open by default.
Open bool
}
TextAnnotation represents a sticky note annotation (/Subtype /Text).
Text annotations appear as icons (sticky notes) on the page. They display pop-up text when clicked.
Example:
note := NewTextAnnotation([4]float64{100, 700, 120, 720}, "This is a comment", "John Doe")
note.SetColor([3]float64{1, 1, 0}) // Yellow
func NewTextAnnotation ¶
func NewTextAnnotation(rect [4]float64, contents, title string) *TextAnnotation
NewTextAnnotation creates a new text (sticky note) annotation.
Example:
note := NewTextAnnotation([4]float64{100, 700, 120, 720}, "Important!", "Alice")
func (*TextAnnotation) SetColor ¶
func (a *TextAnnotation) SetColor(color [3]float64)
SetColor sets the annotation color.
func (*TextAnnotation) SetOpen ¶
func (a *TextAnnotation) SetOpen(open bool)
SetOpen sets whether the pop-up is open by default.
func (*TextAnnotation) Validate ¶
func (a *TextAnnotation) Validate() error
Validate checks if the text annotation is valid.