print
import "github.com/tangoui/tango/sys/print"本页由
site/tools/apigen从源码注释生成(按 darwin 构建标签选文件),请勿手改。
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.
变量
var (
ErrUnsupported = platform.ErrUnsupported
ErrCanceled = platform.ErrCanceled
)函数
func File
func File(a *tango.App, path string, o Options) errorFile 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) errorImage 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) boolIsPDF reports whether data starts with the PDF header "%PDF-".
func PDF
func PDF(a *tango.App, data []byte, o Options) errorPDF prints a PDF document given as its bytes.
func Page
func Page(s *tango.Surface, o Options) errorPage 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) errorSavePDF 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.
类型
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.