Documentation
¶
Overview ¶
Package print prints through the system print dialog: the page shown in a WebView surface, PDF documents and images. It also saves a page as a PDF file without any dialog.
err := print.Page(s, print.Options{Title: "Invoice 42"})
if errors.Is(err, print.ErrCanceled) { ... }
err = print.PDF(app, pdfBytes, print.Options{Parent: s, Copies: 2})
err = print.SavePDF(s, "/tmp/page.pdf")
Every function blocks until the dialog is closed and the job was handed to the printing system (not until paper comes out). Called on the main thread it keeps the app's event loop running meanwhile (not on Android, see docs/mobile.md). Errors: ErrUnsupported where the platform cannot do it (see docs/print.md for the matrix), ErrCanceled when the user dismissed the dialog and the platform reports it, tango.ErrNotRunning after the app quit.
The package name shadows the print builtin in files that import it; import it under another name (printing "…/sys/print") if that matters.
Index ¶
- Variables
- func File(a *tango.App, path string, o Options) error
- func Image(a *tango.App, img image.Image, o Options) error
- func ImagePDF(imgs ...image.Image) ([]byte, error)
- func IsPDF(data []byte) bool
- func PDF(a *tango.App, data []byte, o Options) error
- func Page(s *tango.Surface, o Options) error
- func SavePDF(s *tango.Surface, path string) error
- type Options
Constants ¶
This section is empty.
Variables ¶
var ( ErrUnsupported = platform.ErrUnsupported ErrCanceled = platform.ErrCanceled )
Functions ¶
func File ¶
File prints a PDF document or a GIF, JPEG or PNG image file. Images are printed as one page each through PDF (see ImagePDF).
func ImagePDF ¶
ImagePDF returns a PDF document with one page per image, each page the size of its image at 96 dpi. Transparent pixels are composited on white. It is what File and Image print; it also turns a rendered tango/ui frame (or any image.Image) into a PDF to print or save.
Types ¶
type Options ¶
type Options struct {
// Title names the print job; "" keeps the page title or app name.
Title string
// Copies is the initial number of copies; 0 keeps the system default.
Copies int
// Parent attaches the dialog of PDF, File and Image to this surface's
// window where the platform does; nil shows it on its own. Page always
// uses its own surface.
Parent *tango.Surface
// contains filtered or unexported fields
}
Options are the initial values of the print dialog; the user can change them there. Fields a platform cannot preset are ignored.