pdf

package
v0.0.0-...-2a131dc Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	A4Width      = 595.28
	A4Height     = 841.89
	LetterWidth  = 612.0
	LetterHeight = 792.0
)

Standard PDF page sizes in points (1 point = 1/72 inch)

Variables

This section is empty.

Functions

func EncodeImageAsXObject

func EncodeImageAsXObject(img image.Image, quality int) ([]byte, error)

EncodeImageAsXObject encodes an image.Image as a PDF image XObject dictionary+stream. Returns the raw object content ready to be embedded via w.set(). For JPEG source bytes, use EncodeJPEGAsXObject instead to avoid re-encoding.

func EncodeJPEGAsXObject

func EncodeJPEGAsXObject(jpegBytes []byte, width, height int) ([]byte, error)

EncodeJPEGAsXObject wraps already-encoded JPEG bytes as a PDF image XObject.

func ReadImage

func ReadImage(r io.Reader) (image.Image, string, error)

ReadImage decodes an image from r (JPEG or PNG).

Types

type Page

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

Page accumulates the content stream for a single PDF page. All coordinates are in PDF user space: origin at bottom-left, Y increases upwards Callers work in top-left document space and convert via Page.toY()

func (*Page) DrawLine

func (p *Page) DrawLine(x1, y1, x2, y2, lineWidth, r, g, b float64)

DrawLine strokes a horizontal or vertical rule

func (*Page) DrawRect

func (p *Page) DrawRect(x, y, w, h, r, g, b float64)

DrawRect draws a filled rectangle in top-left document coordinates. (x, y) is the top-left corner.

func (*Page) DrawText

func (p *Page) DrawText(x, y float64, text string)

DrawText renders a UTF-8 strings at doc-space (x, y). y is the baseline position in top-left document coordinates.

func (*Page) PlaceImage

func (p *Page) PlaceImage(name string, x, y, w, h float64)

PlaceImage renders a named XObject (image) at doc-space position. width and height are the rendered dimensions in points.

func (*Page) SetFillColor

func (p *Page) SetFillColor(r, g, b float64)

SetFillColor sets the fill color using normalized RGB (0.0-1.0)

func (*Page) SetFont

func (p *Page) SetFont(name string, size float64)

SetFont sets the active font and size. name must be a key in the page resource dictionary (e.g "F1")

type Writer

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

Writer constructs a PDF 1.4 document Usage:

w := NewWriter() pg := w.AddPage(A4Width, A4Height) pg.SetFont("F1", 12) pg.DrawText(72, 72, "Hello, PDF") pdf, err := w.Write()

func NewWriter

func NewWriter() *Writer

NewWriter returns an empty PDF writer.

func (*Writer) AddPage

func (w *Writer) AddPage(width, height float64) *Page

AddPage adds a new page of the given dimensions and returns it for drawing

func (*Writer) Write

func (w *Writer) Write() ([]byte, error)

Write serialises the entier PDF and returns the bytes

Jump to

Keyboard shortcuts

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