Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Automatic Printing System with Open Source Tools

Mosky Liu
August 03, 2013

Automatic Printing System with Open Source Tools

It is the slides for COSCUP[1] 2013 talk, "Automatic Printing System with Open Source Tools".

It explains how to setup automatic printing system on Linux and includes some tips for it.

[1] COSCUP: http://coscup.org/

Mosky Liu

August 03, 2013
Tweet

More Decks by Mosky Liu

Other Decks in Programming

Transcript

  1. Mosky ✤ I am working at www.pinkoi.com . ✤ I've

    been using Ubuntu everyday since 2009. 3
  2. Mosky ✤ I am working at www.pinkoi.com . ✤ I've

    been using Ubuntu everyday since 2009. ✤ A speaker at PyCon TW 2013, 2012, PyCon JP 2012, ... 3
  3. Mosky ✤ I am working at www.pinkoi.com . ✤ I've

    been using Ubuntu everyday since 2009. ✤ A speaker at PyCon TW 2013, 2012, PyCon JP 2012, ... ✤ http://mosky.tw/ 3
  4. It's just out of control! We have to issue more

    than 1,000 invoices per month. 6
  5. It's just out of control! We have to issue more

    than 1,000 invoices per month. 6
  6. We love hand-made stuff. Pinkoi is the largest online community

    and marketplace for designers in Asia 7
  7. We love hand-made stuff. Pinkoi is the largest online community

    and marketplace for designers in Asia 7
  8. The Check List ✤ A computer installed Linux and CUPS

    (Common Unix Printing System). 10
  9. The Check List ✤ A computer installed Linux and CUPS

    (Common Unix Printing System). ✤ http://www.cups.org/ 10
  10. The Check List ✤ A computer installed Linux and CUPS

    (Common Unix Printing System). ✤ http://www.cups.org/ ✤ http://localhost:631/ 10
  11. The Check List ✤ A computer installed Linux and CUPS

    (Common Unix Printing System). ✤ http://www.cups.org/ ✤ http://localhost:631/ ✤ A printer which has an IP address. 10
  12. The Check List ✤ A computer installed Linux and CUPS

    (Common Unix Printing System). ✤ http://www.cups.org/ ✤ http://localhost:631/ ✤ A printer which has an IP address. ✤ http://192.168.2.100/ 10
  13. The Check List ✤ A computer installed Linux and CUPS

    (Common Unix Printing System). ✤ http://www.cups.org/ ✤ http://localhost:631/ ✤ A printer which has an IP address. ✤ http://192.168.2.100/ ✤ lpd://192.168.2.100/ 10
  14. Setup Printer with CUPS' Driver ✤ Find the driver for

    your printer: ✤ $ lpinfo --make-and-model 'P1006' -m 11
  15. Setup Printer with CUPS' Driver ✤ Find the driver for

    your printer: ✤ $ lpinfo --make-and-model 'P1006' -m ✤ drv:///hpijs.drv/hp-laserjet_p1006-hpijs.ppd HP LaserJet p1006 hpijs, 3.10.2, requires proprietary plugin 11
  16. Setup Printer with CUPS' Driver ✤ Find the driver for

    your printer: ✤ $ lpinfo --make-and-model 'P1006' -m ✤ drv:///hpijs.drv/hp-laserjet_p1006-hpijs.ppd HP LaserJet p1006 hpijs, 3.10.2, requires proprietary plugin ✤ Add the printer with the driver we found from the above command: 11
  17. Setup Printer with CUPS' Driver ✤ Find the driver for

    your printer: ✤ $ lpinfo --make-and-model 'P1006' -m ✤ drv:///hpijs.drv/hp-laserjet_p1006-hpijs.ppd HP LaserJet p1006 hpijs, 3.10.2, requires proprietary plugin ✤ Add the printer with the driver we found from the above command: ✤ $ lpadmin -E -p <NAME> -v socket://<IP> -m <DRIVER> -E 11
  18. Setup Printer with CUPS' Driver ✤ Find the driver for

    your printer: ✤ $ lpinfo --make-and-model 'P1006' -m ✤ drv:///hpijs.drv/hp-laserjet_p1006-hpijs.ppd HP LaserJet p1006 hpijs, 3.10.2, requires proprietary plugin ✤ Add the printer with the driver we found from the above command: ✤ $ lpadmin -E -p <NAME> -v socket://<IP> -m <DRIVER> -E ✤ $ lpadmin -E -p 'hp-p1006' -v socket://192.168.2.100 -m drv:///hpijs.drv/hp-laserjet_p1006-hpijs.ppd -E 11
  19. Setup Printer with PPD ✤ Find the PPD file for

    your printer: ✤ http://www.openprinting.org/drivers 12
  20. Setup Printer with PPD ✤ Find the PPD file for

    your printer: ✤ http://www.openprinting.org/drivers ✤ Put the PPD file in: 12
  21. Setup Printer with PPD ✤ Find the PPD file for

    your printer: ✤ http://www.openprinting.org/drivers ✤ Put the PPD file in: ✤ /usr/share/cups/model 12
  22. Setup Printer with PPD ✤ Find the PPD file for

    your printer: ✤ http://www.openprinting.org/drivers ✤ Put the PPD file in: ✤ /usr/share/cups/model ✤ Add the printer with this PPD file: 12
  23. Setup Printer with PPD ✤ Find the PPD file for

    your printer: ✤ http://www.openprinting.org/drivers ✤ Put the PPD file in: ✤ /usr/share/cups/model ✤ Add the printer with this PPD file: ✤ $ lpadmin -E -p <NAME> -v lpd://<IP>/lp -m <DRIVER> -E 12
  24. Setup Printer with PPD ✤ Find the PPD file for

    your printer: ✤ http://www.openprinting.org/drivers ✤ Put the PPD file in: ✤ /usr/share/cups/model ✤ Add the printer with this PPD file: ✤ $ lpadmin -E -p <NAME> -v lpd://<IP>/lp -m <DRIVER> -E ✤ $ lpadmin -E -p 'hp-p1006' -v lpd://192.168.2.100/lp -m 12
  25. More about lpadmin ✤ Enable a printer: ✤ $ lpadmin

    -p <NAME> -E ✤ Set a printer as default: 13
  26. More about lpadmin ✤ Enable a printer: ✤ $ lpadmin

    -p <NAME> -E ✤ Set a printer as default: ✤ $ lpadmin -d <NAME> 13
  27. More about lpadmin ✤ Enable a printer: ✤ $ lpadmin

    -p <NAME> -E ✤ Set a printer as default: ✤ $ lpadmin -d <NAME> ✤ Remove a printer: 13
  28. More about lpadmin ✤ Enable a printer: ✤ $ lpadmin

    -p <NAME> -E ✤ Set a printer as default: ✤ $ lpadmin -d <NAME> ✤ Remove a printer: ✤ $ lpadmin -x <NAME> 13
  29. Check Printer is Online ✤ Just print a test file:

    ✤ $ lpr -P <NAME> <FILE> ✤ Check the status of printer: 14
  30. Check Printer is Online ✤ Just print a test file:

    ✤ $ lpr -P <NAME> <FILE> ✤ Check the status of printer: ✤ $ lpstat -a / $ lpstat -t 14
  31. Check Printer is Online ✤ Just print a test file:

    ✤ $ lpr -P <NAME> <FILE> ✤ Check the status of printer: ✤ $ lpstat -a / $ lpstat -t ✤ Troubleshooting: 14
  32. Check Printer is Online ✤ Just print a test file:

    ✤ $ lpr -P <NAME> <FILE> ✤ Check the status of printer: ✤ $ lpstat -a / $ lpstat -t ✤ Troubleshooting: ✤ $ nc -v <IP> <PORT> 14
  33. Check Printer is Online ✤ Just print a test file:

    ✤ $ lpr -P <NAME> <FILE> ✤ Check the status of printer: ✤ $ lpstat -a / $ lpstat -t ✤ Troubleshooting: ✤ $ nc -v <IP> <PORT> ✤ $ nmap <IP> -p <PORT_RANGE> 14
  34. The Packages ✤ Use wkhtmltopdf to convert Web to PDF.

    ✤ $ sudo apt-get install wkhtmltopdf 16
  35. The Packages ✤ Use wkhtmltopdf to convert Web to PDF.

    ✤ $ sudo apt-get install wkhtmltopdf ✤ https://code.google.com/p/wkhtmltopdf/ 16
  36. The Packages ✤ Use wkhtmltopdf to convert Web to PDF.

    ✤ $ sudo apt-get install wkhtmltopdf ✤ https://code.google.com/p/wkhtmltopdf/ ✤ If you don't have X Window, you also need xvfb. 16
  37. The Packages ✤ Use wkhtmltopdf to convert Web to PDF.

    ✤ $ sudo apt-get install wkhtmltopdf ✤ https://code.google.com/p/wkhtmltopdf/ ✤ If you don't have X Window, you also need xvfb. ✤ $ sudo apt-get install xvfb 16
  38. The Usage ✤ with X Window: ✤ $ wkhtmltopdf <HTML>

    <PDF> ✤ $ wkhtmltopdf -T 0 -L 0 -R 0 -B 0 --page-size A4 -- encoding utf-8 <HTML> <PDF> 17
  39. The Usage ✤ with X Window: ✤ $ wkhtmltopdf <HTML>

    <PDF> ✤ $ wkhtmltopdf -T 0 -L 0 -R 0 -B 0 --page-size A4 -- encoding utf-8 <HTML> <PDF> ✤ without X window: 17
  40. The Usage ✤ with X Window: ✤ $ wkhtmltopdf <HTML>

    <PDF> ✤ $ wkhtmltopdf -T 0 -L 0 -R 0 -B 0 --page-size A4 -- encoding utf-8 <HTML> <PDF> ✤ without X window: ✤ $ xvfb-run -a -s "-screen 0 640x480x16" wkhtmltopdf -T 0 -L 0 -R 0 -B 0 --page-size A4 --encoding utf-8 <HTML> <PDF> 17
  41. Send File to Printer ✤ Print file: ✤ $ lpr

    -P <NAME> <FILE>... ✤ Show printer queue: 18
  42. Send File to Printer ✤ Print file: ✤ $ lpr

    -P <NAME> <FILE>... ✤ Show printer queue: ✤ $ lpq -P <NAME> 18
  43. Send File to Printer ✤ Print file: ✤ $ lpr

    -P <NAME> <FILE>... ✤ Show printer queue: ✤ $ lpq -P <NAME> ✤ $ lpq -a 18
  44. Send File to Printer ✤ Print file: ✤ $ lpr

    -P <NAME> <FILE>... ✤ Show printer queue: ✤ $ lpq -P <NAME> ✤ $ lpq -a ✤ Cancel print job: 18
  45. Send File to Printer ✤ Print file: ✤ $ lpr

    -P <NAME> <FILE>... ✤ Show printer queue: ✤ $ lpq -P <NAME> ✤ $ lpq -a ✤ Cancel print job: ✤ $ lprm -P <NAME> <JOB_ID>... 18
  46. PyCUPS - Get Printers ✤ Get printers: ✤ conn.getPrinters() ✤

    Example output: ✤ {u'hp': {'device-uri': u'lpd://192.168.0.100/lp', 'printer-info': u'hp', # 3: prepared to print; 4: printing; 5: this device is stop 'printer-state': 3, 'printer-state-message': u'Data file sent successfully', 'printer-state-reasons': [u'none'], ... 'printer-uri-supported': u'ipp://localhost:631/printers/hp'}} 20
  47. PyCUPS - Print File ✤ Print file: ✤ conn.printFile(printer, filename,

    title, options) conn.printFiles(printer, filenames, title, options) 21
  48. PyCUPS - Print File ✤ Print file: ✤ conn.printFile(printer, filename,

    title, options) conn.printFiles(printer, filenames, title, options) ✤ Example: 21
  49. PyCUPS - Print File ✤ Print file: ✤ conn.printFile(printer, filename,

    title, options) conn.printFiles(printer, filenames, title, options) ✤ Example: ✤ conn.printFile(printer, filepath, os.path.basename(filepath), {}) 21
  50. PyCUPS - Get Jobs ✤ Get jobs: ✤ conn.getJobs(which_jobs='not-completed', my_jobs=False,

    limit=-1, first_job_id=-1, requested_attributes=None) ✤ The which_jobs can be 'not-completed', 'completed' or 'all'. 22
  51. PyCUPS - Get Jobs ✤ Get jobs: ✤ conn.getJobs(which_jobs='not-completed', my_jobs=False,

    limit=-1, first_job_id=-1, requested_attributes=None) ✤ The which_jobs can be 'not-completed', 'completed' or 'all'. ✤ It returns a dict, indexed by job id, of dicts representing job attributes. 22
  52. About Template (CSS) ✤ Use cm/mm as your unit ...

    ✤ The steps of adjusting output: 25
  53. About Template (CSS) ✤ Use cm/mm as your unit ...

    ✤ The steps of adjusting output: ✤ Create 1x1 cm div block. 25
  54. About Template (CSS) ✤ Use cm/mm as your unit ...

    ✤ The steps of adjusting output: ✤ Create 1x1 cm div block. ✤ Print it. 25
  55. About Template (CSS) ✤ Use cm/mm as your unit ...

    ✤ The steps of adjusting output: ✤ Create 1x1 cm div block. ✤ Print it. ✤ Use zoom to adjust. 25
  56. About Template (CSS) ✤ Use cm/mm as your unit ...

    ✤ The steps of adjusting output: ✤ Create 1x1 cm div block. ✤ Print it. ✤ Use zoom to adjust. ✤ Avoid floating structure. 25
  57. 29

  58. 29

  59. The End ✤ CUPS ✤ lpadmin, lpstat, lpr, lpq, lprm,

    ... ✤ wxhtmltopdf ✤ PyCUPS 31
  60. The End ✤ CUPS ✤ lpadmin, lpstat, lpr, lpq, lprm,

    ... ✤ wxhtmltopdf ✤ PyCUPS ✤ Some tips 31
  61. The End ✤ CUPS ✤ lpadmin, lpstat, lpr, lpq, lprm,

    ... ✤ wxhtmltopdf ✤ PyCUPS ✤ Some tips ✤ Any Question? 31