PDF printer for puppy

Stuff that has yet to be sorted into a category.
Message
Author
DavidBell
Posts: 132
Joined: Fri 24 Nov 2006, 21:44

#16 Post by DavidBell »

Is this make it into 2.16 final (DLed a week or so ago)? If so what steps do I need to take to print a pdf from Seamonkey? I couldn't find it in the Puppy printer wizard.

TIA. DB

User avatar
BarryK
Puppy Master
Posts: 9392
Joined: Mon 09 May 2005, 09:23
Location: Perth, Western Australia
Contact:

#17 Post by BarryK »

Menu -> System -> Xpdq printer management.

The pdf print entries should be there, you choose one of them and make it the default printer (Xpdq has a menu selection for that).

For any app, if you print to lpr, it should end up as a pdf file.

DavidBell
Posts: 132
Joined: Fri 24 Nov 2006, 21:44

#18 Post by DavidBell »

Thanks Barry (and jcoder). This is something I really wanted. DB

User avatar
jcoder24
Posts: 604
Joined: Fri 06 May 2005, 12:33
Location: Barbados

#19 Post by jcoder24 »

The following script creates a pdf printer for CUPS called CUPS-PDF. This script was adapted from http://www.novell.com/coolsolutions/feature/17636.html. It works the same way as the PDQ version. After testing I'll package it as a dotpet. Please test.

Code: Select all

#!/bin/sh

> /usr/lib/cups/backend/pdf-writer 
cat >> /usr/lib/cups/backend/pdf-writer << EOF_BACKEND
#!/bin/sh
#################################################################################
#
#	File:			pdf-writer
#
#	Description: 	A simple PDF Writer for CUPS 
#
#	Copyright:		(c) 2006  Axel Schmidt,  SUSE LINUX GmbH, Nuernberg, Germany
#				(c) 2001  Michael Goffioul (kdeprint <at> swing <dot> be)
#
#	License:		GPL
#
#################################################################################

PS2PDF=\`which ps2pdf\`

# USERMODE="on" changes PDFPATH to "\$HOME/<user-name>/PDF" 
#
USERMODE="off"
DEFGROUP="users"
JOB=\$1
PRTUSER=\$2

# Check DEVICE DISCOVERY + test PS2PDF 
#
if [ "\$JOB" = "" ]; then
        if test -f "\$PS2PDF" ; then
                echo "file pdf-writer:/export/share/pdf \"unkown\" \"pdf writer\" " 
                logger "pdf-writer: INFO: USERMODE=\"\$USERMODE\""
                if [ "\$USERMODE" = "on" ]; then
                   logger "pdf-writer: CUPS user must be set to root with USERMODE=\"on\"!"
                fi
                exit 0  
        else
                echo "Error: \$0 - ps2pdf is not available!"      
                logger "pdf-writer: ERROR: ps2pdf is not available!"      
                exit 1 
        fi 
fi

logger "pdf-writer started: \$1 \$2 \$3 \$4 \$5 \$6"

# Check number of command line arguments
#
if [ \$# -ne 5 -a \$# -ne 6 ]; then
        echo "Usage: \$0 job-id user title copies options [file]"
        logger "pdf-writer: CRITICAL: Printer stopped !"      
        exit 1
fi

# Get pdf filename from user via xdialog
# added by jcoder24
export PATH=\$PATH:/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/X11R7/bin
export DISPLAY=":0.0"

if [ "\`whoami\`" = "root" ]; then
	export XAUTHORITY="/root/.Xauthority"
	export "FOLDER=/root"
else
	export XAUTHORITY="/home/\`whoami\`/.Xauthority"
	export FOLDER="/home/\`whoami\`"
fi

FILENAME=\`Xdialog --title "PDF-Writer - Save As..." --fselect "\$FOLDER" 28 60 2>&1 | tail -1 | gawk '{gsub (/\.pdf\$|\.PDF\$/,"",\$0); print \$0'}\`

if [ -z "\$FILENAME" ]; then
	exit 0
fi

if [ -f "\$FILENAME.pdf" ]; then 
	FILENAME="\$FILENAME-\`date +%m%d-%H%M-%S\`.pdf"
else
	FILENAME="\$FILENAME.pdf"
fi

# get PDF-WRITER directory file selected 
# modified by jcoder24
PDFPATH="\`dirname \$FILENAME\`" 
logger "pdf-writer: \"\$FILENAME\" was placed in: \$PDFPATH"

# Check write status 
#
if [ ! -d "\$PDFPATH" -o ! -w "\$PDFPATH" ]; then
        logger "pdf-writer: ERROR: directory \$PDFPATH not writeable"
        exit 1
fi

# Run ps2pdf (ghostscript)
#
if [ \$# -eq 6 ]; then
        \$PS2PDF \$6 \$FILENAME >& /dev/null
else
        \$PS2PDF - \$FILENAME >& /dev/null
fi

# Chown + set permissions for the user 
# Note: this will not work if CUPS runs as lp
if [ "\$PRTUSER" != "" ]; then
        chmod 644 \$FILENAME
        chown \$PRTUSER:\$DEFGROUP \$FILENAME
fi
exit 0

#
#########################  CUPS pdf-writer ends here  ########################
#
EOF_BACKEND

chmod 755 /usr/lib/cups/backend/pdf-writer
ln -sf /usr/share/ghostscript/8.15/lib/ghostpdf.ppd /usr/share/cups/model/ghostpdf.ppd
/etc/init.d/cups restart
sleep 5
lpadmin -p CUPS-PDF -v pdf-writer:/export/share/pdf/ -E -P /usr/share/cups/model/ghostpdf.ppd 
/etc/init.d/cups restart

User avatar
BarryK
Puppy Master
Posts: 9392
Joined: Mon 09 May 2005, 09:23
Location: Perth, Western Australia
Contact:

#20 Post by BarryK »

jcoder24, that's great that you're tackling the CUPS implementation of print-to-pdf! ...now that Puppy has CUPS.

If we get some positive tests, then it would be good to get it into the 2.17-final.

JB4x4
Posts: 256
Joined: Sun 30 Jul 2006, 22:44
Contact:

#21 Post by JB4x4 »

I tried the script in Puppy 2.16 using pakt's CUPS install v0.3 and it worked as expected (very good). I did notice that everything was "printing" black and white, but did not take time to investigate.

EDIT: I needed to change a couple of lines at the end of the script to read /etc/rc.d/rc.cups instead of /etc/init.d/cups to work with 2.16 properly.

JB
Last edited by JB4x4 on Tue 17 Jul 2007, 09:38, edited 1 time in total.

disciple
Posts: 6984
Joined: Sun 21 May 2006, 01:46
Location: Auckland, New Zealand

#22 Post by disciple »

Is this just aimed at 2.17 at the moment?
I installed the Cups dotpup in 2.16.1, and have no /etc/init.d/cups, so get this when I run the script:

sh-3.00# ./pdf
./pdf: line 115: /etc/init.d/cups: No such file or directory
lpadmin: Unable to connect to server: Connection refused
./pdf: line 118: /etc/init.d/cups: No such file or directory

I just rebooted, and then ran the second to last line in the script again, and then rebooted again, but if someone can advise how to restart cups, then that would help other people.

disciple
Posts: 6984
Joined: Sun 21 May 2006, 01:46
Location: Auckland, New Zealand

Breaks when you cancel a job

#23 Post by disciple »

:( OK.
So I installed in my Grafpup 104 install, which uses the latest CUPS dotpup. I went to print something to pdf, then on a whim pressed cancel when it asked me where to save it. Now when I try to print to pdf the job gets added to the queue, it asks me where I want to save it, and then it pauses the printer (according to CUPS). Telling CUPS to start the printer starts it, then pauses it immediately, and the job stays in the queue. If the printer was paused when I printed the job, it starts the job, asks me where to save it, then pauses the job straight away. My real printer works fine still. I never printed a page, so can't tell if the PDF printer worked to start with and is just broken because I cancelled a job.

So I installed in Puppy 2.16.1 with the same CUPS dotpup, and printed a test page (colour worked). So it definitely worked here to start with. I then printed something, but pressed cancel when it asked me where to save it, like before. Now when I print something it goes through the thing preparing it for printing, adds it to the queue, doesn't ask me where to save it, and pauses the printer. Unlike in Grafpup, if I now tell CUPS to start the printer, it starts and then pauses straight away, but does not ask where to save it. So it is impossible to get to the stage where it asks me where to save it.
More disturbingly, I then installed my real printer in Puppy (an HP PSC1610), using the HPIJS PSC1600 driver, from the same CUPS dotpup that works in Grafpup104 and in Puppy 2.02, and it does not print. Jobs go to the queue, then leave there, but the printer doesn't do anything. I don't know if this is because of the pdf thing or not because I haven't used the printer with 2.16 before, but if it isn't then it is very sad, and indicates that having CUPS in 2.17 may not be quite as wonderful as we think... ---EDIT--- My HP works in a fresh install
Last edited by disciple on Wed 18 Jul 2007, 06:26, edited 1 time in total.

User avatar
BarryK
Puppy Master
Posts: 9392
Joined: Mon 09 May 2005, 09:23
Location: Perth, Western Australia
Contact:

#24 Post by BarryK »

JB4x4 wrote:EDIT: I needed to change a couple of lines at the end of the script to read /etc/rc.d/rc.cups instead of /etc/init.d/cups to work with 2.16 properly.
Yes, Puppy 2.17 has the script at /etc/init.d/cups.

disciple
Posts: 6984
Joined: Sun 21 May 2006, 01:46
Location: Auckland, New Zealand

#25 Post by disciple »

Thanks.

Do other people have the same problem when cancelling, or is there something funny about my system?

User avatar
jcoder24
Posts: 604
Joined: Fri 06 May 2005, 12:33
Location: Barbados

#26 Post by jcoder24 »

My apologies as the script was written an tested in 2.17 alpha only.

I've since done some updates and converted the script to a dotpet package.

Updates
1) Added check for location of cups start|stop|restart script (/etc/init.d/cups or /etc/rc.d/rc.cups)
2) Reduced amount of logging to /var/log/messages
3) Removed some code from the original script
4) Added additional comments

This package has been tested on successfully Puppy 2.17 alpha, Puppy 2.16 and Grafpup 2.00. Grafpup 1.04 requires that /usr/lib/cups/backend/pdf-writer be modifed as follows to fix the problem reported by disciple (which only occurs in Grafpup 1.04).

Change

Code: Select all

if [ $# -eq 6 ]; then
        $PS2PDF $6 $FILENAME >& /dev/null
else
        $PS2PDF - $FILENAME >& /dev/null
fi
to

Code: Select all

if [ $# -eq 6 ]; then
        $PS2PDF $6 $FILENAME 
else
        $PS2PDF - $FILENAME 
fi
Updated 2007/07/18, follow link below
http://www.murga-linux.com/puppy/viewto ... 067#129067
Last edited by jcoder24 on Wed 18 Jul 2007, 19:32, edited 1 time in total.

disciple
Posts: 6984
Joined: Sun 21 May 2006, 01:46
Location: Auckland, New Zealand

#27 Post by disciple »

Wow - you are fast. That is very kind of you supporting such obsolete software, and presumably the problem would occur in all (or at least most) Puppy 1.xs
But I had the problem in Puppy 2.16.1 as well - do others not have the problem, or have you fixed it?

disciple
Posts: 6984
Joined: Sun 21 May 2006, 01:46
Location: Auckland, New Zealand

#28 Post by disciple »

You are a legend jcoder:) I fixed the script and reran it in Grafpup 104, and now it works great. Thanks!! :)
Cups seemed to be permanently broken in Puppy 2.16.1, so I started with a fresh save file and installed the .pet and it works great. Thanks. This should definitely be in 2.17

Thoughts/Suggestions:
I have no idea how possible it would be to change, but I think it might be better for a print job to be deleted if you press cancel, than for it to stay in the queue and the printer to go off line. I think the current behaviour would be confusing to most users.
Also, it would be handy to have a printer option to turn off the feature to add a date to prevent overwriting a file - often people want to overwrite a file. I guess we could manually edit the script, but it would be handy to be able to turn it on or off.

disciple
Posts: 6984
Joined: Sun 21 May 2006, 01:46
Location: Auckland, New Zealand

#29 Post by disciple »

This is curious. I have gtklp installed (both my systems), and I don't know if the problems are with CUPS, GTKLP, the PDF printer and/or Seamonkey/Firefox.
To change my paper size I have to change it it the CUPS web interface AND in GTKLP AND I have to restart cups, otherwise it will still print on the old size.
Printing from Firefox or Seamonkey I also have to specify the same size when I go to print it, otherwise it scales to the size specified by the browser, but puts it on the size paper specified by CUPS. How annoying. Why can't the browser dictate the paper size?

Nothing is ever simple. At least I can print to pdf now :)

disciple
Posts: 6984
Joined: Sun 21 May 2006, 01:46
Location: Auckland, New Zealand

#30 Post by disciple »

In case anybody else wants to print to pdf from CUPS from Puppy 1.x, run this and it should work ---EDIT---I can't quite figure out how to modify the script for version 0.2, so run it and then replace /usr/lib/cups/backend/pdf-writer with the attached file (make sure you unzip it)---

#!/bin/sh
#################################################################################
#
# File: pdf-writer
#
# Description: A simple PDF Writer for CUPS
#
# Copyright: (c) 2007 jcoder24 on puppylinux forum
# (c) 2006 Axel Schmidt, SUSE LINUX GmbH, Nuernberg, Germany
# (c) 2001 Michael Goffioul (kdeprint <at> swing <dot> be)
#
# License: GPL
#
#################################################################################

PS2PDF=`which ps2pdf`

# USERMODE="on" changes PDFPATH to "$HOME/<user-name>/PDF"
#
DEFGROUP="users"
JOB=$1
PRTUSER=$2

# Check DEVICE DISCOVERY + test PS2PDF
#
if [ "$JOB" = "" ]; then
if [ -f "$PS2PDF" ]; then
echo "file pdf-writer:/export/share/pdf \"unkown\" \"pdf writer\" "
exit 0
else
echo "Error: $0 - ps2pdf is not available!"
logger "pdf-writer: ERROR: ps2pdf is not available!"
exit 1
fi
fi

logger "pdf-writer started: $1 $2 $3 $4 $5 $6"

# Check number of command line arguments
#
if [ $# -ne 5 -a $# -ne 6 ]; then
echo "Usage: $0 job-id user title copies options [file]"
logger "pdf-writer: CRITICAL: Printer stopped !"
exit 1
fi

# Get pdf filename from user via xdialog
# added by jcoder24
export PATH=$PATH:/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/X11R7/bin
export DISPLAY=":0.0"

#cups sets an env var called USER, which we will access here
#The env variables DISPLAY (above) & XAUTHORITY (below) are needed by xdialog
if [ "$USER" = "root" ]; then
export XAUTHORITY="/root/.Xauthority"
FOLDER="/root"
else
export XAUTHORITY="/home/$USER/.Xauthority"
FOLDER="/home/$USER"
fi

FILENAME=`Xdialog --title "PDF-Writer - Save As..." --fselect "$FOLDER" 28 60 2>&1 | tail -1 | gawk '{gsub (/\.pdf$|\.PDF$/,"",$0); print $0'}`

#if user choses not to save file, exit gracefully
if [ -z "$FILENAME" ]; then
logger "pdf-writer: INFO: JOB $JOB aborted by $USER!"
exit 0
fi

#if selected file exists, append timestamp to filename
if [ -f "$FILENAME.pdf" ]; then
FILENAME="$FILENAME-`date +%m%d-%H%M-%S`.pdf"
else
FILENAME="$FILENAME.pdf"
fi

# get PDF-WRITER directory file selected
# modified by jcoder24
PDFPATH="`dirname $FILENAME`"
#logger "pdf-writer: Created pdf \"$FILENAME\"."

# Check write status
#
if [ ! -d "$PDFPATH" -o ! -w "$PDFPATH" ]; then
logger "pdf-writer: ERROR: directory $PDFPATH not writeable"
exit 1
fi

# Run ps2pdf (ghostscript)
#
if [ $# -eq 6 ]; then
$PS2PDF $6 $FILENAME
else
$PS2PDF - $FILENAME
fi

# Chown + set permissions for the user
# Note: this will not work if CUPS runs as lp
if [ "$PRTUSER" != "" ]; then
chmod 644 $FILENAME
chown $PRTUSER:$DEFGROUP $FILENAME
fi
exit 0

#
######################### CUPS pdf-writer ends here ########################
#

EOF_BACKEND

chmod 755 /usr/lib/cups/backend/pdf-writer
ln -sf /usr/share/ghostscript/8.15/lib/ghostpdf.ppd /usr/share/cups/model/ghostpdf.ppd
/etc/rc.d/rc.cups restart
sleep 5
lpadmin -p CUPS-PDF -v pdf-writer:/export/share/pdf/ -E -P /usr/share/cups/model/ghostpdf.ppd
/etc/rc.d/rc.cups restart
Attachments
pdf-writer.gz
(1.55 KiB) Downloaded 775 times
Last edited by disciple on Thu 19 Jul 2007, 04:45, edited 2 times in total.

User avatar
jcoder24
Posts: 604
Joined: Fri 06 May 2005, 12:33
Location: Barbados

#31 Post by jcoder24 »

disciple wrote:I think it might be better for a print job to be deleted if you press cancel, than for it to stay in the queue and the printer to go off line. I think the current behaviour would be confusing to most users.
This is taken care of by this piece of code.

Code: Select all

#if user choses not to save file, exit gracefully 
if [ -z "$FILENAME" ]; then 
        logger "pdf-writer: INFO: JOB $JOB aborted by $USER!" 
        exit 0 
fi
exit 0 tells cups that everything was completed successfully. During testing, (before I posted the script) I saw the problem and plugged it with that code. However, what I've since noticed is that if you enter a filename and hit enter instead of clicking ok, Xdialog segfaults producing the symptoms you have described. This too may be happening when you hit esc. I've added a check to abort the print if ok/cancel is not clicked.
disciple wrote:Also, it would be handy to have a printer option to turn off the feature to add a date to prevent overwriting a file
I have modifed the printer so that if the file exists it ask you if you want to overwrite with a yes or no option. If the answer no, display they dialog again.
disciple wrote:Printing from Firefox or Seamonkey I also have to specify the same size when I go to print it, otherwise it scales to the size specified by the browser, but puts it on the size paper specified by CUPS. How annoying. Why can't the browser dictate the paper size?
In Seamonkey/Firefox I can change the paper size by clicking the properties button next to the printer name. Unfortunately all programs don't have this option eg geany.

Thanks for all of your testing disciple
Attachments
cupspdf-0.2.pet
(2.1 KiB) Downloaded 927 times

disciple
Posts: 6984
Joined: Sun 21 May 2006, 01:46
Location: Auckland, New Zealand

#32 Post by disciple »

-
Last edited by disciple on Thu 19 Jul 2007, 05:03, edited 1 time in total.

disciple
Posts: 6984
Joined: Sun 21 May 2006, 01:46
Location: Auckland, New Zealand

#33 Post by disciple »

--I'm testing the latest version, in a fresh 2.16.1 frugal install, with just the CUPS dotpup, XPDF and GTKLP installed--

The new overwrite behaviour is suberb. Thanks :)
This is taken care of by this piece of code.
On my system it isn't. If I press cancel when asked where to save it, the job stays in the queue and the printer gets stopped. The same thing happens if I press X to close the window - or do you mean that this code makes it behave like this, rather than preventing it? It would be much more user-friendly if somehow the job could just be deleted and the printer stay online.
Pressing enter instead of clicking OK works fine.

Apart from that it is absolutely great, and I can't get it to break or anything.
The only other enhancement I can think of is to not let a user click OK without putting in a name, but I don't know if this is even possible. At the moment if you are in /root/my-documents, it will make /root/my-documents.pdf, which is a little confusing.

-----------
Just because I like to document everything: If /usr/lib/cups/backend/pdf-writer gets deleted then you get the symptoms I reported before, where jobs will queue, but you never get asked where to save it. If you uninstall the .pet, then this will be deleted, but the printer will still appear to be on the system. (This is not why I initially had the problem, as that was before the .pet :))

-----------
Printing from browsers etc - that's interesting if it works for you - for me the printer properties from Seamonkey/Firefox scale what is printed, but don't actually change the papersize. Changing the page size from Openoffice just prints it at the size set by CUPS. I don't think it has anything to do with the PDF printer, I was just commenting on it. Another funny thing is that when you print from Seamonkey or Firefox, while it is preparing to print it has a window with a cancel button that doesn't actually cancel anything :)

User avatar
jcoder24
Posts: 604
Joined: Fri 06 May 2005, 12:33
Location: Barbados

#34 Post by jcoder24 »

Barry,
lpadmin adds these lines to /etc/cups/printers.conf if its the first printer to be installed.

Code: Select all

<DefaultPrinter CUPS-PDF>
Info CUPS-PDF
DeviceURI pdf-writer:/export/share/pdf/
State Idle
Accepting Yes
Shared Yes
JobSheets none none
QuotaPeriod 0
PageLimit 0
KLimit 0
</Printer>
If not, then the first line becomes

Code: Select all

<Printer CUPS-PDF>
You should be able to just add those lines to /etc/cups/printers.conf to simiulate running lpadmin when creating the live-cd.

User avatar
BarryK
Puppy Master
Posts: 9392
Joined: Mon 09 May 2005, 09:23
Location: Perth, Western Australia
Contact:

#35 Post by BarryK »

jcoder24, thanks for that info, yes, that would be an improvement.
I "froze" 2.17 last night, and won't make any further changes, even one as small as this. The way I did it is less efficient but works, and I have written down your improved method to be implemented for the next Puppy.

Post Reply