Install a printer on an embedded Linux system __linux

Source: Internet
Author: User
Tags openssl strcmp

1. Introduction:
Install printers in Linux environments, usually cups, ghostscript, etc., but usually large in size, several 10 trillion
In my application environment, the requirements of the printing module is not more than 5M, the web search program is to cups part of the extraction,
namely Imagetoraster, RASTERTOHP, Rastertoepson. After streamlining, I finally merged the latter two,
Remove other picture format support, only retain BMP, and static compilation, generate two files Imagetoraster, Rastertoany,
Total 1M, and tested successfully on HP-1010. Because my task is relatively simple, I do not consider the issue of print task management.
Because Hp-deskjet needs Ijs drive, this method fails, with Ghostscript test success, but relatively large, 15M or so,
So it's not introduced here.

2. Printing process
Export PPD=/SA_USER_DATA/UP/LASERJET.PPD
/root/imagetoraster "" "1" "/root/1.bmp" | /root/rastertoany HP 10 "" "1" "| Cat >/dev/usb/lp0

To execute the above statement, you can print 1.bmp to my printer HP-1010 USB laser printer, where
LASERJET.PPD printer driver, can be downloaded from the linuxprinting.org, not necessarily 1010, perhaps universal can be, such as I have here
General driver for HP lasers
Imagetoraster is responsible for converting the picture to raster data
Rastertoany is responsible for converting raster data to printer-aware data
The cat is responsible for outputting the printed data to the printer, and if there is no equipment, build a master device 180, from the lp0 of unit number 0

The following parameters are Imagetoraster, respectively
1:job_id
2:user
3:title
4:copies
5:num_options
6:filename
The first few are useless, just press what I write.
Rastertoepson The first parameter is HP or Epson, indicating which printer to use, followed by the same parameter as Imagetoraster

3. Cups cutting
Platform Linux-2.4 + gcc3.2.2 + cups-1.1.23

3.1 Compile options, the need is static compilation, and to remove the useless, you can write a script:
./configure--prefix=/root/mycupsinstall/
Ldflags=--static/
--enable-static/
--disable-shared/
--disable-debug/
--disable-mallinfo/
--DISABLE-SLP/
--disable-ssl/
--disable-openssl/
--DISABLE-GNUTLS/
--disable-cdsassl/
--disable-pam/
--without-cups-user/
--without-cup-group/
--without-fontpath/
--without-docdir/
--without-rcdir/
--without-openslp-libs/
--without-openslp-includes/
--without-openssl-libs/
--without-openssl-includes/
--without-java/
--without-perl/
--without-php/
--without-python

To see all the options,./configure--help after the execution will generate the corresponding makefile, first do not hurry make,
First modify the cups directory config.h #define HAVE_LIBZ 1, and then start to modify the source code

3.2 Delete Print information
By default, when you print out a bunch of information, such as the size of the detected picture, I remove him.
Will filter under the file Common.c, RASTERTOHP, RASTERTOEPSON.C, image.c imagetoraster.c, image-bmp.c
There are stderr in the place.
3.3 Remove other picture formats, only BMP
Delete filter/image.c in the Imageopen function, file open part, except BMP things are deleted, only keep
if (header, "BM", 2) = 0) memcmp
Status = Imagereadbmp (IMG, FP, primary, secondary, saturation, hue, lut);
Else
{
Fclose (FP);
status =-1;
}

Modify Filter/makefile
Delete image-gif.o image-jpeg.o image-photocd.o image-pix.o image-png.o image-pnm.o in IMAGEOBJS =
IMAGE-SGI.O IMAGE-SGILIB.O IMAGE-SUN.O IMAGE-TIFF.O/

3.4 Combined RASTERTOHP Rastertoepson
These two files open look similar, because it is static compilation, if written in two files, each occupies 400K, after the merger of about 400K.
The idea of merging is as follows:
Rename the main function of RASTERTOHP and rastertoepson to a normal function
Create a rastertoany.c, which has only the main function, which calls RASTERTOHP or Toepson based on the input parameters
FILTER/RASTERTOANY.C:
#include <string.h>
extern int RASTERTOHP (int argc, char *argv[]);
extern int Rastertoepson (int argc, char *argv[]);

int main (int argc, char *argv[])
{
if (strcmp (argv[1], "hp") = = 0)
Return RASTERTOHP (Argc-1, &argv[1]);
else if (strcmp (argv[1], "epson") = = 0)
Return Rastertoepson (Argc-1, &argv[1]);
Else
return 0;
}
Filter/rastertohp.c
Rename the main function rastertohp
Rename the following functions with the purpose of Rastertoepson these functions with the same name, the same project cannot have two identical functions
Setup--> setuphp
StartPage--> STARTPAGEHP
EndPage--> ENDPAGEHP
Shutdown--> SHUTDOWNHP
Canceljob--> canceljobhp
Compressdata--> COMPRESSDATAHP
Outputline--> OUTPUTLINEHP

Filter/rastertoepson.c
Rename the main function Rastertoepson
Since RASTERTOHP has changed its name, here is the place to change.

Filter/makefile
FILTERS = Add Rastertoany, delete rastertohp Rastertoepson
OBJS = Increase RASTERTOANY.O
Add an output file, imitate RASTERTOHP
RASTERTOANY:RASTERTOANY.O RASTERTOHP.O RASTERTOEPSON.O. /makedefs.. /cups/$ (libcups) $ (libcupsimage)
echo Linking $@ ...
$ (CC) $ (ldflags)-O $@ rastertoany rastertohp.o rastertoepson.o $ (linkcupsimage) $ (imglibs) $ (LIBS)

3.5
Compile, make it in the cups directory,

4. Conclusion
  This method can solve some of the printer in the Linux simple printing problem, I only verified the HP-1010, printing effect to meet the requirements, test HP DeskJet 3420 failure. Modified source code, will be uploaded to Csdn resources in the future.
  Resources:
      www.linuxprinting.org                find PPD-driven
      www.cups.org                          bbs very good
      Google + embedded Linux + print + B-,  This is the birthplace of this article ideas
& nbsp;    http://www.gccgle.com/book/samba/CUPS-printing.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.