# Lexmark Z25 finally working... (supposedly also for Z35)

## tiktak

I finally managed to get my cheap Lexmark Z25 printer running! - more or less (see below).

I am using the binary driver from Lexmark. Not sure if anyone here already did it, but the earlier threads about the topic confused me......

Since it was really complicated, I will present detailed step-by-step instructions on how to easily do it in Gentoo.

### I do NOT recommend buying this printer!! ###

### Lexmark sucks, because they should have released open-source drivers or detailed specs! ###

But it was a gift, and there might be another person whose desk is currently still occupied by a bulky Lexmark paperweight  :Smile: 

btw, these instructions should be fairly accurate for a Z35, too.

(For Z35, check http://www.linuxprinting.org/lexmark-faq.html#s_15  first before believing me blindly :p)

1)  emerge cups ghostview gimp-printing enscript rpm2targz

   I'm not sure whether they are all required (esp. cups and gimp-printing are not used in my preliminary-o-esque solution), but it doesn't hurt.

2)  Install a  usleep program!

  For example, copy&paste the c code in

http://members.lycos.nl/jupp/linux/soft/C/usleep.c.html

   into a new file called usleep.c, and run 

  # gcc -o usleep usleep.c

  # cp usleep /usr/local/bin

3) Get the Lexmark Z35 Linux Drivers (they are for

 Z25 and Z35). Filename should be CJLZ35LE-1.0-1.TAR.GZ

4) mkdir /my/working/dir; cd /my/working/dir

5) tar xvzf /some/path/cjlz35le-1.0-1.tar.gz

  This yields a file called lexmarkz35-1.0-1.gz.sh.

6) edit the .gz.sh with your favourite editor (i suggest gvim)

    and remove some dozen lines at the beginning, up to and

    including the END_OF_STUB line. Save it and rename to

    lexmark.tgz  . Then do a

 # tar xvzf lexmark.tgz

  Tar might complain about the file, ignore it...

7) We are interested in the lexmarkz35-1.0-1.i386.rpm we 

  just extracted! Run

 # rpm2targz lexmarkz35-1.0-1.i386.rpm

 :Cool:  (root access required from this point)

 # cd /

 # tar xvzf /my/working/dir/lexmarkz35-1.0-1.i386.tar.gz

 # chown -R root.lp /usr/local/lexmark

 # chmod -R o-rwx /usr/local/lexmark

 This will install all the driver files etc. in  /usr/local/lexmark/z25-z35

9a)

 # mkdir /var/spool/lexmark/Z35Driver/

 # cd /my/working/dir

 # touch /etc/printcap     (z35install will fail otherwise!!)

 # ./z35install

 The z35install will put default configs in /var/spool/lexmark/Z35Driver .

 If you selected Country: US, there will be an (invalid) link "auckUS.lut"

 there, if you selected a European country (A4 is way better than US letter format :p)

 the link will be called auckEU.lut.  (see 10) )

9b)

 # touch /var/spool/lexmark/Z35Driver/lpd.log

 # mkfifo /var/spool/lexmark/Z35Driver/input_pipe

 # chown -R root.lp /var/spool/lexmark

 # chmod -R o-rwx /var/spool/lexmark

 # chmod -R g+w /var/spool/lexmark

10)

 # cd /var/spool/lexmark/Z35Driver

 # ln -s /usr/local/lexmark/z25-z35/layout/auckUS.lut   (or auckEU.lut, respectively)

11) in /etc/printcap, change the (two)

    :if=/usr/bin/LexmarkZ35:

  lines to

    :if=/usr/local/lexmark/z25-z35/scripts/LexmarkZ35:

12) Now here comes the tricky part  :Smile: 

   The developers of the driver created a printing script, 

  /usr/local/lexmark/z25-z35/scripts/LexmarkZ35

  This script is a heap of junk because it didnt work too well for me!

  Here are the neccessary modifications. Fire up an editor (like gvim  :Very Happy: ) on the file.

  Now check the "image_conversion()" function. Some errors there (the rest of the script is ok):

    - Change all the "-r$2" parameters you find in this function to "-r$LXRESOLUTION"

    - Change all the "-g$3" parameters you find in this function to "-g$LXDIMENSION"

    - The file type to print is detected using the "file" utility. Unfortunately, they

       parse the output, which has changed..... so if you want to print Postscipt

       files ( .PS )  (which you most certainly will), make another modification:

       Change the

           "postscript* | pdf* )"       line to

           "hp* |postscript* | pdf* ) "

13) Put your user in the lp group and re-login. Now,

  # cd $HOME

  # ln -s /var/spool/lexmark/Z35Driver .lexmark

  This is important. Only root can print without creating the link in his or her home dir.

14) Congratulations! If I didn't forget anything, and didn't make too big a mistake in this post,  you can now more or less print! :p

 You cannot directly use lpr, cups or some other nifty multi-user printing utility, tho. (I have never looked into these, being more of the hardware-ish type  :Smile: 

 -- ****** If you find out how to set it up properly - could be easy enough -, reply in this thread!!! ********* )

15) Might be a good idea to

 # cd /usr/local/bin

 # ln -s /usr/local/lexmark/z25-z35/scripts/LexmarkZ35

---------------------

 To print, just use:

  # cat my_document.ps | LexmarkZ35 -

  # cat my_document.txt | LexmarkZ35 -

 and so on (simple use the script as a filter!!). Postscript works best. Color works 100%. There are printer analysis tools somewhere in /usr/local/lexmark - for ink status display etc...

You might also want to have a look at the /var/spool/lexmark/Z35Driver/Z35Driver.conf file to adjust quality settings etc...

  w00t !!

btw, The actual printer driver accepts ppmraw as an input format, so if you want to add a supported document type, extend the LexmarkZ35 script. Have a (document-type)->ppm converter ready  :Smile: 

Partially based on the Lexmark FAQ. http://www.linuxprinting.org/lexmark-faq.html#s_11

- which was not very accurate but slightly helpful. Not too compatible with a (recent) Gentoo installation, tho...  :Wink: 

Have fun!

 tiktak

----------

## Cicero

Wow, that's actually easier than getting their crappy windows drivers to work.    :Razz: 

----------

## TheMasterRat

Doesn't seem to work for me   :Sad: 

It launches the script. Doesn't error out or anything. 

Just sits there. ( both for root and users )

/dev/usb/lp* is present ( about 15 of em actually )

But still no worky.

Thanks for the attempt though   :Very Happy: 

-edit-

There is one thing different..  I couldn't compile that code. GCC3 didn't like it... hmm...

-edit#2-

nope. got the program to compile. still fails to print!

----------

## tiktak

Any error messages? Did a lexmark-error process get spawned (i think that was the correct name). Did you install the fifo using the mkfifo line? Are the auckUS.lut links ok? Is there a valid /var/spool/lexmark/Z35Driver/Z35Driver.conf file with appropriate config data inside?

Is your printer actually listed in the output of "lsusb"? The fact that there are 15 /dev/usb/lp* devices might suggest a problem. I've only got 1 device,  /dev/usb/lp0, when I plug in the printer...

(You do have a Z25 and not a Z35 right? As a Z35 user, visit the link I posted first to check for printer-specific differences during basic setup...)

1) ####### Put debug messages into the script to see where exactly it stalls!!!!!  #######

2) emerge strace and run:   strace -f -e trace=open,ioctl <your-print-commandline> 2>debug.txt

and check the resulting debug.txt to look for error messages.

Note: sometimes, the printing stalls for a while before continuing. Doesn't take longer than like 10 seconds tho, so I assume there is an error somewhere in your installation. And I just might have forgotten to post some important detail .....  :Sad: 

Tell me more, I'm motivated to help you fellow Lexmark victims  :Smile: 

----------

## TheMasterRat

The script did not report any error messages.

I used the mkfifo and doublechecked the links.

Not sure ( and can't verify right now ) if there is a Z35Driver.conf in /var/spool. ( I know there was one, I remember editing it )

I'll check lsusb when I get home as well.

And yes, it actually is a Z35... I'll look through that article ( seen it once before) to see if there are any differences. ( I don't think there are.. )

And I'll try the strace as well. 

  I should note, that before going through this process, there *was* only one /dev/usb/lp0 , instead of 15 that I have now.

----------

## TheMasterRat

Here's the results from an strace :

open("/etc/ld.so.preload", O_RDONLY)    = -1 ENOENT (No such file or directory)

open("/etc/ld.so.cache", O_RDONLY)      = 3

open("/lib/libdl.so.2", O_RDONLY)       = 3

open("/lib/libc.so.6", O_RDONLY)        = 3

open("/dev/tty", O_RDWR|O_NONBLOCK|O_LARGEFILE) = 3

open("/etc/mtab", O_RDONLY)             = 3

open("/proc/meminfo", O_RDONLY)         = 3

open("/usr/local/bin/LexmarkZ35", O_RDONLY|O_LARGEFILE) = 3

ioctl(3, SNDCTL_TMR_TIMEBASE, 0xbffff5a0) = -1 ENOTTY (Inappropriate ioctl for device)

Process 16470 attached

[pid 16470] open("/etc/ld.so.preload", O_RDONLY) = -1 ENOENT (No such file or directory)

[pid 16470] open("/etc/ld.so.cache", O_RDONLY) = 3

[pid 16470] open("/usr/lib/libstdc++-libc6.1-2.so.3", O_RDONLY) = 3

[pid 16470] open("/lib/libm.so.6", O_RDONLY) = 3

[pid 16470] open("/lib/libc.so.6", O_RDONLY) = 3

[pid 16470] open("VERIFY", O_RDONLY)    = -1 ENOENT (No such file or directory)

[pid 16470] open("/etc/nsswitch.conf", O_RDONLY) = 3

[pid 16470] open("/etc/ld.so.cache", O_RDONLY) = 3

[pid 16470] open("/lib/libnss_compat.so.2", O_RDONLY) = 3

[pid 16470] open("/lib/libnsl.so.1", O_RDONLY) = 3

[pid 16470] open("/etc/passwd", O_RDONLY) = 3

Process 16470 detached

--- SIGCHLD (Child exited) @ 0 (0) ---

Process 16471 attached

[pid 16471] open("/etc/ld.so.preload", O_RDONLY) = -1 ENOENT (No such file or directory)

[pid 16471] open("/etc/ld.so.cache", O_RDONLY) = 3

[pid 16471] open("/lib/libc.so.6", O_RDONLY) = 3

[pid 16471] open("/tmp/lexmark.aRwUe9", O_RDWR|O_CREAT|O_EXCL, 0600) = 3

Process 16471 detached

--- SIGCHLD (Child exited) @ 0 (0) ---

Process 16472 attached

[pid 16472] open("/tmp/lexmark.aRwUe9", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE, 0666) = 3

[pid 16472] open("/etc/ld.so.preload", O_RDONLY) = -1 ENOENT (No such file or directory)

[pid 16472] open("/etc/ld.so.cache", O_RDONLY) = 3

[pid 16472] open("/lib/libc.so.6", O_RDONLY) = 3

Process 16469 suspended

Process 16469 resumed

Process 16472 detached

Seems to be failing on ld.so.preload... ( which, does *not* exist ).

Ideas?

----------

## tiktak

No that should not be problematic... ld.preload is not required... did you specify "-f" in the strace options? Because strace did not trace the child processes...

----------

## tiktak

Oh oh.... sorry my fault!!!!

Don't print using:   LexmarkZ35 <your-file>

Use it as a filter! Sorry, it was late, and I overgeneralized. The Lexmark guys are a bit stupid though!

If you type:

 #  cat <your-file.ps> | LexmarkZ35 - 

it should work just fine! The minus at the end should indicate "read from stdin" - but as i said the guys were not too smart - the parameter is ignored in the script and it works from stdin no matter what the parameter is. I didn't recognize the problem because i typed "LexmarkZ35" as printer command in MozillaFirebird, ignoring the fact that the browser uses that command as a filter  :Smile:  Stupid me  :Wink: 

P.S. I'll edit my original post and correct the mistake!

----------

## tiktak

OK. To solve that LexmarkZ35 dilemma once and for all, here is my modified version

Thanks to my testing, my black cartridge is now empty. Lexmark ink is expensive, might as well get a good printer now  :Very Happy:   :Very Happy: 

Modifications from original Lexmark version as follows:

 * can now print files directly:  LexmarkZ35 <file>

 * works as a filter when you type  - (minus) or nothing as a filename

 * Correctly detects Postscript files

 * Uses the resolution and geometry data directly from the Config file

Tell me when there are still problems,

Cheers,

 tiktak

```

#!/bin/sh

#

# tiktak's Fundamentally Improved Lexmark Filter Script...

#

PDIR=/usr/local/lexmark/z25-z35

CONFDIR=`$PDIR/bin/lxgetconf VERIFY`

INPUT_PIPE=/var/spool/lexmark/Z35Driver/input_pipe

CONFFILE=Z35Driver.conf

export LXTMPFILE=`mktemp /tmp/lexmark.XXXXXX`

USE_STDIN=FALSE

[ %$#% == %0% ] && USE_STDIN=TRUE

[ %$1% == %-% ] && USE_STDIN=TRUE

[ %$USE_STDIN% == %TRUE% ] && cat > $LXTMPFILE || cp $1 $LXTMPFILE

magic=$(file $LXTMPFILE)

magic=${magic#*: }

LXORIENT=`$PDIR/bin/lxgetconf $CONFDIR/$CONFFILE "current settings" "orientation"`

LXMEDIA_SIZE=`$PDIR/bin/lxgetconf $CONFDIR/$CONFFILE "current settings" "media_size"`

LXMEDIA_TYPE=`$PDIR/bin/lxgetconf $CONFDIR/$CONFFILE "current settings" "media_type"`

LXCOPIES=`$PDIR/bin/lxgetconf $CONFDIR/$CONFFILE "current settings" "copies_number"`

LXQUALITY=`$PDIR/bin/lxgetconf $CONFDIR/$CONFFILE "current settings" "quality_speed"`

LXPAPER_WIDTH=`$PDIR/bin/lxgetconf $CONFDIR/$CONFFILE "paper width" "$LXMEDIA_SIZE"`

LXPAPER_HEIGHT=`$PDIR/bin/lxgetconf $CONFDIR/$CONFFILE "paper height" "$LXMEDIA_SIZE"`

LXBIDIFLAG=`$PDIR/bin/lxgetconf $CONFDIR/$CONFFILE "settings" "bidi"`

LXCUSTOM_WIDTH=`$PDIR/bin/lxgetconf $CONFDIR/$CONFFILE "custom paper size" "width"`

LXCUSTOM_HEIGHT=`$PDIR/bin/lxgetconf $CONFDIR/$CONFFILE "custom paper size" "height"`

LXCUSTOM_UNITS=`$PDIR/bin/lxgetconf $CONFDIR/$CONFFILE "custom paper size" "units"`

if [ "$LXMEDIA_SIZE" = "Custom" ]

then

   LXPAPER_WIDTH=`$PDIR/bin/lxgetconf CONVERT "$LXQUALITY" "$LXCUSTOM_UNITS" "$LXCUSTOM_WIDTH"`

    LXPAPER_HEIGHT=`$PDIR/bin/lxgetconf CONVERT "$LXQUALITY" "$LXCUSTOM_UNITS" "$LXCUSTOM_HEIGHT"`

fi

if [ "$LXQUALITY" = "Quick Print" ]

then

   LXPRINTRES=300

else

   LXPRINTRES=600

   LXPAPER_WIDTH=`expr $LXPAPER_WIDTH \* 2`

   LXPAPER_HEIGHT=`expr $LXPAPER_HEIGHT \* 2`

fi

LXRESOLUTION=$LXPRINTRES\x$LXPRINTRES

LXDIMENSION=$LXPAPER_WIDTH\x$LXPAPER_HEIGHT

if [ "$LXORIENT" = "Landscape" ]

then

   ENSORIENT="-r"

else

   ENSORIENT="-R"

fi

image_conversion ()

{

   echo $magic

   case `echo $magic | tr 'A-Z' 'a-z'` in

       "pc bitmap data"* )

          bmptoppm $1 > $INPUT_PIPE ;;

       "gif image data"* )

          giftopnm $1 > $INPUT_PIPE ;;

       "jpeg image data"* )

           djpeg -pnm $1 > $INPUT_PIPE ;;

       "tiff image data"* )

          tiff2ps -a $1 | gs -q -dNOPAUSE -r$LXRESOLUTION -g$LXDIMENSION -sDEVICE=ppmraw -dBATCH -sOutputFile=- - > $INPUT_PIPE  ;;

       "pgm"*|"pbm"*|"ppm"*|"netpbm"* )

          cat $1 > $INPUT_PIPE ;;

       hp* |postscript* | pdf* )

      if [ "$LXMEDIA_SIZE" = "Custom" ]

      then

            echo "ps custom"

              gs -sDEVICE=ppmraw -q -dNOPAUSE -dBATCH -r$LXRESOLUTION -g$LXDIMENSION -sOutputFile=- $1 > $INPUT_PIPE 

      else   

            echo "ps standard"

              gs -sDEVICE=ppmraw -q -dNOPAUSE -dBATCH -r$LXRESOLUTION -g$LXDIMENSION -sOutputFile=- $1 > $INPUT_PIPE 

            # -g$3

      fi   ;;

       *ascii*|*text*|*english*|*script* )

      if [ "$LXORIENT" = "Landscape" ]

      then

         cat $1 | enscript -B $ENSORIENT -o - | gs -q -dNOPAUSE -r$LXRESOLUTION -g$LXDIMENSION -sDEVICE=ppmraw -dBATCH -sOutputFile=- - > $INPUT_PIPE 

      else

         cat $1 | enscript -B $ENSORIENT -o - | gs -q -dNOPAUSE -r$LXRESOLUTION -g$LXDIMENSION -sDEVICE=ppmraw -dBATCH -sOutputFile=- - > $INPUT_PIPE  

      fi   ;;

   esac

}

if [ "$LXCOPIES" -gt "1" ]

then

   COPY_COUNT=0

   while [ "$COPY_COUNT" -lt "$LXCOPIES" ];

   do

      LEXPID=`/sbin/pidof -s Z35Driver`

      if [ "$LEXPID" != "" ]

      then

         sleep 12 

      fi

      $PDIR/Z35Driver $LXBIDIFLAG &

      image_conversion $LXTMPFILE "$LXRESOLUTION" "$LXDIMENSION"

      if [ "$?" != "0" ]

      then

         let COPY_COUNT=100

      fi

      let COPY_COUNT=`expr $COPY_COUNT + 1`

   done

   /bin/rm -f $LXTMPFILE

else

   LEXPID=`/sbin/pidof -s Z35Driver`

   if [ "$LEXPID" != "" ]

   then

      sleep 12

   fi

   $PDIR/Z35Driver $LXBIDIFLAG &

   image_conversion $LXTMPFILE "$LXRESOLUTION" "$LXDIMENSION"

     /bin/rm -f $LXTMPFILE

fi

LEXPID=`/sbin/pidof -s Z35Driver`

while [ "$LEXPID" != "" ]

do

   usleep 1000

   LEXPID=`/sbin/pidof -s Z35Driver`

done

exit 3

 
```

----------

## TheMasterRat

Well, I just got done removing all the things done throughout the install.

I will try again later.

Just out of curiousity, do you know how to apply the patch from http://www.linuxprinting.org/lexmark-faq.html#s_15 ? As i'm guessing  I *might* need to?

----------

## tiktak

Hmmm... from quickly reading the patch file, I don't think that you really need it (besides, there are encoding errors in the script text...).

***Try using my version instead, and don't worry about the patch.*** If there is any page you print that doesnt come out in a sensible size or resolution or something, you can always fall back on the script patch posted in the FAQ. You'll want to look up "man patch" then (basically, "patch -p0 <my_patch_file").

----------

## TheMasterRat

Nothing seems to work.. I think I'll ditch it at work for 30-40$ and pick up an HP DJ5650 or something.

----------

## tiktak

Yeah, I said it before... my black cartridge is empty now... EUR18 for a new one. Color is almost empty too... I might as well get a cheap Linux-ready printer off eBay for just a bit more.

*** But, for all future readers of this thread: my Lexmark Z25 did in fact work 100% under Gentoo Linux. Follow the instructions I gave in the first post, and replace the original LexmarkZ35 script by the one posted above. That worked for me. ***

----------

## xraver

 *Quote:*   

> 
> 
> 2) Install a usleep program!
> 
> For example, copy&paste the c code in
> ...

 

I have do this, but error.

```

$ gcc -o usleep usleep.c

usleep.c: In function `main':

usleep.c:55: `errno' undeclared (first use in this function)

usleep.c:55: (Each undeclared identifier is reported only once

usleep.c:55: for each function it appears in.)

usleep.c:55: `ERANGE' undeclared (first use in this function)

```

Some Ideas?

----------

## sandcrawler

Now only if I could print these directions!!!!!! DOH!!

----------

## tiktak

 *xraver wrote:*   

>  *Quote:*   
> 
> 2) Install a usleep program!
> 
> For example, copy&paste the c code in
> ...

 

Yes. Although it used to work. They have updated the

page and now the program is broken.

Just add a 

   #include <errno.h>

after the other #include lines.

Good luck &&  Cheers

  tiktak

----------

## Lateralus

I've went through all of the steps, and encountered no problems, however:

when I'm not root, the following occurs:

```

bash-2.05b$ LexmarkZ35 Harry.txt

ASCII English text, with very long lines

open: Permission denied

```

and when I'm root, this happens:

```

bash-2.05b# /usr/local/bin/LexmarkZ35 /home/lateralus/Harry.txt 

ASCII English text, with very long lines

[ 1 pages * 1 copy ] left in -

8 lines were wrapped

/usr/local/bin/LexmarkZ35: line 118: 12761 Done                    cat $1

     12762                       | enscript -B $ENSORIENT -o -

     12763 Broken pipe             | gs -q -dNOPAUSE -r$LXRESOLUTION -g$LXDIMENSION -sDEVICE=ppmraw -dBATCH -sOutputFile=- - >$INPUT_PIPE

bash-2.05b# 

```

in both cases nothing was printed.

----------

## CdWhistler

Wow, that is way to much work if you only want printing through cups to work. I do agree that lexmark is not a first choice printer to get, but mine was a gift too. 

Check out my guide: [url]https://forums.gentoo.org/viewtopic.php?t=118732[url]

----------

