Documentation
¶
Overview ¶
Package raw sends documents to printers that do not speak IPP: over the raw socket of port 9100 (AppSocket, JetDirect), the line printer daemon protocol (LPD, RFC 1179), a serial port (and a Bluetooth printer of the serial port profile, which the OS shows as one), the device file of a USB printer (Linux and the BSDs), and a queue of Windows whose driver passes RAW data on (winspool). The document is a file of the printer's language, which package print makes: PostScript or PDF, or the language of a printer of labels, receipts or forms (ZPL, SBPL, TPCL, ESC/POS, ESC/P; package print/pdl). The printer is told nothing else of the job but what the file says and an optional PJL header (the copies, sides and paper of PostScript are in the file, those of PDF in PJL).
None of them tells the state of a job: Send ends when the printer has the whole document. None has a way to ask the printer what it supports, so the format sent is told by the URL, as in socket://host:9100?format=pdf or serial:///dev/ttyUSB0?lang=escpos.
A job that was sent in part may have been printed in part: from the first byte of a 9100 job, and from the control file of an LPD job (an LPD printer prints a job once it has its control file, which is sent after the data). Send calls Begin then, and an error after it is ErrPartial, which a spool does not send again on its own.
Index ¶
Constants ¶
const ( FormatPostScript = "ps" FormatPDF = "pdf" )
Formats of a raw printer: what package print writes for it.
Variables ¶
var ( // ErrPartial wraps an error after the printer may have begun to print // the job: it is not known whether, or how much of it, it printed. ErrPartial = errors.New("raw: the printer may have printed a part of the job") // ErrRefused is returned when an LPD printer refuses the job (or its // queue). ErrRefused = errors.New("raw: the printer refused the job") )
Errors of Send.
var ErrNotHere = errors.New("raw: the printer is not reached that way on this system")
ErrNotHere is returned for a device that this OS does not reach that way (a USB device file on Windows, a queue of Windows elsewhere).
Functions ¶
func IsLanguage ¶
IsLanguage reports whether a format is the language of a printer of labels, receipts or forms.
Types ¶
type Job ¶
type Job struct {
// Name is the job's name (PJL and LPD), and User its user (LPD).
Name string
// Format is the document's: FormatPostScript, FormatPDF or a
// language of print/pdl.
Format string
// Data is the document.
Data []byte
// PJL are the lines of the PJL header that set the job (@PJL SET
// DUPLEX=ON …), without the lines that begin and end it, which Send
// writes when the printer uses PJL for the format.
PJL []string
// Begin is called before what the printer may print of the job is
// sent; an error stops the job there.
Begin func() error
}
Job is a document to send.
type Printer ¶
type Printer struct {
// URL is the printer's URL, without its query.
URL string
// Scheme is "socket", "lpd", "serial", "usb" or "winspool".
Scheme string
// Addr is the host and port.
Addr string
// Queue is the queue of an LPD printer.
Queue string
// Device is the serial port or device file, or the name of the
// queue of Windows.
Device string
// Serial is the setting of a serial port.
Serial Serial
// Format is the format the printer takes: FormatPostScript (the
// default), FormatPDF, or a language of print/pdl; "" for the
// language of the Profile, which the URL names without one.
Format string
// Profile, DPI and Width describe a printer of a language of
// print/pdl: a profile's name, and its dots and width as the URL
// overrides them ("" for the profile's).
Profile, DPI, Width string
// PJL wraps the document in a PJL header: "true", "false", or "" for
// PDF only (which many printers do not tell from other files without
// it).
PJL string
// User is the user an LPD job is of ("bdf" when "").
User string
// Timeout bounds the connection and each write and read: 30 seconds
// when 0.
Timeout time.Duration
}
Printer is a printer reached over 9100, LPD, a serial port, a USB device file or a queue of Windows, as its URL says:
socket://host[:9100][?format=…][&pjl=true|false] lpd://host[:515]/queue[?format=…][&pjl=true|false][&user=name] serial:///dev/ttyUSB0?format=…[&baud=9600][&bits=8][&parity=none][&stop=1][&flow=none] serial://COM3?format=… (Windows) usb:///dev/usb/lp0?format=… (Linux, the BSDs) winspool:///Printer%20Name?format=… (Windows)
The format is ps (the default) or pdf, or a language of print/pdl (zpl, sbpl, tpcl, escpos, escp; lang is the same parameter), which takes a profile, dpi and width too.
func (*Printer) Check ¶
Check tells whether the printer takes connections: it connects and closes the connection, sending nothing.
type Serial ¶
type Serial struct {
Baud int
// Bits are the data bits: 7 or 8.
Bits int
// Parity is "none", "even" or "odd".
Parity string
// Stop are the stop bits: 1 or 2.
Stop int
// Flow is "none", "rtscts" (hardware) or "xonxoff" (software).
Flow string
}
Serial is the setting of a serial port: 9600 bauds, 8 bits, no parity, 1 stop bit and no flow control unless the URL says otherwise.