print

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 14 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

View Source
var (
	ErrUnsupported = platform.ErrUnsupported
	ErrCanceled    = platform.ErrCanceled
)

Functions

func File

func File(a *tango.App, path string, o Options) error

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 Image

func Image(a *tango.App, img image.Image, o Options) error

Image prints img on one page, scaled to fit the paper by the system.

func ImagePDF

func ImagePDF(imgs ...image.Image) ([]byte, error)

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.

func IsPDF

func IsPDF(data []byte) bool

IsPDF reports whether data starts with the PDF header "%PDF-".

func PDF

func PDF(a *tango.App, data []byte, o Options) error

PDF prints a PDF document given as its bytes.

func Page

func Page(s *tango.Surface, o Options) error

Page prints the page shown in WebView surface s. Canvas surfaces (and tango/ui windows) have no page: they get ErrUnsupported, see docs/print.md for how to print them.

func SavePDF

func SavePDF(s *tango.Surface, path string) error

SavePDF saves the page shown in WebView surface s as a PDF file at path, without a dialog. It is tango.Surface.PrintToPDF with default options plus writing the file; use PrintToPDF directly for paper size, orientation and backgrounds.

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.

Jump to

Keyboard shortcuts

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