gpdf

package module
v0.0.0-...-6e902d7 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2026 License: MIT Imports: 4 Imported by: 0

README

gpdf

Generate PDF using high-level objects (text, lines, curves, shapes) using a percentage-based coordinate system.

Placemat

gpdf-api

Initialize

canvas, err := SetupCanvas(width, height float64) (*Canvas, error)

Set page background

(c *Canvas) Background(color string)

Line between (x0,y0) and (x1, y1)

(c *Canvas) Line(x0, y0, x1, y1, size float64, color string, opacity ...float64)

Filled circle centered at (x,y) with radius r

(c *Canvas) Circle(x, y, r float64, color string, opacity ...float64)

Filled ellipse centered at (x,y), dimensions (w,h)

(c *Canvas) Ellipse(x, y, w, h float64, color string, opacity ...float64)

Filled rectangle upper left corner at (x,y), dimensions (w,h)

(c *Canvas) CornerRect(x, y, w, h float64, color string, opacity ...float64)

Filled rectangle centered at (x,y), dimensions (w,h)

(c *Canvas) Rect(x, y, w, h float64, color string, opacity ...float64)

Gradient filled rectangle

(c *Canvas) GradRect(x, y, w, h float64, color1 string, color2 string, percent float64)

Filled square centered at (x,y), both sized are w.

(c *Canvas) Square(x,y, w, float64 color string, opacity ...float64)

Text beginning at (x,y) at the specified size and color

(c *Canvas) Text(x, y, size float64, s string, color string, opacity ...float64)

(c *Canvas) BText(x, y, size float64, s string, color string, opacity ...float64)

Text centered at (x,y) at the specified size and color

(c *Canvas) CText(x, y, size float64, s string, color string, opacity ...float64)

Text end-aligned at (x,y) at the specified size and color

(c *Canvas) EText(x, y, size float64, s string, color string, opacity ...float64)

Rotated text at the specified angle, anchored at (x,y), with the specified size and color

(c *Canvas) RText(x, y, size, angle float64, s string, color string, opacity ...float64)

Filled polygon with specified coordinates

(c *Canvas) Polygon(x, y []float64, color string, opacity ...float64)

Stroked polyline with specified coordinates

(c *Canvas) Polyline(x, y []float64, size, color string, opacity ...float64)

Cubic Bezier curve; begin (bx,by), control1 (cx1,cy1), control2 (cx2,cy2), end (ex,ey), with specifed stroke size and color

(c *Canvas) CubicCurve(bx, by, cx1, cy1, cx2, cy2, ex, ey, size float64, strokecolor string, opacity ...float64)

Quadradic Bezier curve; begin (bx,by), control (cx,cy), end (ex,ey), with specifed stroke size and color

(c *Canvas) QuadCurve(bx, by, cx, cy, ex, ey, size float64, color string, opacity ...float64)

Circular arc; center at (x,y), radius r, between angles a1 and s2 (degrees), with specifed stroke size and color

(c *Canvas) Arc(x, y, r, a1, a2, size float64, fillcolor string, opacity ...float64)

Image centered at (x,y), dimensions (w, h)

(c *Canvas) ImageName(x, y, w, h float64, name string)

Plain and labeled grids between (xmin,ymin) and (xmax,ymax) at the specified increment, using specified size and color

(c *Canvas) Grid(xmin, xmax, ymin, ymax, size, incr float64, color string)

(c *Canvas) LGrid(xmin, xmax, ymin, ymax, size, incr float64, color string, opacity ...float64)

hello, world

hello

Documentation

Overview

gpdf generates PDF using a %-based coordinate system, with high-level functions for page elements absolute coordinate methods

gpdf generates PDF using a %-based coordinate system, with high-level functions for page elements color processing

gpdf generates PDF using a %-based coordinate system, with high-level functions for page elements convenience functions

gpdf generates PDF using a %-based coordinate system, with high-level functions for page elements

gpdf generates PDF using a %-based coordinate system, with high-level functions for page elements percentage-based methods

Index

Constants

View Source
const (
	Letter  = creator.Letter
	Legal   = creator.Legal
	Tabloid = creator.Tabloid
	A3      = creator.A3
	A4      = creator.A4
	A5      = creator.A5
	B4      = creator.B4

	Mono  = creator.Courier
	Sans  = creator.Helvetica
	Serif = creator.TimesRoman
)

built-in pagesizes and fonts

Variables

This section is empty.

Functions

func ColorLookup

func ColorLookup(s string) creator.ColorRGBA

ColorLookup returns a color.RGBA corresponding to the named color or "rgb(r)", "rgb(r,b)", "rgb(r,g,b), "rgb(r,g,b,a)", "#rr", "#rrgg", "#rrggbb", "#rrggbbaa" string. "hsv(hue,sat,value)" On error, return black.

func MapRange

func MapRange(value, low1, high1, low2, high2 float64) float64

MapRange maps a value between low1 and high1, return the corresponding value between low2 and high2

Types

type CF

type CF *creator.CustomFont

type Canvas

type Canvas struct {
	Page          *creator.Page
	Creator       *creator.Creator
	StdFont       creator.FontName
	CustomFont    *creator.CustomFont
	Width, Height float64
}

Canvas object

func SetupCanvas

func SetupCanvas(width, height float64) (*Canvas, error)

SetupCanvas nitializes the canvas object, with specified dimensions

func SetupCanvasStdSize

func SetupCanvasStdSize(pagesize creator.PageSize) (*Canvas, error)

SetupCanvas initializes the canvas object with a standard page size

func (*Canvas) AbsArc

func (c *Canvas) AbsArc(x, y, w, h, a1, a2, size float64, color creator.ColorRGBA)

AbsArc makes an arc centered at (x,y), width(w), height(h)

func (*Canvas) AbsBText

func (c *Canvas) AbsBText(x, y, size float64, s string, fillcolor creator.ColorRGBA)

AbsBText is a wrapper for AbsText

func (*Canvas) AbsCText

func (c *Canvas) AbsCText(x, y, size float64, s string, fillcolor creator.ColorRGBA)

AbsCText centered at (x,y)

func (*Canvas) AbsCenterImage

func (c *Canvas) AbsCenterImage(x, y, w, h float64, img *creator.Image) error

AbsCenterImage places an image centered at (x,y),dimensions of (w,h)

func (*Canvas) AbsCenterImageName

func (c *Canvas) AbsCenterImageName(x, y, w, h float64, name string) error

AbsCenterImageName places a named image at centered at (x,y), dimensions of (w,h)

func (*Canvas) AbsCenterRect

func (c *Canvas) AbsCenterRect(x, y, w, h float64, color creator.ColorRGBA)

AbsCenterRect makes a rectangle centered (x,y), width(w), height(h)

func (*Canvas) AbsCircle

func (c *Canvas) AbsCircle(x, y, r float64, color creator.ColorRGBA)

AbsCircle makes a circle centered at (x,y) with radius r

func (*Canvas) AbsCornerRect

func (c *Canvas) AbsCornerRect(x, y, w, h float64, color creator.ColorRGBA)

func (*Canvas) AbsCubicBezier

func (c *Canvas) AbsCubicBezier(bx, by, c0x, c0y, c1x, c1y, ex, ey, size float64, color creator.ColorRGBA)

AbsCubicBezier makes a stroked cubic Bezier begin (bx, by), control points at (c0x,c0y) and (c1x, c1y) end point at (ex,ey)

func (*Canvas) AbsEText

func (c *Canvas) AbsEText(x, y, size float64, s string, fillcolor creator.ColorRGBA)

AbsEText which text end at (x,y)

func (*Canvas) AbsEllipse

func (c *Canvas) AbsEllipse(x, y, w, h float64, color creator.ColorRGBA)

AbsEllipse make an ellipse centered at (x,y), width(w), height(h)

func (*Canvas) AbsGradRect

func (c *Canvas) AbsGradRect(x, y, w, h float64, color1, color2 creator.ColorRGBA, percent float64)

AbsGradRect makes a gradient filled rectangle lower left at (x,y), width(w), height(h)

func (*Canvas) AbsImage

func (c *Canvas) AbsImage(x, y, w, h float64, name string) error

AbsImage places a named image at (x,y) (lower left), dimensions of (w,h)

func (*Canvas) AbsLine

func (c *Canvas) AbsLine(x0, y0, x1, y1, size float64, color creator.ColorRGBA)

AbsLine draws a line from (x0,y0) to (x1, y1)

func (*Canvas) AbsPolygon

func (c *Canvas) AbsPolygon(x, y []float64, color creator.ColorRGBA)

AbsPolygon makes a filled polygon using coordinates in x and y

func (*Canvas) AbsQuadBezier

func (c *Canvas) AbsQuadBezier(bx, by, cx, cy, ex, ey, size float64, color creator.ColorRGBA)

AbsQuadBezier makes a stroked quadradic Bezier curve begin (bx, by), control (cx, cy), end (ex, ey)

func (*Canvas) AbsRText

func (c *Canvas) AbsRText(x, y, size, angle float64, s string, color creator.ColorRGBA)

AbsRText makes rotated text anchored at (x,y), at angle

func (*Canvas) AbsText

func (c *Canvas) AbsText(x, y, size float64, s string, color creator.ColorRGBA)

AbsText makes text anchored at (x,y)

func (*Canvas) Arc

func (c *Canvas) Arc(x, y, w, h, a1, a2, size float64, fillcolor string, opacity ...float64)

Arc makes a stroked arc, using percentage-based measures center is (x, y), the arc begins at angle a1, and ends at a2, with radius r. The arc is stroked with the specified stroke size and color

func (*Canvas) BText

func (c *Canvas) BText(x, y, size float64, s string, fillcolor string, opacity ...float64)

BText places text begin aligned at (x,y) at the specified size and color

func (*Canvas) Background

func (c *Canvas) Background(fillcolor string)

Background set the page background color

func (*Canvas) CText

func (c *Canvas) CText(x, y, size float64, s string, fillcolor string, opacity ...float64)

CText places text centered at (x,y) at the specified size and color

func (*Canvas) Circle

func (c *Canvas) Circle(x, y, r float64, fillcolor string, opacity ...float64)

Circle makes a color filled circle centered at (x, y) with radius r

func (*Canvas) Coord

func (c *Canvas) Coord(x, y, size float64, s string, fillcolor string)

Coord shows the specified coordinate, using percentage-based coordinates the (x, y) label is above the point, with a label below

func (*Canvas) CornerRect

func (c *Canvas) CornerRect(x, y, w, h float64, fillcolor string, opacity ...float64)

CornerRect a color filled rectangle lower left at (x,y), with dimentions (w,h)

func (*Canvas) CubicCurve

func (c *Canvas) CubicCurve(bx, by, cx1, cy1, cx2, cy2, ex, ey, size float64, strokecolor string, opacity ...float64)

CubicCurve draws a quadradic bezier curve begin coordinates (bx, by) control coordinates (cx, cy) end coordinates at (ex, ey)

func (*Canvas) Curve

func (c *Canvas) Curve(bx, by, cx, cy, ex, ey, size float64, strokecolor string, opacity ...float64)

Curve makes a quadradic bezier curve

func (*Canvas) EText

func (c *Canvas) EText(x, y, size float64, s string, fillcolor string, opacity ...float64)

EText places text end-aligned at (x,y) at the specified size and color

func (*Canvas) Ellipse

func (c *Canvas) Ellipse(x, y, w, h float64, fillcolor string, opacity ...float64)

Ellipse draws an ellipse centered at (x, y) with dimensions (w,h)

func (*Canvas) GradRect

func (c *Canvas) GradRect(x, y, w, h float64, color1 string, color2 string, percent float64)

GradRect makes a rectangle filled with a gradient

func (*Canvas) Grid

func (c *Canvas) Grid(xmin, xmax, ymin, ymax, size, incr float64, color string)

Grid makes a unlabeled coordinate grid starting at (xmin, ymin) ending at (xmax, ymax), line width is size, incr is the size of the grid

func (*Canvas) Image

func (c *Canvas) Image(x, y, w, h float64, img Pimage)

Image places an image centered at (x,y), with dimensions (w,h)

func (*Canvas) ImageName

func (c *Canvas) ImageName(x, y, w, h float64, name string)

ImageName places a named image centered at (x,y), with dimensions (w,h)

func (*Canvas) ImageScale

func (c *Canvas) ImageScale(x, y, w, h, scale float64, img Pimage)

func (*Canvas) ImageScaleName

func (c *Canvas) ImageScaleName(x, y, w, h, scale float64, name string)

func (*Canvas) LGrid

func (c *Canvas) LGrid(xmin, xmax, ymin, ymax, size, incr float64, color string, opacity ...float64)

Grid makes a labeled coordinate grid starting at (xmin, ymin) ending at (xmax, ymax), line width is size, incr is the size of the grid

func (*Canvas) Line

func (c *Canvas) Line(x0, y0, x1, y1, size float64, strokecolor string, opacity ...float64)

Line strokes a colored line from (x0, y0) to (x1, y1)

func (*Canvas) LoadFontFile

func (c *Canvas) LoadFontFile(path string) (*creator.CustomFont, error)

LoadFont loads a custom font

func (*Canvas) LoadImage

func (c *Canvas) LoadImage(name string) (Pimage, error)

LoadImage loads a named image into the Pimage struct

func (*Canvas) NewPage

func (c *Canvas) NewPage(width, height float64) error

NewPage starts a new Page

func (*Canvas) Polar

func (c *Canvas) Polar(cx, cy, r, theta float64) (float64, float64)

Polar returns the Cartesian coordinates (x, y) from polar coordinates with compensation for canvas aspect ratio center at (cx, cy), radius r, and angle theta (radians)

func (*Canvas) PolarDegrees

func (c *Canvas) PolarDegrees(cx, cy, r, theta float64) (float64, float64)

PolarDegrees returns the Cartesian coordinates (x, y) from polar coordinates with compensation for canvas aspect ratio center at (cx, cy), radius r, and angle theta (degrees)

func (*Canvas) Polygon

func (c *Canvas) Polygon(x, y []float64, fillcolor string, opacity ...float64)

Polygon makes a color filled polygon using the specified coordinates in x and y

func (*Canvas) Polyline

func (c *Canvas) Polyline(x, y []float64, size float64, strokecolor string, opacity ...float64)

Polyline makes connected lines using coordinates in x and y

func (*Canvas) QuadCurve

func (c *Canvas) QuadCurve(bx, by, cx, cy, ex, ey, size float64, strokecolor string, opacity ...float64)

QuadCurve draws a quadradic bezier curve begin coordinates (bx, by) control coordinates (cx, cy) end coordinates at (ex, ey)

func (*Canvas) RText

func (c *Canvas) RText(x, y, size, angle float64, s string, fillcolor string, opacity ...float64)

RText places text end-aligned at (x,y) at the specified size and color

func (*Canvas) Rect

func (c *Canvas) Rect(x, y, w, h float64, fillcolor string, opacity ...float64)

Rect makes a color filled rectangle centered at (x,y), with dimentions (w,h)

func (*Canvas) SetAuthor

func (c *Canvas) SetAuthor(s string)

SetAuthor sets the document author

func (*Canvas) SetFont

func (c *Canvas) SetFont(f *creator.CustomFont)

SetFont specifes the current font

func (*Canvas) SetTitle

func (c *Canvas) SetTitle(s string)

SetTitle sets the document title

func (*Canvas) Square

func (c *Canvas) Square(x, y, w float64, fillcolor string, opacity ...float64)

Square makes a square centered at (x,y), at size w

func (*Canvas) Text

func (c *Canvas) Text(x, y, size float64, s string, fillcolor string, opacity ...float64)

Text places text at (x,y) at the specified size and color

func (*Canvas) TextWrap

func (c *Canvas) TextWrap(x, y, w, size, linespacing float64, s string, textcolor string, opacity ...float64)

TextWrap wraps text at the width

func (*Canvas) TextWrapStrict

func (c *Canvas) TextWrapStrict(x, y, w, size, linespacing float64, s string, textcolor string, opacity ...float64)

TextWrap wraps text at the width, using strict mode

type Pimage

type Pimage struct {
	Image         *creator.Image
	Width, Height float64
}

Directories

Path Synopsis
hello, world
hello, world
radbar - radial barchart
radbar - radial barchart

Jump to

Keyboard shortcuts

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