LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-07-2024, 09:32 PM   #1
Kenan
LQ Newbie
 
Registered: May 2024
Posts: 7

Rep: Reputation: 0
CUPS PDF output file name changing


Is there a way to change the CUPS PDF printer output file name? I use Ubuntu and most recent CUPS.

I tried a script, cups-pdf.conf file, lp options but I was not able to find a way.

If you have a solution for this please let me know
 
Old 05-08-2024, 10:50 AM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,781

Rep: Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935
I have not played with cups-pdf in awhile but you should be able to add a post-processing script in the cups-pdf.conf file.

Quote:
### Key: PostProcessing (config, lptoptions)
## postprocessing script that will be called after the creation of the PDF
## as arguments the filename of the PDF, the username as determined by
## CUPS-PDF and the one as given to CUPS-PDF will be passed
## the script will be called with user privileges
## set this to an empty value to use no postprocessing
 
1 members found this post helpful.
Old 05-08-2024, 09:19 PM   #3
Kenan
LQ Newbie
 
Registered: May 2024
Posts: 7

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by michaelk View Post
I have not played with cups-pdf in awhile but you should be able to add a post-processing script in the cups-pdf.conf file.
I have already written a script. So should I just paste it with the starting Key, "PostProcessing"? How can I use my script for this?

#PDFVer 1.4

### Key: PostProcessing (config, lptoptions)
## postprocessing script that will be called after the creation of the PDF
## as arguments the filename of the PDF, the username as determined by
## CUPS-PDF and the one as given to CUPS-PDF will be passed
## the script will be called with user privileges
## set this to an empty value to use no postprocessing
### Default: <empty>

PostProcessing



My Script:

#!/bin/bash
# /etc/cups/generate_pdf_filename.sh

# Get current user login
USER=$(whoami)

# Get hostname
HOSTNAME=$(hostname)

# Generate timestamp
TIMESTAMP=$(date +'%Y-%m-%d_%H-%M-%S')

# Construct filename
FILENAME="${HOME}/PDF/stdntrns_${USER}_${HOSTNAME}_${TIMESTAMP}.pdf"
 
Old 05-09-2024, 12:42 PM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,781

Rep: Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935
It seems like you copied the script from another forum/thread that did not appear to work.

In another thread it appeared like it was not possible to create another file name via the cups configuration file since Ubuntu developers changed the cups-pdf code. I have not looked at the source code. I don't see any option with cups-pdf from debian repository either.

Change cups-pdf.conf to make the script executable. I don't necessarily like /etc/ for executable scripts.
Quote:
PostProcessing /path/to/generate_pdf_filename.sh
untested.
Quote:
#!/bin/bash

USER=$2 # 2nd command line argument passed is user name
OLD_FILE=$1 # 1st command line argument file name as generated by cups-pdf
HOSTNAME=$(hostname)
TIMESTAMP=$(/usr/bin/date +'%Y-%m-%d_%H-%M-%S')
mv "$OLD_FILE" "/home/$USER/PDF/stdntrns_${USER}_${HOSTNAME}_${TIMESTAMP}.pdf"

Last edited by michaelk; 05-10-2024 at 03:47 AM.
 
Old 05-09-2024, 11:53 PM   #5
Kenan
LQ Newbie
 
Registered: May 2024
Posts: 7

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by michaelk View Post
It seems like you copied the script from another forum/thread that did not appear to work.

In another thread it appeared like it was not possible to create another file name via the cups configuration file since Ubuntu developers changed the cups-pdf code. I have not looked at the source code. I don't see any option with cups-pdf from debian repository either.

Change cups-pdf.conf to make the script executable. I don't necessarily like /etc/ for executable scripts.


untested.
I am the one who asks this question for different forums. The script was written by me. So I will try on PostProssesing. Can you provide more information about this?
The question is when I change the cups-pdf.conf file as you stated and with my script. Is there anything else should I do? Like -lp options or something like that? Or you said that one right script and cups-pdf.conf are enough for this. Right?
 
Old 05-10-2024, 03:49 AM   #6
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,781

Rep: Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935
My script and posted changes to the conf file should be enough.
 
Old 05-10-2024, 12:14 PM   #7
Kenan
LQ Newbie
 
Registered: May 2024
Posts: 7

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by michaelk View Post
My script and posted changes to the conf file should be enough.
I will let you know. Thank you so much, Michael.
 
Old 05-18-2024, 01:23 AM   #8
Kenan
LQ Newbie
 
Registered: May 2024
Posts: 7

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by michaelk View Post
My script and posted changes to the conf file should be enough.
Unfortunately, it did not work. Are you sure about the script you send me?


#!/bin/bash

USER=$2 # 2nd command line argument passed is user name
OLD_FILE=$1 # 1st command line argument file name as generated by cups-pdf
HOSTNAME=$(hostname)
TIMESTAMP=$(/usr/bin/date +'%Y-%m-%d_%H-%M-%S')
mv "$OLD_FILE" "/home/$USER/PDF/stdntrns_${USER}_${HOSTNAME}_${TIMESTAMP}.pdf"
 
Old 05-18-2024, 07:14 AM   #9
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,781

Rep: Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935
I tested it using debian versus Ubuntu but I am fairly certain it will work. Did you remove the leading '#' in front of postprocessing? Did you use the full path to your script and is it executable?
 
Old 05-20-2024, 04:07 PM   #10
Kenan
LQ Newbie
 
Registered: May 2024
Posts: 7

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by michaelk View Post
I tested it using debian versus Ubuntu but I am fairly certain it will work. Did you remove the leading '#' in front of postprocessing? Did you use the full path to your script and is it executable?
Hello again, unfortunately, it does not work. Do you have any ideas ? I have added all the related information below. Please help me.

I use Ubuntu.

You may find my cups-pdf.conf below:

## set this to an empty value to use no postprocessing
### Default: <empty>

PostProcessing /etc/cups/generate_pdf_filename.sh

###########################################################################

And this is my generate_pdf_filename.sh script with permission information.

PERMISSIONS

informix@legacysparc:/etc/cups$ ls -la generate_pdf_filename.sh
-rwxrwxrwx 1 root root 181 May 17 15:01 generate_pdf_filename.sh

SCRIPT

GNU nano 6.2 generate_pdf_filename.sh
#!/bin/bash

USER=$2
OLD_FILE=$1
HOSTNAME=$(hostname)
TIMESTAMP=$(/usr/bin/date +'%Y-%m-%d_%H-%M-%S')
mv "$OLD_FILE" "/home/$USER/PDF/stdntrns_${USER}_${HOSTNAME}_${TIMESTAMP}.pdf"

LPOPTIONS

informix@legacysparc:/etc/cups$ lpoptions
copies=1 device-uri=cups-pdf:/ finishings=3 job-cancel-after=10800 job-hold-until=no-hold job-priority=50 job-sheets=none,none marker-change-time=0 name=PDF number-up=1 OutputFile=/home/informix/PDF OutputScript=/etc/cups/generate_pdf_filename.sh page-bottom=36 page-left=36 page-right=36 page-top=36 PDF=true pdftops-renderer=pdftocairo PDFVer=1.5 print-color-mode=color printer-commands=AutoConfigure,Clean,PrintSelfTestPage printer-info=PDF printer-is-accepting-jobs=true printer-is-shared=false printer-is-temporary=false printer-location printer-make-and-model='Generic CUPS-PDF Printer (w/ options)' printer-state=3 printer-state-change-time=1716237954 printer-state-reasons=none printer-type=10678348 printer-uri-supported=ipp://localhost/printers/PDF
 
Old 05-20-2024, 05:16 PM   #11
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,781

Rep: Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935
Quote:
GNU nano 6.2 generate_pdf_filename.sh
Does your script actually contain the above? If so, it would cause an error and should be deleted. Otherwise the script should work as posted. I am testing the script by printing a text file from the command line.

lp -d PDF some_text.file

FWIW
Quote:
lpoptions
copies=1 device-uri=cups-pdf:/ finishings=3 job-cancel-after=10800 job-hold-until=no-hold job-priority=50 job-sheets=none,none marker-change-time=0 media number-up=1 output-bin=face-down pdftops-renderer=pdftocairo print-color-mode=color printer-commands=AutoConfigure,Clean,PrintSelfTestPage printer-info=PDF printer-is-accepting-jobs=true printer-is-shared=false printer-is-temporary=false printer-location printer-make-and-model='Generic CUPS-PDF Printer (w/ options)' printer-state=3 printer-state-change-time=1716243083 printer-state-reasons=none printer-type=10678348 printer-uri-supported=ipp://localhost/printers/PDF sides=one-sided
 
Old 05-21-2024, 11:56 AM   #12
Kenan
LQ Newbie
 
Registered: May 2024
Posts: 7

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by michaelk View Post
Does your script actually contain the above? If so, it would cause an error and should be deleted. Otherwise the script should work as posted. I am testing the script by printing a text file from the command line.

lp -d PDF some_text.file

FWIW
No, my script does not have that line.

When I run below command..

informix@legacysparc:~$ lp -d PDF mytextfile.txt
request id is PDF-323 (1 file(s))


I got this. So the script did not work!

-rw------- 1 informix informix 9000 May 21 12:51 mytextfile-job_323.pdf
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to combine a .txt file and a .pdf file into one .pdf file rblampain Programming 1 01-11-2023 04:51 AM
[SOLVED] lp doesn't print file to pdf directory after installing cups-pdf using synaptic mrcj Debian 1 10-09-2013 07:18 PM
How to search contents of multiple pdf files and return the pdf's file name? Hoxygen232 Linux - Newbie 4 04-28-2013 09:39 AM
My cups-pdf pdf printer is not working. sgsawant Linux - Software 1 03-16-2010 02:35 AM
How to wget a webpage, and save as PDF (like cups-pdf) ? frenchn00b Programming 3 11-18-2008 03:48 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration