- SDB:Printing to PDF
- Contents
- Printing to PDF from Desktops
- Download and install the cups-pdf package
- Set up a print queue for cups-pdf
- Adjust permissions for cups-pdf
- Configuration options for cups-pdf
- PDF output location
- External links
- Background Information regarding Print as PDF versus Save as PDF
- Cups pdf for linux
- User-contributed addons for CUPS-PDF
- Установка виртуального PDF принтера в Linux
SDB:Printing to PDF
CUPS-PDF provides a virtual PDF printer which produces PDF files so that application programs which have no built-in support to «Save as PDF» could «Print to PDF» as workaround to get a PDF file.
Do this only if you know about the consequences, in particular when running a multi-user system. This may cause a denial of service (spool directory fills up so that the harddisk may run full), no privacy of data (anyone may read the PDFs), or specially crafted printjobs might be able to cause security issues.
Contents
Printing to PDF from Desktops
Depending on which desktop system (in particular Gnome versus KDE) is installed and depending on which version of the desktop system is used and depending on which additional packages are installed, the desktop system may already provide a Print to PDF or Save as PDF functionality (see below) out-of-the-box so that there is no need for CUPS-PDF.
Download and install the cups-pdf package
Go to the software search page, and search for the cups-pdf package for your version of openSUSE.
Preferably use the package from the «Printing» repository.
To download RPM packages manually from the «Printing» repository use http://download.opensuse.org/repositories/Printing/ and go to the matching sub-directory for your particular system and architecture (in particular 32-bit i586 versus 64-bit x86_64).
If you install software from whatever arbitrary repository, make sure you really know what you do. Is it really the exact software which you expect? Does it really match your currently running system?
Set up a print queue for cups-pdf
A print queue must be set up so that user application programs can print, see Concepts printing. In this case a special print queue is set up which does not print to a real printer device but stores the printout as PDF file.
Any printer setup tool which works in compliance with CUPS can be used.
- Instead of a real printer device «Virtual PDF Printer (CUPS-PDF)» must be selected which uses the CUPS device URI «cups-pdf:/».
- The matching printer driver is «Generic CUPS-PDF Printer» (under the manufacturer «Generic») which uses the PPD file «/usr/share/cups/model/CUPS-PDF.ppd».
As user root via lpadmin command it could be done as follows (see «How to set up a print queue in full compliance with CUPS» at SDB:CUPS in a Nutshell):
lpadmin -h localhost -p cups-pdf -v cups-pdf:/ -P /usr/share/cups/model/CUPS-PDF.ppd -E
Alternatively when you use for example the CUPS web frontend to set up the print queue, the procedure is like (depending on the CUPS version it could be different):
- Open the CUPS web frontend http://localhost:631 using a web browser like Firefox.
- Use the «root» username and password (or any username with CUPS admin rights) when prompted for authentication.
- Select the Administration tab and click «Find New Printers».
- You should see Virtual PDF Printer (CUPS-PDF), click «Add This Printer» and then «Continue».
- In the next screen «MAKE/MANUFACTURER FOR CUPS-PDF», select Generic and click «Continue». Then select Generic CUPS-PDF Printer and click «Add Printer».
- Optionally change the default page size to match the locality (i.e. A4 versus US Letter) under the PDF:General, Page Size setting.
Adjust permissions for cups-pdf
cups-pdf provides the CUPS backend /usr/lib/cups/backend/cups-pdf which needs root privileges to set the file ownerships for the PDFs to the user who submitted the print job. You may have a look at «What is a CUPS backend and how does it work» in SDB:CUPS in a Nutshell.
By default the permissions for cups-pdf should be correct.
In exceptional cases you may have to run the following command as root so that /usr/lib/cups/backend/cups-pdf is run as «root»
chmod u=rwx,go= /usr/lib/cups/backend/cups-pdf
because since CUPS 1.2 backends without world execute permissions are run as the root user, see «man backend».
For CUPS 1.1 you may have to use something like
chmod u=rwxs,go= /usr/lib/cups/backend/cups-pdf
or even (when a CUPS 1.1 cupsd runs as user «lp»)
chown root:lp /usr/lib/cups/backend/cups-pdf chmod u=rwxs,g=x,o= /usr/lib/cups/backend/cups-pdf
so that the CUPS backend is run as setuid root program.
Configuration options for cups-pdf
The configuration options are stored and described in the /etc/cups/cups-pdf.conf file. For some hints and notes see also /usr/share/doc/packages/cups-pdf/README.
PDF output location
The default location for the PDF files is
/var/spool/cups-pdf/yourusername/
To change this, edit the /etc/cups/cups-pdf.conf file. For example to store the PDF files in the «Desktop» directory in each user’s home directory you may set:
In this case have in mind that the printing system cannot store files at arbitrary places, see «Background Information regarding Print as PDF versus Save as PDF» below.
External links
Background Information regarding Print as PDF versus Save as PDF
User applications (including user print dialog programs) run on the user’s local machine as a user’s process under the user’s ID (i.e. they run in the user’s personal environment). Therefore user applications can store files (e.g. PDFs) in the user’s home directory (or wherever the user has specified in the application).
On the other hand the processes of the printing system do not run under the user’s ID and in case of printing in the network they even run on an arbitrary different machine in the network.
Therefore the printing system cannot store files in whatever place which was specified by a user who has submitted a print job.
On a single-user stand-alone system it works to print to a «PDF printer» which stores a PDF at a predefined file location but this can cause issues in a multi-tasking multi-user networked system.
Some applications provide a «print to (PostScript/PDF) file» functionality. This is done by the user application itself. No printing system is involved when the user application does not send its printing output to a print queue but instead stores it into whatever file the user likes.
The wording «print to file» is misleading because what actually happens is «save as (PostScript/PDF) file».
Probably the reason for the confusion with the wording is that the «save as PS/PDF» functionality is often not found in the «File» menue. Instead in the «Print» menue a «print to file» option can be found and fortunately this results a PostScript or PDF file so that for the user it looks as if printing is done when he likes to do «save as PS/PDF file».
Strictly speaking «save as PS/PDF» and «print to file» are not the same regarding the result. Only «save as PS» guarantees that the result is a PostScript file and «save as PDF» guarantees that the result is a PDF file.
In contrast «print to file» can result whatever arbitrary printer-specific (binary) data which the application produces to be sent as print job.
Only by luck (more precisely because PostScript or PDF is the usual data format when Unix/Linux applications produce data for print jobs, see Concepts printing) it happens that «print to file» can be misused when there is no «save as PS/PDF» functionality in the application.
There is no guarantee that such a PostScript or PDF file could be printed later on any printer because it could be printer-specific PostScript or printer-specific PDF. For example OpenOffice is known to produce printer-specific PostScript so that such a PostScript file may only print on the printer for which OpenOffice has made it.
When there is no «save as PS/PDF» functionality in the application a possible workaround on a stand-alone system is to set up a «PDF printer» which stores a PDF at a predefined file location to get hopefully a printer-independent PDF file.
The real solution is to have a properly implemented «save as PDF file» functionality in the application which really results a printer-independent PDF file.
A printer-independent PDF file should be PDF/A — preferably PDF/A-1 — or PDF/X (see «PostScript versus PDF as standard print job format» at Concepts printing).
Cups pdf for linux
Martin-Éric Racine maintains a Debian package of CUPS-PDF which is part of the official distribution.
For openSUSE packages are maintained at their Build Service.
Remi Collet maintains RPM packages for Fedora, RHEL, and CentOS which are available from Fedora packages.
For Gentoo there is a package of CUPS-PDF in the net-print category.
A build of CUPS-PDF for Slackware can be found on On bitbucket a package for Mac OS X is available. Futhermore, MacPorts offers a portfile.
Simon Olofsson maintains a port of the current CUPS-PDF for FreeBSD on FreshPorts.
CUPS-PDF is also available in the packages and ports collection of OpenBSD.
A package of CUPS-PDF for the T2 System Development Environment can be found here.
User-contributed addons for CUPS-PDF
- This filter allows conversion of character encoding in PS files for processing by CUPS-PDF. This will allow international characters in filenames when printing from Windows clients.
- An elaborate postprocessing script for CUPS-PDF that allows sending mails with the created PDFs to users.
- This script uses a CUPS-PDF config file and converts its contents to lpoption settings for the current user (take care: executing it as root will set the system default!).
As far as not explicitly stated otherwise all of the contributed software is distributed under the same license as CUPS-PDF (GPLv2) — check Licensing for more information.
Установка виртуального PDF принтера в Linux
В Linux вы можете использовать пакет cups-pdf для реализации виртуального PDF принтера. Что такое PDF-принтер? Это виртуальное устройство, которое добавляется в систему как обычный принтер и при отправке документа на печать генерирует из него pdf-файл.
Проверьте, что в вашем дистрибутиве Linux установлена подсистема печати CUPS (Common UNIX Printing System):
Проверьте, что на компьютере слушается порт TCP/631 и служба cups запущена:
$ sudo systemctl status cups
Теперь можно установить пакет cups-pdf:
Перезапустите систему печати:
$ sudo service cups restart
Выведите список установленных принтеров и какой принтер назначен по-умолчанию:
CUPS-PDF (Virtual PDF Printer)
Выведите список установленных принтеров и какой принтер назначен по-умолчанию:
CUPS-PDF (Virtual PDF Printer) system default destination: PDF device for PDF: cups-pdf:/
Если принтер отключен, его можно включить:
Можно вручную создать новый PDF принтер в CUPS с помощью команды:
$ sudo lpadmin -p cups-pdf -v cups-pdf:/ -E -P /usr/share/ppd/cups-pdf/CUPS-PDF_opt.ppd
Если в списке появился виртуальный принтер, вы можете отправлять на него любые документы и сохранять результат в PDF файл. По умолчанию файлы в формате name-job_N.pdf сохраняются в каталог пользователя ~/PDF ( Out $/PDF ).
Вы можете изменить путь к каталогу в конфигурационном файле /etc/cups/cups-pdf.conf.
Вы можете управлять настройками и очередью печати на виртуальном PDF принтере через веб интерфейс CUPS.
Перейдите в браузере на http://yourcupshost:631/printers
Выберите очередь PDF для принтера Generic CUPS-PDF Printer (w/ options)
Здесь вы можете изменить настройки печати (page size, output resolution), открыть к нему общий доступ, очистить очередь печати и т.д.
Description: PDF Location: Driver: Generic CUPS-PDF Printer (w/ options) (color) Connection: cups-pdf:/ Defaults: job-sheets=none, none media=iso_a4_210x297mm sides=one-sided
Вы можете отправить на печать в PDF файл из любого приложения или прямо из консоли Linux. Например, чтобы сохранить содержимое conf файла в PDF, просто отправьте его через пайплайн на lpr (для печати будет использоваться принтер по-умолчанию).
$ cat /etc/cups/cups-pdf.conf | lpr
Или вы можете отправить файл на печать так: