pdf

package module
v0.0.0-...-484671e Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2023 License: BSD-2-Clause Imports: 12 Imported by: 0

README

This is a package for generating PDF files from Go. The most interesting feature is its font support.

Font Features

  • Supports both TrueType and OpenType fonts.
  • All text is UTF-8; supports any Unicode character (but only 255 per font).
  • Embeds font subsets, converted to Type 3 outline fonts.

Why Type 3?

PDF Type 3 fonts have a bad reputation, because they are often used for bitmap fonts. But it's actually a pretty nice format. The only real disadvantage is that it doesn't have hinting. I like the fact that it's PDF objects all the way down—no binary blobs.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Document

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

A Document represents a PDF document.

func (*Document) Encode

func (d *Document) Encode() []byte

func (*Document) LoadFont

func (d *Document) LoadFont(filename string) (*Font, error)

LoadFont loads a TrueType or OpenType font from the file specified. If it has already been loaded into this Document, the previous instance is returned instead of loading it again.

func (*Document) NewPage

func (d *Document) NewPage(width, height float64) *Page

type Font

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

type Page

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

func (*Page) Center

func (p *Page) Center(x, y float64, s string)

Center puts s on the page, centered at (x, y).

func (*Page) ClosePath

func (p *Page) ClosePath()

ClosePath closes the current subpath with a straight line to its starting point.

func (*Page) CurveTo

func (p *Page) CurveTo(x1, y1, x2, y2, x3, y3 float64)

CurveTo appends a cubic Bézier curve to the current path.

func (*Page) Fill

func (p *Page) Fill()

Fill fills the current path.

func (*Page) FillAndStroke

func (p *Page) FillAndStroke()

FillAndStroke fills and strokes the current path.

func (*Page) FillCMYK

func (p *Page) FillCMYK(c, m, y, k float64)

FillCMYK sets an CMYK color to be used by Fill. Each component is in the range from 0 to 1.

func (*Page) FillGray

func (p *Page) FillGray(g float64)

FillGray sets a grayscale value to be used by Fill. 0 is black and 1 is white.

func (*Page) FillRGB

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

FillRGB sets an RGB color to be used by Fill. Each component is in the range from 0 to 1.

func (*Page) Left

func (p *Page) Left(x, y float64, s string)

Left puts s on the page, left-aligned at (x, y).

func (*Page) LineTo

func (p *Page) LineTo(x, y float64)

LineTo adds a straight line to the current path.

func (*Page) MoveTo

func (p *Page) MoveTo(x, y float64)

MoveTo starts a new path or subpath at x, y.

func (*Page) Multiline

func (p *Page) Multiline(x, y float64, s string)

Multiline puts multiple lines of text on the page (splitting s at '\n'). It uses the line spacing set with Leading.

func (*Page) Right

func (p *Page) Right(x, y float64, s string)

Right puts s on the page, right-aligned at (x, y).

func (*Page) SetFont

func (p *Page) SetFont(f *Font, size float64)

func (*Page) SetLeading

func (p *Page) SetLeading(leading float64)

SetLeading sets the line spacing to be used by Multiline.

func (*Page) SetLineWidth

func (p *Page) SetLineWidth(w float64)

SetLineWidth sets the width of the line to be drawn by Stroke.

func (*Page) Stroke

func (p *Page) Stroke()

Stroke strokes the current path.

func (*Page) StrokeCMYK

func (p *Page) StrokeCMYK(c, m, y, k float64)

StrokeCMYK sets an CMYK color to be used by Stroke. Each component is in the range from 0 to 1.

func (*Page) StrokeGray

func (p *Page) StrokeGray(g float64)

StrokeGray sets a grayscale value to be used by Stroke. 0 is black and 1 is white.

func (*Page) StrokeRGB

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

StrokeRGB sets an RGB color to be used by Stroke. Each component is in the range from 0 to 1.

func (*Page) Translate

func (p *Page) Translate(x, y float64)

Translate offsets the page's coordinate system by x and y.

func (*Page) Truncate

func (p *Page) Truncate(x, y, width float64, s string)

Truncate displays s at (x, y), truncating it with an ellipsis if it is longer than width.

func (*Page) WordWrap

func (p *Page) WordWrap(x, y, margin float64, s string)

WordWrap displays s on multiple lines, wrapping at word boundaries to keep the width less than margin.

Jump to

Keyboard shortcuts

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