printing

package
v0.76.3 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2024 License: MPL-2.0 Imports: 23 Imported by: 2

Documentation

Index

Constants

View Source
const (
	Portrait         = "portrait"
	Landscape        = "landscape"
	ReverseLandscape = "reverse-landscape"
	ReversePortrait  = "reverse-portrait"
)

Possible orientations

View Source
const (
	OneSided      = "one-sided"
	TwoSidedLong  = "two-sided-long-edge"
	TwoSidedShort = "two-sided-short-edge"
)

Possible sides

Variables

View Source
var Language = language.AmericanEnglish // TODO: Use the user's default

Language is the language that will be used when performing string manipulations for display.

Functions

func ExtractPageRanges

func ExtractPageRanges(text string) (ranges []goipp.Range, noErrors bool)

ExtractPageRanges extracts a set of ranges from the given string.

func FormatPageRanges

func FormatPageRanges(ranges []goipp.Range) string

FormatPageRanges returns a string representing the given ranges.

func OrientationPresentationName

func OrientationPresentationName(key string) string

OrientationPresentationName returns the presentation name (i.e. for humans to read) for the given orientation key.

func SidePresentationName

func SidePresentationName(key string) string

SidePresentationName returns the presentation name (i.e. for humans to read) for the given side key.

func ValidPageRanges

func ValidPageRanges(ranges []goipp.Range) bool

ValidPageRanges returns true if the page ranges are valid.

Types

type Attributes

type Attributes map[string]goipp.Values

Attributes provides the base support for printer attributes.

func NewAttributes

func NewAttributes(attrs goipp.Attributes) Attributes

NewAttributes creates a new set of printer attributes from a set of goipp.Attributes.

func (Attributes) Boolean

func (a Attributes) Boolean(key string, def bool) bool

Boolean returns the first boolean value for the given key.

func (Attributes) Booleans

func (a Attributes) Booleans(key string, def []bool) []bool

Booleans returns the boolean values for the given key.

func (Attributes) Collection

func (a Attributes) Collection(key string) Attributes

Collection returns the first collection value for the given key.

func (Attributes) Collections

func (a Attributes) Collections(key string) []Attributes

Collections returns the collection values for the given key.

func (Attributes) Copy

func (a Attributes) Copy() Attributes

Copy creates a new copy of these attributes.

func (Attributes) ForJob

func (a Attributes) ForJob() *JobAttributes

ForJob returns an Attributes that has extra methods for easily accessing the job-specific attributes.

func (Attributes) ForPrinter

func (a Attributes) ForPrinter() *PrinterAttributes

ForPrinter returns an Attributes that has extra methods for easily accessing the printer-specific attributes.

func (Attributes) Integer

func (a Attributes) Integer(key string, def int) int

Integer returns the first integer value for the given key.

func (Attributes) Integers

func (a Attributes) Integers(key string, def []int) []int

Integers returns the integer values for the given key.

func (Attributes) Range

func (a Attributes) Range(key string, def goipp.Range) goipp.Range

Range returns the first Range value for the given key.

func (Attributes) Ranges

func (a Attributes) Ranges(key string, def []goipp.Range) []goipp.Range

Ranges returns the Range values for the given key.

func (Attributes) Resolution

func (a Attributes) Resolution(key string, def goipp.Resolution) goipp.Resolution

Resolution returns the first resolution value for the given key.

func (Attributes) Resolutions

func (a Attributes) Resolutions(key string, def []goipp.Resolution) []goipp.Resolution

Resolutions returns the Resolution values for the given key.

func (Attributes) SetBoolean

func (a Attributes) SetBoolean(key string, value, replaceExisting bool)

SetBoolean sets the boolean value for the given key.

func (Attributes) SetCharset

func (a Attributes) SetCharset(key, value string, replaceExisting bool)

SetCharset sets the character set (string) value for the given key. If replaceExisting is true and the new value is empty, the key will be removed instead.

func (Attributes) SetEnum

func (a Attributes) SetEnum(key string, value int, replaceExisting bool)

SetEnum sets the enum (integer) value for the given key.

func (Attributes) SetInteger

func (a Attributes) SetInteger(key string, value int, replaceExisting bool)

SetInteger sets the integer value for the given key.

func (Attributes) SetKeyword

func (a Attributes) SetKeyword(key, value string, replaceExisting bool)

SetKeyword sets the keyword (string) value for the given key. If replaceExisting is true and the new value is empty, the key will be removed instead.

func (Attributes) SetLanguage

func (a Attributes) SetLanguage(key, value string, replaceExisting bool)

SetLanguage sets the language (string) value for the given key. If replaceExisting is true and the new value is empty, the key will be removed instead.

func (Attributes) SetMemberName

func (a Attributes) SetMemberName(key, value string, replaceExisting bool)

SetMemberName sets the member name (string) value for the given key. If replaceExisting is true and the new value is empty, the key will be removed instead.

func (Attributes) SetMimeType

func (a Attributes) SetMimeType(key, value string, replaceExisting bool)

SetMimeType sets the MIME type (string) value for the given key. If replaceExisting is true and the new value is empty, the key will be removed instead.

func (Attributes) SetNameWithLang

func (a Attributes) SetNameWithLang(key string, value goipp.TextWithLang, replaceExisting bool)

SetNameWithLang sets the name with language (TextWithLang) value for the given key.

func (Attributes) SetRange

func (a Attributes) SetRange(key string, value goipp.Range, replaceExisting bool)

SetRange sets the range value for the given key.

func (Attributes) SetReservedString

func (a Attributes) SetReservedString(key, value string, replaceExisting bool)

SetReservedString sets the reserved string (string) value for the given key. If replaceExisting is true and the new value is empty, the key will be removed instead.

func (Attributes) SetResolution

func (a Attributes) SetResolution(key string, value goipp.Resolution, replaceExisting bool)

SetResolution sets the resolution value for the given key.

func (Attributes) SetString

func (a Attributes) SetString(key, value string, replaceExisting bool)

SetString sets the string value for the given key. If replaceExisting is true and the new value is empty, the key will be removed instead.

func (Attributes) SetText

func (a Attributes) SetText(key, value string, replaceExisting bool)

SetText sets the text (string) value for the given key. If replaceExisting is true and the new value is empty, the key will be removed instead.

func (Attributes) SetTextWithLang

func (a Attributes) SetTextWithLang(key string, value goipp.TextWithLang, replaceExisting bool)

SetTextWithLang sets the text with language value for the given key.

func (Attributes) SetTime

func (a Attributes) SetTime(key string, value time.Time, replaceExisting bool)

SetTime sets the time/date value for the given key.

func (Attributes) SetURI

func (a Attributes) SetURI(key, value string, replaceExisting bool)

SetURI sets the URI (string) value for the given key. If replaceExisting is true and the new value is empty, the key will be removed instead.

func (Attributes) SetURIScheme

func (a Attributes) SetURIScheme(key, value string, replaceExisting bool)

SetURIScheme sets the URI scheme (string) value for the given key. If replaceExisting is true and the new value is empty, the key will be removed instead.

func (Attributes) String

func (a Attributes) String(key, def string) string

String returns the first string value for the given key.

func (Attributes) Strings

func (a Attributes) Strings(key string, def []string) []string

Strings returns the string values for the given key.

func (Attributes) TextWithLang

func (a Attributes) TextWithLang(key string, def goipp.TextWithLang) goipp.TextWithLang

TextWithLang returns the first TextWithLang value for the given key.

func (Attributes) TextWithLangs

func (a Attributes) TextWithLangs(key string, def []goipp.TextWithLang) []goipp.TextWithLang

TextWithLangs returns the TextWithLang values for the given key.

func (Attributes) Time

func (a Attributes) Time(key string, def time.Time) time.Time

Time returns the first time value for the given key.

func (Attributes) Times

func (a Attributes) Times(key string, def []time.Time) []time.Time

Times returns the time values for the given key.

type JobAttributes

type JobAttributes struct {
	Attributes
}

JobAttributes holds attributes specific to a printer job.

func (*JobAttributes) ColorMode

func (a *JobAttributes) ColorMode() string

ColorMode returns the color mode.

func (*JobAttributes) ContentOptimization

func (a *JobAttributes) ContentOptimization() string

ContentOptimization returns the content optimization.

func (*JobAttributes) Copies

func (a *JobAttributes) Copies() int

Copies returns the number of copies to make.

func (*JobAttributes) Media

func (a *JobAttributes) Media() string

Media returns the media (page size).

func (*JobAttributes) MediaSource

func (a *JobAttributes) MediaSource() string

MediaSource returns the media source.

func (*JobAttributes) Orientation

func (a *JobAttributes) Orientation() string

Orientation returns the page orientation.

func (*JobAttributes) PageRanges

func (a *JobAttributes) PageRanges() []goipp.Range

PageRanges returns the page ranges.

func (*JobAttributes) PrintScaling

func (a *JobAttributes) PrintScaling() string

PrintScaling returns the print scaling.

func (*JobAttributes) SetColorMode

func (a *JobAttributes) SetColorMode(mode string)

SetColorMode sets the color mode.

func (*JobAttributes) SetContentOptimization

func (a *JobAttributes) SetContentOptimization(optimization string)

SetContentOptimization sets the content optimization.

func (*JobAttributes) SetCopies

func (a *JobAttributes) SetCopies(count int)

SetCopies sets the number of copies to make.

func (*JobAttributes) SetMedia

func (a *JobAttributes) SetMedia(media string)

SetMedia sets the media.

func (*JobAttributes) SetMediaSource

func (a *JobAttributes) SetMediaSource(src string)

SetMediaSource sets the media source.

func (*JobAttributes) SetOrientation

func (a *JobAttributes) SetOrientation(orientation string)

SetOrientation sets the page orientation.

func (*JobAttributes) SetPageRanges

func (a *JobAttributes) SetPageRanges(ranges []goipp.Range)

SetPageRanges sets the page ranges. Pass in nil to remove the page range restriction.

func (*JobAttributes) SetPrintScaling

func (a *JobAttributes) SetPrintScaling(scaling string)

SetPrintScaling sets the print scaling.

func (*JobAttributes) SetSides

func (a *JobAttributes) SetSides(sides string)

SetSides sets the sides.

func (*JobAttributes) Sides

func (a *JobAttributes) Sides() string

Sides returns the sides.

type JobDialog

type JobDialog struct {
	// contains filtered or unexported fields
}

JobDialog provides a print job dialog.

func (*JobDialog) JobAttributes

func (d *JobDialog) JobAttributes() *JobAttributes

JobAttributes returns the job attributes that were configured.

func (*JobDialog) Printer

func (d *JobDialog) Printer() *Printer

Printer returns the printer that the dialog was configured for.

func (*JobDialog) RunModal

func (d *JobDialog) RunModal() bool

RunModal presents the dialog and returns true if the user pressed OK.

type PrintManager

type PrintManager struct {
	// contains filtered or unexported fields
}

PrintManager holds the data needed by the print manager.

func (*PrintManager) LookupPrinter

func (p *PrintManager) LookupPrinter(id PrinterID) *Printer

LookupPrinter returns a printer by ID, or nil if it is not in our currently discovered set.

func (*PrintManager) NewJobDialog

func (p *PrintManager) NewJobDialog(id PrinterID, mimeType string, attributes *JobAttributes) *JobDialog

NewJobDialog creates a dialog to configure a print job. 'printerID' may be empty or an ID for a printer that is no longer available.

func (*PrintManager) Printers

func (p *PrintManager) Printers() []*Printer

Printers returns the previously discovered available printers, sorted by name.

func (*PrintManager) ScanForPrinters

func (p *PrintManager) ScanForPrinters(ctx context.Context, printers chan<- *Printer)

ScanForPrinters first clears the previously known set of printers, then creates a goroutine to scan for printers, adding them to the set of known printers. You may pass nil for the out parameter if you do not need to receive the printers as they are discovered. If out is not nil, it will be closed when the scan completes.

type Printer

type Printer struct {
	RemotePath       string
	AuthInfoRequired string
	User             string
	Password         string
	MimeTypes        []string
	PrinterID

	Color  bool
	Duplex bool
	UseTLS bool
	// contains filtered or unexported fields
}

Printer holds the information for a printer. Note that the User, Password, and UseTLS fields must be filled in if you wish to use those features, as the call to PrintManager.Printers() will not fill them in for you.

func (*Printer) Attributes

func (p *Printer) Attributes(timeout time.Duration, allowCachedReturn bool) (*PrinterAttributes, error)

Attributes returns the printer's attributes. If allowCachedReturn is true and a previous call to Attributes() was made successfully, the previous data will be returned instead of communicating with the printer again.

func (*Printer) MimeTypeSupported

func (p *Printer) MimeTypeSupported(mimeType string) bool

MimeTypeSupported returns true if the given MIME type is supported by the printer.

func (*Printer) Print

func (p *Printer) Print(ctx context.Context, jobName, mimeType string, fileData io.Reader, fileLength int, attributes *JobAttributes) error

Print a document.

func (*Printer) Validate

func (p *Printer) Validate(ctx context.Context, jobName, mimeType string, attributes *JobAttributes) (*JobAttributes, error)

Validate the job attributes. Any attributes that have been either ignored or altered by the printer will be returned.

type PrinterAttributes

type PrinterAttributes struct {
	Attributes
}

PrinterAttributes holds attributes specific to a printer.

func (*PrinterAttributes) DefaultColorMode

func (a *PrinterAttributes) DefaultColorMode() string

DefaultColorMode returns the default color mode.

func (*PrinterAttributes) DefaultContentOptimization

func (a *PrinterAttributes) DefaultContentOptimization() string

DefaultContentOptimization returns the default content optimization to perform.

func (*PrinterAttributes) DefaultMedia

func (a *PrinterAttributes) DefaultMedia() string

DefaultMedia returns the default media (page size) that will be used.

func (*PrinterAttributes) DefaultMediaSource

func (a *PrinterAttributes) DefaultMediaSource() string

DefaultMediaSource returns the default media source.

func (*PrinterAttributes) DefaultOrientation

func (a *PrinterAttributes) DefaultOrientation() string

DefaultOrientation returns the default page orientation.

func (*PrinterAttributes) DefaultPDFFitToPage

func (a *PrinterAttributes) DefaultPDFFitToPage() bool

DefaultPDFFitToPage returns the default PDF fit-to-page value that will be used.

func (*PrinterAttributes) DefaultPrintScaling

func (a *PrinterAttributes) DefaultPrintScaling() string

DefaultPrintScaling returns the default print scaling that will be used.

func (*PrinterAttributes) DefaultSides

func (a *PrinterAttributes) DefaultSides() string

DefaultSides returns the default sides to print on.

func (*PrinterAttributes) Icons

func (a *PrinterAttributes) Icons() []string

Icons returns a list of icon URLs that can be used to represent this printer.

func (*PrinterAttributes) MaxCopies

func (a *PrinterAttributes) MaxCopies() int

MaxCopies returns the maximum number of copies that are supported.

func (*PrinterAttributes) MinimumMargins

func (a *PrinterAttributes) MinimumMargins() geom.Insets[int]

MinimumMargins returns the minimum margins for a page, given in hundreths of millimeters (the equivalent of 1/2540's of an inch).

func (*PrinterAttributes) PageRangesSupported

func (a *PrinterAttributes) PageRangesSupported() bool

PageRangesSupported returns true if page ranges are supported.

func (*PrinterAttributes) SupportedColorModes

func (a *PrinterAttributes) SupportedColorModes() []string

SupportedColorModes returns the supported color modes.

func (*PrinterAttributes) SupportedContentOptimizations

func (a *PrinterAttributes) SupportedContentOptimizations() []string

SupportedContentOptimizations returns the supported content optimizations.

func (*PrinterAttributes) SupportedDocumentTypes

func (a *PrinterAttributes) SupportedDocumentTypes() []string

SupportedDocumentTypes returns the supported document MIME types.

func (*PrinterAttributes) SupportedJobCreationAttributes

func (a *PrinterAttributes) SupportedJobCreationAttributes() []string

SupportedJobCreationAttributes returns the set of attributes that are supported when creating a new job.

func (*PrinterAttributes) SupportedMedia

func (a *PrinterAttributes) SupportedMedia() []string

SupportedMedia returns the supported media (page sizes) that may be used.

func (*PrinterAttributes) SupportedMediaSources

func (a *PrinterAttributes) SupportedMediaSources() []string

SupportedMediaSources returns the supported media sources.

func (*PrinterAttributes) SupportedOrientations

func (a *PrinterAttributes) SupportedOrientations() []string

SupportedOrientations returns the supported page orientations.

func (*PrinterAttributes) SupportedPDFFitToPage

func (a *PrinterAttributes) SupportedPDFFitToPage() []bool

SupportedPDFFitToPage returns the supported PDF fit-to-page values that may be used.

func (*PrinterAttributes) SupportedPrintScaling

func (a *PrinterAttributes) SupportedPrintScaling() []string

SupportedPrintScaling returns the supported print scaling that may be used.

func (*PrinterAttributes) SupportedSides

func (a *PrinterAttributes) SupportedSides() []string

SupportedSides returns the supported sides that may be printed on.

type PrinterID

type PrinterID struct {
	ID   string `json:"id"`
	Name string `json:"name"`
	Host string `json:"host"`
	Port int    `json:"port"`
}

PrinterID identifies a specific printer.

func (*PrinterID) String

func (p *PrinterID) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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