'CUPS'에 해당되는 글 1건

  1. 2017.07.11 Linux에 IP로 공유된 PDF 프린터 설정하기

(불친절한) 삽질 내용을 적어 봅니다. 친절한 버젼은 나중에 시간이 나면 업데이트 하겠습니다.

메모식으로 적어서 반말이 섞여있으니 양해 부탁드립니다

VM과 리눅스에 대한 기본적 세팅방법을 하시면 한번 해 보시면 어떨까 싶네요.


<목적>

완벽한(?) 'IP 네트워크로 보이는 PDF 프린터 VM'을 만들기 위해서 해봤다.

SMB 공유된 프린터로는 막히는 사이트들이 많기 때문에, IP 공유된 프린터를 만들어야 한다.

그냥 cups-pdf에서 만들어진 pdf를 일반적으로 많이 쓰는 http://ip:631/priters/XXX 를 가져다가 공유를 해봤자, samba와 다름없게 \\~~식으로 공유가 되기 때문에, 그런(?) 철저한 사이트들에서는 block이 됩니다.


다른 경우들을 보면, Windows에서 rawprintserver 라는 프로그램을 활용하는 방법이 있는데, 동일 PC에서는 IP문제로 안되고, Windows10_64bit에서는 동작을 하지 않음.(Win7에서만 방화벽 끄고 성공하며, PrimoPDF 등 몇개만 프린트가 가능하고, 다른 Adobe PDF등으로는 프린트가 안됨.)


<삽질 내용>

1) Ubuntu 16.04 LTS (distro xenial) 에서는 세팅하기가 복잡하다. (아래 대충 적은거 읽고 이해되면 따라하시고, 아니면 이후 버젼을 쓰자.)

   - 기본적으로 16.04에서는 apt-get으로 설치가 가능한 CUPS가 cups-lpd 모듈에 한글 처리에 심각한 버그가 있는 2.1.3 이다.

     (이것 때문에 cups를 로그를 파보는 삽질을 해봤다. 한글이 job-name이나 document-name등의 meta data에 들어가 있으면 아예 cupsd로 넘기지도 않는다. ㅠㅠ)

   - distro별 cups 버젼 참고: https://launchpad.net/ubuntu/+source/cups

   - 이것은 2.1.4부터 해결이 된 버그이기 때문에, Yakky나 Zesty를 깔아야 하는데, 16버젼에다가 이걸 깔려면 꽤나 삽질이 필요하다.

   - 내 경우 sources.list에다가 zesty를 추가하고, cups 모듈들은 zesty에서 가져오게 pinning 하여 설치하였다. 버전 conflict를 피하게 pinning이 필요하다.

File: /etc/apt/sources.list 에 하기 내용을 맨 아랫줄에 추가

deb http://kr.archive.ubuntu.com/ubuntu/ zesty universe multiverse restricted main


File: /etc/apt/preferences.d/cups 을 생성해서 하기 pinning 내용 추가
Package: cups* cups-pdf
Pin: release a=zesty
Pin-Priority: 1001

Package: printer-driver-cups-pdf
Pin: release a=xenial
Pin-Priority: 1001


설치 하기 위해서 다음의 cmd 수행:

sudo apt-get update

sudo apt-get install cups-pdf


   -  cups를 맞는 버젼으로 설치후에 다시 꼭 원상복구 해서 추후 실수로 apt-get upgrade 시에 패키지(및 커널)을 상위 버젼대(17.x)로 업그래이드 하면서 꼬이는걸 방지해야한다!


2) cups-lpd 사용 자체가 legacy한 방법이라고 권장하지 않기 때문에, service/socket 설정이 기본적으로 빠져있다.

   - systemd 설정법 참고: https://askubuntu.com/questions/916559/enable-cups-lpd-on-server-16-04-lts

   - 여기서 sudo systemctl enable cups-lpd.socket 가 빠져있다. (이거 해야 리붓하고 자동으로 켜짐)


3) cups-pdf가 파일명에 multibyte/unicode character가 들어오면 파일을 못만든다. (혹은 Linux에서만 보이고, smb에서 안보임)

   --> 파일명은 job-name이나, PS에 포함된 title을 참조하게 되므로, 다음 두가지 해결법 중 하나(또는 적당히 섞어서)를 택하면 된다.

   - 해결법1: cups-lpd에서 강제로 job-name을 설정하고, cups-pdf에서 title 대신 이것을 사용하도록 강제함(None이 파일명이 된다.)

File: /lib/systemd/system/cups-lpd@.service

[Unit]

Description=CUPS LPD server

Documentation=man:cups-lpd(8)


[Service]

ExecStart=/usr/lib/cups/daemon/cups-lpd -o document-format=application/octet-stream -o job-name=None

StandardInput=socket


[Install]

WantedBy=multi-user.target


File: /etc/cups/cups-pdf.conf 에서 하기 내용 반영

### Key: TitlePref

##  where to look first for a title when creating the output filename

##  (title in PS file or title on commandline):

##  0: prefer title from %Title statement in the PS file

##  1: prefer title passed via commandline

### Default: 0


TitlePref 1

--> 1: commandline 을 사용하게 하면 위에서 설정한 job-name을 사용하게 된다.


   - 해결법2: cups-pdf에서 title이 hex일경우 decode 하지 말라고 설정

File: /etc/cups/cups-pdf.conf 에서 하기 내용 반영

### Key: DecodeHexStrings

##  this option will try to decode hex strings in the title to allow

##  internationalized titles

##  (have a look at contrib/pstitleconv for a suitable filter for data

##   from Windows clients)

##  0: disable, 1: enable

### Default: 0


#DecodeHexStrings 1

DecodeHexStrings 0

--> 이걸 세팅하면 굳이 multibyte/unicode 인지 구분도 안되는 HEX title을 파일명으로 컨버팅하면서, 파일을 못만들어서 프린트를 못하거나 파일명이 이상한 경우가 방지된다. 그냥 HEX 그대로 파일명으로 사용하게 된다.


4) Windows에서 프린터 추가 방법

다른 드라이버 깔필요도 없고, 기본 HP 드라이버중에 뒤에 PS가 붙은것을 추가한다.

(예: Color LaserJet 4800 PS, LaserJet 2300 PS 등. )

편의상 일단 LPT로 추가하고, 다음 설정으로 TCP/IP Port를 추가 하여 포트로 세팅한다:

  - Port IP는 UBUNTU 가상머신의 주소

  - Protocol은 LPR

  - LPR Queue 이름 PDF (cups에서 알려주는 이름)

  - LPR Byte 체크박스 설정


5) 기타 참고사항

   - cups-pdf 에서 PDF 프린터가 기본적으로 share가 안되어있으므로, CUPS Admin에서 설정해 줘야 한다. (web 인터페이스에서 modify 선택하여 설정 하면 편함)

   - cups-pdf의 파일 저장경로를 전혀 딴데로 하려면 apparmor 에서 경로를 풀어줘야 한다. (selinux 스펙 때문에 별게 다 들어가서 골썩인다.)

File: /etc/apparmor.d/usr.sbin.cupsd 에서 아래같은 식으로 추가

# separate profile since this needs to write into /home

/usr/lib/cups/backend/cups-pdf {

  #include <abstractions/base>

  #include <abstractions/fonts>

  #include <abstractions/nameservice>

  #include <abstractions/user-tmp>


  capability chown,

  capability fowner,

  capability fsetid,

  capability setgid,

  capability setuid,


  # unfortunate, but required for when $HOME is 700

  capability dac_override,

  capability dac_read_search,


  # allow communicating with cupsd via Unix sockets

  unix peer=(label=/usr/sbin/cupsd),


  @{PROC}/*/auxv r,


  /{usr/,}bin/dash ixr,

  /{usr/,}bin/bash ixr,

  /{usr/,}bin/cp ixr,

  /etc/papersize r,

  /etc/cups/cups-pdf.conf r,

  /etc/cups/ppd/*.ppd r,

  @{HOME}/PDF/ rw,

  @{HOME}/PDF/* rw,

  /share/PDF-PRINTER/ rw,

  /share/PDF-PRINTER/* rw,

  /usr/bin/gs ixr,

  /usr/lib/cups/backend/cups-pdf mr,

  /usr/lib/ghostscript/** mr,

  /usr/share/** r,

  /var/log/cups/cups-pdf*_log w,

  /var/spool/cups/** r,

  /var/spool/cups-pdf/** rw,

}


   - cups-pdf가 파일명이 중복된 요청이 들어오면 그냥 덮어쓴다. job#을 파일명에 꼭 붙여서 방지해주도록 하자.

File: /etc/cups/cups-pdf.conf 에서 하기 내용 반영

### Key: Label

##  label all jobs with a unique job-id in order to avoid overwriting old

##  files in case new ones with identical names are created; always true for

##  untitled documents

##  0: label untitled documents only

##  1: label all documents with a preceeding "job_#-"

##  2: label all documents with a tailing "-job_#"

### Default: 0


Label 1


   - pdf 파일이 저장된 폴더를 samba 공유를 열어서 windows로 쉽게 꺼내게 하는건 다른 강좌들이 많으니 참고하자. 아래는 내설정

File: /etc/samba/smb.conf 맨 아래에 추가

[PDF-PRINTER]

   comment = PDF printer output

   path = /share/PDF-PRINTER

   browseable = yes

   read only = no

   guest ok = yes

   create mask = 0000

   directory mask = 0000


: