Printing
Computer Center, CS, NCTU Basic terms (1) q Spooler • Printer server • Receive, store, prioritize print jobs • Send print jobs sequentially(FIFO) to printer q dpi • Dots Per Inch • Such as 300 x 600 dpi q Bitmap • Set of data that specify how dots are filled • Compression: JPEG, PNG, TIFF, … q Filters • Programs that modify print jobs between spooler and printer 2
Computer Center, CS, NCTU Basic terms (2) q PDL • Page Description Language • Describe where and how the image is placed on the page • PDLs: Post. Script and Printer Command Language (PCL) q Post. Script • PDL developed by Adobe • %!PS starting q PCL • HP’s alternative to Post. Script q RIP • Raster Image Processor • PDLs-to-bitmap conversion 3
Computer Center, CS, NCTU 4 Types of Printer q Serial and Parallel Printer • Parallel printer is simple and faster than serial printer q USB Printer q Network printer • Printer with NIC • Two kinds of network printer Ø Printer that can do jobs queuing and scheduling Ø Printer that does not know above, the NIC is nothing more than a channel to transfer printing data, just like serial or parallel port
Computer Center, CS, NCTU BSD Printing System Architecture Free. BSD Users lpr (1) lpq (1) lprm (1) Admin Printcap lp|Local Printer: … np|Network Printer: … op|Other Printer: … LPD ap|Another Printer: … Network Printer (ex: hp 4350) Spool directory lpc (8) Network Printer Server LPD 5 Local Printer Printcap op|Other Printer: … ap|Another Printer: … Other Printer Another Printer
Computer Center, CS, NCTU 6 BSD Printing System (1) q Printer server • lpd Ø Responsible for accepting jobs, processing them and sending them to an actual printer Ø Read printer settings from /etc/printcap • Enable lpd in Free. BSD Ø Edit rc. conf – lpd_enable=“YES” – lpd_flags=“-l” (log print request)
Computer Center, CS, NCTU 7 BSD Printing System (2) q When we want to print … • Using lpr command Ø Ex: lpr –Php 4350 myfile. txt • Printer selection 1. If there is –P option, use that printer 2. If there is “PRINTER” variable, use that printer 3. Use the default printer(lp) defined in /etc/printcap 4. If there is no default printer, use the first entry defined in /etc/printcap
Computer Center, CS, NCTU BSD Printing System (3) q When lpd receives the jobs … • Put the job in spool directory Ø cf file (control file) – Information about the jobs – Ex: cf. A 023 ntserv Ø df file (data file) cf file H 140. 113. 235. 1 Pchwong JEdit 2* ldf. A 023140. 113. 235. 1 Udf. A 023140. 113. 235. 1 NEdit 2* – Actual data that is going to be printed – Ex: df. A 023 ntserv • Send the first queued job to printer Ø lpd creates a series of UNIX pipes between spool and printer to let system invokes filter to modify the job or something else Ø Local or remote printer cf meanings: lpd(8) 8
Computer Center, CS, NCTU BSD Printing System (4) q What client can do ? • lpr • lpq • lprm to send the job to list the queued jobs to remove the job q What administrator can do ? • lpq, lprm • lpc to change the printing environment lpr(1), lpq(1), lprm(1), lpc(8) 9
Computer Center, CS, NCTU BSD Printing System lpr command q lpr: submit the jobs • % lpr –Pprinter-name file Ø Ex: % lpr –Php 4350 hwk 2. txt • % lpr –Pprinter-name -#N file Ø Produce N copies of file Ø Ex: % lpr –Php 4350 -#3 hwk 2. txt Ø Ex: % lpr –Php 4350 -#3 hwk 2. c hwk 2. h Makefile Ø Ex: % cat hwk 2. c hwk 2. h Makefile | lpr –Php 4350 -#3 10
Computer Center, CS, NCTU 11 BSD Printing System lpq command q lpq: view the printing queue • % lpq –Pprinter-name • % lpq –a Ø If the first record is not “active” , no printing daemon is running on the printer – Using lpc start hp 4050 sabsd [/etc] -chwong. Rank Owner Job active chwong 1 1 st chwong 2 2 nd chwong 3 lpq -Php 4050 Files /etc/printcap /etc/hosts /etc/group Total Size 324 bytes 131 bytes 423 bytes
Computer Center, CS, NCTU BSD Printing System lprm command q lprm: remove print jobs • % lprm –Pprinter-name jobid Ø Remove single printing job with certain id Ø Ex: % lprm –Php 4350 121 • % lprm –Pprinter-name user Ø Remove all jobs owned by user Ø Ex: % lprm –Php 4350 chwong • % lprm –Pprinter-name Ø Remove the active job if the job is owned by user • % lprm –Pprinter-name – Ø Remove jobs you submitted Ø Remove all jobs when root execute it 12
Computer Center, CS, NCTU Print a job Printcap lp|Local Printer: … np|Network Printer: … op|Other Printer: … ap|Another Printer: … Users lpr (1) lpq (1) lprm (1) Admin lpc (8) Spool directory LPD Local Printer Network Printer (ex: hp 4350) lp spool queue np spool queue 1. Spooling files to queue Printing Job (cf/df files) 2. Filter files Filters op spool queue ap spool queue 13 3. Print to printer
Computer Center, CS, NCTU 14 BSD Printing System lpc command (1) q lpc: make administrative changes sabsd [/etc] -chwong- lpc> ? Commands may be abbreviated. abort bottomq clean enable lpc> exit disable down help Commands are: quit restart status setstatus stop tclean topq up ? xtopq
Computer Center, CS, NCTU BSD Printing System lpc command (2) q lpc commands • help [command] Ø One-line description of that command • enable/disable {all | printer} Ø Start or stop spooling on the queue • start/stop {all | printer} Ø Start of stop printing, the active job will be finished • abort {all | printer} Ø Stop printing, the active job will be suspended until start printing again • up/down {all | printer} Ø Start or stop “spooling and printing” at the same time • clean {all | printer} Ø Remove all jobs, including active jobs, but it will be finished 15
Computer Center, CS, NCTU 16 BSD Printing System lpc command (3) • topq/bottomq printer [jobid|username] Ø Move the jobs to top/bottom of queue • restart {all | printer} Ø Restart the printer; restart will fail if the printer still has a filter running • status {all | printer} Ø Whether spooling Ø Whether printing Ø Number of jobs in queue Ø Printer status lpc> status hp 4050: queuing is enabled printing is disabled 2 entries in spool area printer idle lpc>
Computer Center, CS, NCTU /etc/printcap file q How, where to process printing jobs • Configuration format Ø Separated by “: ” Ø Three option format – xx=string – xx#number (enable/disable option) (string type option) (numeric type option) hp 6 mp|HP Laser. Jet 6 MP: : sh: : rw: : mx#0: : sd=/var/spool/lpd/hp 6 mp: : lp=/dev/lpt 0: : if=/usr/libexec/lpr/lpf: : lf=/var/spool/lpd/hp 6 mp/log: 17 Printer name Configuration options
Computer Center, CS, NCTU /etc/printcap file printer name q Multiple names separated by “|” • The record has “lp” will be the default printer hp 6 mp|HP Laser. Jet 6 MP: : sh: : rw: : mx#0: : sd=/var/spool/lpd/hp 6 mp: : lp=/dev/lpt 0: : if=/usr/libexec/lpr/lpf: : lf=/var/spool/lpd/hp 6 mp/log: hp 4050|lp|HP Laser. Jet 4100: : sh: : rw: : mx#0: : sd=/var/spool/lpd/hp 4050: : lp=/dev/null: : rm=hp 4050: : if=/usr/libexec/lpr/lpf: : lf=/var/spool/lpd/hp 4050/log: 18
Computer Center, CS, NCTU /etc/printcap file configuration options (1) q sd: spool directory • Where to put the print jobs before sending to printer • Ideal path: under /var/spool/lpd/ • Permission with 755 and owner, group owner with “daemon” Ø Ex: sd=/var/spool/lpd/hp 4050 q lf: error log file • Where to put the error message • Ideal path: under spool directory with name “log” Ø Ex: lf=/var/spool/lpd/hp 4050/log • lpd mind sends error messages to syslog, check both q mx: file size limit • Size of data that can be spooled at one time in block • Ex: mx#5000 (limit of 5000*1024 bytes) • Ex: mx#0 (no limit) 19
Computer Center, CS, NCTU /etc/printcap file configuration options (2) q lp: device name • Local: the device file under /dev • Remote: /dev/null Ø Ex: lp=/dev/lpt 0 Ø Ex: lp=/dev/null q rm: remote machine • Which host to send the print job if this printer is a remote one Ø Ex: rm=csduty q rp: remote printer • Which printer to send if this remote host has several printer Ø Ex: rm=csduty Ø Ex: rp=hp 4050 20
Computer Center, CS, NCTU /etc/printcap file configuration options (3) q if, of: printing filters • shell scripts mostly • Three basic jobs Ø Accept printing job from standard in Ø Transform data Ø Send the result to standard output • Another usage of filters Ø Accounting Ø Access control to “user” level Ø Auditing q af: accounting file • Tell filters where to append the auditing records 21
Computer Center, CS, NCTU Restricting Printer Usage q Multiple Copies • To disable: sc option q Group access • rg option q Control size of jobs • mx option q Remote access • /etc/hosts. lpd hp 4050|lp|HP Laser. Jet 4100: : sh: : rw: : mx#0: : sd=/var/spool/lpd/hp 4050: : sc: : rg=cs: : mx#5000: : lp=/dev/null: : rm=hp 4050: : if=/usr/libexec/lpr/lpf: : lf=/var/spool/lpd/hp 4050/log: Ø Hosts in file are allowed to access the printer 22
Computer Center, CS, NCTU filters q Three kinds • Text filters (input filter) Ø Handle regular text printing Ø /usr/libexec/lpr/lpf • Conversion filter Ø Convert a specific file format into another • Output filter Ø Used if there is no text filter q Return value • exit 0 Ø successfully • exit 1 Ø Failed to print, but want LPD to print the file again • exit 2 Ø Failed to print, and does not want to print the file anymore 23
Computer Center, CS, NCTU filters plaintext on Post. Script Printers (1) q. Post. Script printing jobs • Start with %!PS • If this job start with “%!PS”, Ø let it goes to printer directory • Else Ø convert the text into Postscript and print the result q. Using text filter “lprps” • /usr/ports/print/lprps-a 4 24
Computer Center, CS, NCTU 25 filters plaintext on Post. Script Printers (2) sabsd [/etc] -chwong- cat /usr/share/examples/printing/psif #!/bin/sh # # psif - Print Post. Script or plain text on a Post. Script printer # Script version; NOT the version that comes with lprps # Installed in /usr/local/libexec/psif # read first_line first_two_chars=`expr "$first_line" : '(. . )'` if [ "$first_two_chars" = "%!" ]; then # # Post. Script job, print it. # echo "$first_line" && cat && printf "