Documentation
¶
Overview ¶
Package pdf provides a PDF export backend for gg's recording system.
This package registers a "pdf" backend that can be used to export recorded drawing operations to PDF format using the gxpdf library.
Usage ¶
Import this package with a blank identifier to register the PDF backend:
import _ "github.com/gogpu/gg-pdf"
Then use recording.NewBackend("pdf") to create a PDF backend:
backend, err := recording.NewBackend("pdf")
if err != nil {
log.Fatal(err)
}
// Record drawing operations
rec := recording.NewRecorder(800, 600)
// ... draw ...
r := rec.Finish()
// Playback to PDF backend
r.Playback(backend)
// Save to file
if fb, ok := backend.(recording.FileBackend); ok {
fb.SaveToFile("output.pdf")
}
Index ¶
- type Backend
- func (b *Backend) Begin(width, height int) error
- func (b *Backend) ClearClip()
- func (b *Backend) DrawImage(img image.Image, src, dst recording.Rect, opts recording.ImageOptions)
- func (b *Backend) DrawText(s string, x, y float64, face text.Face, brush recording.Brush)
- func (b *Backend) End() error
- func (b *Backend) FillPath(path *gg.Path, brush recording.Brush, rule recording.FillRule)
- func (b *Backend) FillRect(rect recording.Rect, brush recording.Brush)
- func (b *Backend) Restore()
- func (b *Backend) Save()
- func (b *Backend) SaveToFile(path string) error
- func (b *Backend) SetClip(path *gg.Path, rule recording.FillRule)
- func (b *Backend) SetTransform(m recording.Matrix)
- func (b *Backend) StrokePath(path *gg.Path, brush recording.Brush, stroke recording.Stroke)
- func (b *Backend) WriteTo(w io.Writer) (int64, error)
- type Document
- func (d *Document) Finish() error
- func (d *Document) NewPage(width, height int) recording.Backend
- func (d *Document) PageCount() int
- func (d *Document) Playback(rec *recording.Recording) error
- func (d *Document) SaveToFile(path string) error
- func (d *Document) SetAuthor(author string)
- func (d *Document) SetKeywords(keywords string)
- func (d *Document) SetSubject(subject string)
- func (d *Document) SetTitle(title string)
- func (d *Document) WriteTo(w io.Writer) (int64, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Backend ¶
type Backend struct {
// contains filtered or unexported fields
}
Backend implements recording.Backend for PDF output. It uses gxpdf to generate PDF documents from recorded drawing commands.
PDF coordinates use a bottom-left origin, while gg uses a top-left origin. This backend handles the coordinate transformation automatically.
func NewBackend ¶
func NewBackend() *Backend
NewBackend creates a new PDF backend. The backend starts in an uninitialized state. Call Begin() to initialize with specific dimensions before drawing.
func (*Backend) Begin ¶
Begin initializes the backend for rendering at the given dimensions. This creates a new PDF document with a single page of the specified size.
func (*Backend) ClearClip ¶
func (b *Backend) ClearClip()
ClearClip removes any clipping region. Note: PDF doesn't support clearing clips, so this is a no-op warning. Proper clip management should use Save/Restore.
func (*Backend) DrawImage ¶
DrawImage draws an image from the source rectangle to the destination rectangle.
func (*Backend) DrawText ¶
DrawText draws text at the given position with the specified font face and brush.
func (*Backend) End ¶
End finalizes the rendering and prepares the output. After End is called, WriteTo and SaveToFile can be used to get the PDF.
func (*Backend) Restore ¶
func (b *Backend) Restore()
Restore restores the graphics state from the stack.
func (*Backend) SaveToFile ¶
SaveToFile saves the PDF to a file at the given path. This implements recording.FileBackend.
func (*Backend) SetTransform ¶
SetTransform sets the current transformation matrix. The transform is in gg coordinates (top-left origin).
func (*Backend) StrokePath ¶
StrokePath strokes the given path with the brush and stroke style.
type Document ¶
type Document struct {
// contains filtered or unexported fields
}
Document provides multi-page PDF document support. Unlike Backend which creates a single-page PDF, Document allows creating multiple pages with different sizes.
Example:
doc := pdf.NewDocument()
// First page
backend := doc.NewPage(800, 600)
// ... draw on first page ...
// Second page
backend = doc.NewPage(600, 800)
// ... draw on second page ...
doc.SaveToFile("output.pdf")
func (*Document) Finish ¶
Finish finalizes all pages in the document. This must be called before WriteTo or SaveToFile.
func (*Document) NewPage ¶
NewPage creates a new page with the given dimensions and returns a backend for it. Each call to NewPage adds a new page to the document. The returned backend can be used with recording.Playback() to draw on the page.
func (*Document) Playback ¶
Playback replays a recording to a new page with the recording's dimensions. This is a convenience method that creates a page and plays the recording to it.
func (*Document) SaveToFile ¶
SaveToFile saves the PDF to a file at the given path. Finish() is called automatically if not already called.
func (*Document) SetKeywords ¶
SetKeywords sets the document keywords metadata.
func (*Document) SetSubject ¶
SetSubject sets the document subject metadata.