Documentation ¶
Overview ¶
Package pdf implements a Portable Document Format writer, as defined in ISO 32000-1.
An example of basic usage:
package main import ( "bitbucket.org/zombiezen/gopdf/pdf" "fmt" "os" ) func main() { doc := pdf.New() canvas := doc.NewPage(pdf.USLetterWidth, pdf.USLetterHeight) canvas.Translate(100, 100) path := new(pdf.Path) path.Move(pdf.Point{0, 0}) path.Line(pdf.Point{100, 0}) canvas.Stroke(path) text := new(pdf.Text) text.SetFont(pdf.Helvetica, 14) text.Text("Hello, World!") canvas.DrawText(text) canvas.Close() err := doc.Encode(os.Stdout) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } }
Index ¶
- Constants
- type Canvas
- func (canvas *Canvas) Close() error
- func (canvas *Canvas) CropBox() Rectangle
- func (canvas *Canvas) Document() *Document
- func (canvas *Canvas) DrawImage(img image.Image, rect Rectangle)
- func (canvas *Canvas) DrawImageReference(ref Reference, rect Rectangle)
- func (canvas *Canvas) DrawLine(pt1, pt2 Point)
- func (canvas *Canvas) DrawText(text *Text)
- func (canvas *Canvas) Fill(p *Path)
- func (canvas *Canvas) FillStroke(p *Path)
- func (canvas *Canvas) Pop()
- func (canvas *Canvas) Push()
- func (canvas *Canvas) Rotate(theta float32)
- func (canvas *Canvas) Scale(x, y float32)
- func (canvas *Canvas) SetColor(r, g, b float32)
- func (canvas *Canvas) SetCropBox(crop Rectangle)
- func (canvas *Canvas) SetLineDash(phase Unit, dash []Unit)
- func (canvas *Canvas) SetLineWidth(w Unit)
- func (canvas *Canvas) SetSize(width, height Unit)
- func (canvas *Canvas) SetStrokeColor(r, g, b float32)
- func (canvas *Canvas) Size() (width, height Unit)
- func (canvas *Canvas) Stroke(p *Path)
- func (canvas *Canvas) Transform(a, b, c, d, e, f float32)
- func (canvas *Canvas) Translate(x, y Unit)
- type Document
- type Path
- type Point
- type Rectangle
- type Reference
- type Text
- type Unit
Constants ¶
const ( Courier = "Courier" CourierBold = "Courier-Bold" CourierOblique = "Courier-Oblique" CourierBoldOblique = "Courier-BoldOblique" Helvetica = "Helvetica" HelveticaBold = "Helvetica-Bold" HelveticaOblique = "Helvetica-Oblique" HelveticaBoldOblique = "Helvetica-BoldOblique" Symbol = "Symbol" Times = "Times-Roman" TimesBold = "Times-Bold" TimesItalic = "Times-Italic" TimesBoldItalic = "Times-BoldItalic" ZapfDingbats = "ZapfDingbats" )
Standard 14 fonts
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Canvas ¶
type Canvas struct {
// contains filtered or unexported fields
}
Canvas is a two-dimensional drawing region on a single page. You can obtain a canvas once you have created a document.
func (*Canvas) Close ¶
Close flushes the page's stream to the document. This must be called once drawing has completed or else the document will be inconsistent.
func (*Canvas) DrawImage ¶
DrawImage paints a raster image at the given location and scaled to the given dimensions. If you want to render the same image multiple times in the same document, use DrawImageReference.
func (*Canvas) DrawImageReference ¶
DrawImageReference paints the raster image referenced in the document at the given location and scaled to the given dimensions.
func (*Canvas) DrawLine ¶
DrawLine paints a straight line from pt1 to pt2 using the current stroke color and line width.
func (*Canvas) FillStroke ¶
FillStroke fills then strokes the given path. This operation has the same effect as performing a fill then a stroke, but does not repeat the path in the file.
func (*Canvas) Pop ¶
func (canvas *Canvas) Pop()
Pop restores the most recently saved graphics state by popping it from the stack.
func (*Canvas) Push ¶
func (canvas *Canvas) Push()
Push saves a copy of the current graphics state. The state can later be restored using Pop.
func (*Canvas) Rotate ¶
Rotate rotates the canvas's coordinate system by a given angle (in radians).
func (*Canvas) SetColor ¶
SetColor changes the current fill color to the given RGB triple (in device RGB space).
func (*Canvas) SetCropBox ¶
SetCropBox changes the page's crop box.
func (*Canvas) SetLineDash ¶
SetLineDash changes the line dash pattern in the current graphics state. Examples:
c.SetLineDash(0, []Unit{}) // solid line c.SetLineDash(0, []Unit{3}) // 3 units on, 3 units off... c.SetLineDash(0, []Unit{2, 1}) // 2 units on, 1 unit off... c.SetLineDash(1, []Unit{2}) // 1 unit on, 2 units off, 2 units on...
func (*Canvas) SetLineWidth ¶
SetLineWidth changes the stroke width to the given value.
func (*Canvas) SetStrokeColor ¶
SetStrokeColor changes the current stroke color to the given RGB triple (in device RGB space).
type Document ¶
type Document struct {
// contains filtered or unexported fields
}
Document provides a high-level drawing interface for the PDF format.
func (*Document) AddImage ¶
AddImage encodes an image into the document's stream and returns its PDF file reference. This reference can be used to draw the image multiple times without storing the image multiple times.
type Path ¶
type Path struct {
// contains filtered or unexported fields
}
Path is a shape that can be painted on a canvas. The zero value is an empty path.
func (*Path) Close ¶
func (path *Path) Close()
Close appends a line segment from the current point to the starting point of the subpath.
type Rectangle ¶
type Rectangle struct {
Min, Max Point
}
A Rectangle defines a rectangle with two points.
type Text ¶
type Text struct {
// contains filtered or unexported fields
}
Text is a PDF text object. The zero value is an empty text object.
func (*Text) NextLine ¶
func (text *Text) NextLine()
NextLine advances the current text position to the next line, based on the current leading.
func (*Text) NextLineOffset ¶
NextLineOffset moves the current text position to an offset relative to the beginning of the line.
func (*Text) SetFont ¶
SetFont changes the current font to a standard font. This also changes the leading to 1.2 times the font size.
func (*Text) SetLeading ¶
SetLeading changes the amount of space between lines.