Mar 172009
 

Sponsored Link

CUPS-PDF provides a PDF Writer backend to CUPS. This can be used as a virtual printer in a paperless network or to perform testing on CUPS.Documents are written to a configurable directory (by default to ~/PDF) or can be further manipulated by a post-processing command.

This tutorial will set up a virtual PDF printer that outputs files named with a timestamp into the folder ~/PDF.

Install CUPS-PDF in Debian

#aptitude install cups-pdf

Configuring CUPS-PDF

Now go to http://localhost:631″ in a browser,Add the virtual printer, choosing among the options presented,When prompted for a username and password, use "root" as your username and... your root password as your password!

Now go to Menu > Settings > Printing System Settings, select "CUPS"

Configure output settings

# vi /etc/cups/cups-pdf.conf

To change the folder where generated PDF folders are created, edit the line "Out ${HOME}/PDF" to whatever you like.

CUPS-PDF doesn't allow you to change the name of the resulting file, so if you want to customize the filename, use the built-in post-processing option. Still in cups-pdf.conf, uncomment "PostProcessing" and set it to "/usr/local/bin/cups-pdf-renamer".

Create a simple shell script

# vi /usr/local/bin/cups-pdf-renamer

Paste the following code into that file:

#!/bin/bash

FILENAME=`basename $1`
DIRNAME=`dirname $1`
DATE=`date +"%Y-%m-%d_%H:%M:%S"`

mv $1 $DIRNAME"/"$DATE".pdf"

Save and exit the file.

Finally, give the script proper permissions

# chmod 755 /usr/local/bin/cups-pdf-renamer

Now when you choose to print with cups-pdf, you should see a file with a name like "2009-03-16_10:57:03.pdf" in your ~/PDF directory.

Sponsored Link

 Posted by at 12:31 am
  • Al

    [quote]Now go to http://localhost:631? in a browser,Add the virtual printer, choosing among the options presented,[/quote]
    What Make/Manufacturer do you use? Or do you use a PPD file? If so where do you find it?

    I found this to be a very poor “HowTo” and more of a general overview of the package.

    Al

  • Collins

    Pretty minimal howto. For example, cups-pdf requires you to select a printer (or PPD file). Doe it even matter which one, and why if printing to a PDF file?

    I’ll try it anyway.

  • Collins

    Doesn’t seem to work. I printed a document from OpenOffice to the new virtual printer, but when I viewed the generated document via acroread (ie adobe acrobat reader), the document was totally blank.

  • Isaac Izquierdo

    Thanks! I didn’t know there was a PostProcessing option. Here’s my script, it’s limited but it works:

    #!/bin/bash
    export DISPLAY=:0.0
    export XAUTHORITY=/home/$2/.Xauthority
    FILENAME=`basename $1`
    DIRNAME=`dirname $1`
    SAVE_AS=`gxmessage “Save as:” -entrytext $FILENAME`
    mv $1 $DIRNAME”/”$SAVE_AS

  • Jerry

    Also in Debian Lenny does it not work, cause you have always a dialog where you can set name or folder for the output.

  • http://www.proyectopideudneseomexico.org celiapgt

    When chaging the output directory in Ubuntu, you have to also reconfigure the apparmor for cups-pdf. The exact instructions are in
    Changing cups-pdf directory, by erginemr. Until you do it, pdf won’t be written to the Out directory, as I myself verified first.

    Celita

  • firehawk256

    I was confused about the make/manufacturer as well. I just chose “generic” for make and “generic cups-pdf printer” for the model. However, after I finished I noticed that there was already a pdf printer in my cups list. I don’t know how that got there but both seem to work fine.

  • Johnny

    Hi
    Here is my a little bit more comfortable improvement:

    /usr/local/bin/cups-pdf-renamer:
    ——————————–
    #!/bin/bash
    export DISPLAY=:0.0
    export XAUTHORITY=/home/$2/.Xauthority

    FILENAME=`basename $1`
    cd ~
    SAVE_TO=$(zenity –file-selection –save –filename=”$FILENAME”)
    mv “$1″ “$SAVE_TO”

    /etc/cups/cups-pdf.conf:
    —————————-
    change Out directive:
    Out /tmp/cups-pdf # for example

    I hope, someone appreciate this as me

  • Duane

    Yes, configuring in the browser took some doing. You can find the PDF printer under the “generic” printer category.

  • David

    When I will asked for my user-name and pw and I tipe in root and my pw then my pw seems to be wrong…

    Any solution for that?

  • Odus

    Working !
    I have been using the pdf printer for online payment receipts. But the saved PDF file always gets overwriten if the receipt is from the same site, since the filename is from the URL. I want to append date to the generated file name, avoiding overwriting existing file.

    Changed the last 2 lines to append date (no time parts) to the generated file name:

    DATE=`date +”%Y-%m-%d”`
    mv $1 $DIRNAME”/”$FILENAME-$DATE”.pdf”