Re: Bar Code Printing With 4GL
Posted in 1998
In article <3538342b.214091170@nntp.cts.com>, <dwolt@cts.com> wrote: >I have a project in which my client would like the post office bar >code printed on a customer's statement. Has anyone had success with >performing this task? > >I am using 4GL and standard HP laser printers. Any information or >guidance will be appreciated! > >Thanks >Dave > >-------------------------------------- >Dave I found this in my archive. Never used it. There is info on barcodes in Informix archive. /* barcode.c This is a program to produce postal barcodes on an HPLJ. It was printed in the Winter '90 issue of the C Gazette (a fine publication). For a complete technical description, see that issue of the magazine. This code could probable be easily adapted to almost any mailing list manager, as it accepts the zip code digits in ASCII and outputs the required HPLJ graphics commands to product a properly formatted postal bar code. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Todd Merriman - Software Toolz, Inc. * Maintainer * * 8030 Pooles Mill Dr., Ball Ground, GA 30107-9610 * of the * * UUCP: ...!emory!slammer!toolz!todd * Software * * Internet: todd%toolz.uucp@mathcs.emory.edu * Entrepreneur's * * V-mail (800) 869-3878, (404) 889-8264 * mailing list * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include <stdio.h> #include <stdlib.h> #include <string.h> #define LONG '1' #define SHORT '0' #define ESC 0x1B #define FORMFEED 0x0C FILE *prt; void print_bar(char); void print_bar_code(char*); void print_digit_barcode(char *); void print_bar_code(char *zip) { static char *pattern [10] = { "11000", /* 0 */ "00011", /* 1 */ "00101", /* 2 */ "00110", /* 3 */ "01001", /* 4 */ "01010", /* 5 */ "01100", /* 6 */ "10001", /* 7 */ "10010", /* 8 */ "10100" /* 9 */ }; char *p; int i,j,len,sum; i = sum = 0; len = strlen(zip); if (len != 5 && len != 10) { fprintf(stderr,"zip %s must be 5 or 10 characters\\n",zip); exit(1); } while (*zip) { if (*zip == '-') /* skip the dash in ZIP+4 */ { zip += 1; continue; } /* since zip is going to be converted into an index to pattern, we must make sure it contains the data we expect, namely digits */ if (!(isdigit(*zip))) { fputs("Zip code error",prt); exit(1); } j = *zip - '0'; /* convert to value */ if (i == 0) /* no digits done yet? */ print_bar(LONG); p = pattern[j]; /* point p at the pattern */ print_digit_barcode(p); /* output it */ i += 1; /* count digits processed */ sum += j; /* sum of zip code digits */ zip += 1; /* look at next digit */ } sum %= 10; /* remainder of sum/10 */ p = pattern [10-sum]; /* check digit = 10 - sum */ print_digit_barcode(p); print_bar(LONG); /* closing bar */ } void print_digit_barcode(char *p) { while (*p) { print_bar(*p); p += 1; } } void print_bar(char size) { if (size == SHORT) fprintf(prt,"%c*p+21Y",ESC); /* bar width is .015 - .025 inch */ /* 6 dots = .020 inch */ fprintf(prt,"%c*c%dA",ESC,6); /* bar height is: LONG: .115 - .135 inchd or 35 -41 dots SHORT: .040 - .060 inch or 14-20 dots we use: LONG 38 dots, SHORT 17 dots */ fprintf(prt,"%c*c%dB",ESC, (size == SHORT ? 17 :38)); /* specify print as black */ fprintf(prt,"%c*c0P",ESC); /* horizontal spacing from start of on bar to start of next bar is .045 - .050 inch, or 14 - 15 dots. We'lluse a relative move of 15 dots. */ fprintf(prt,"%c*p+15X",ESC); if (size == SHORT) fprintf(prt,"%c*p-21Y",ESC); } main(int argc,char *argv[]) { if (argc < 2) { fputs("Usage: BARCODE zipcode",stderr); exit(1); } prt = stdprn; fprintf(prt,"\\n\\r\\tBarcode for %s is: ",argv[1]); print_bar_code(argv[1]); fprintf(prt,"%c",FORMFEED); exit(0); } -- Michael J. Kuhn Computer Systems Consultant phone:410-254-7060 Email: mkuhn@csd.clark.net, csd@clark.net mkuhn@rhlab.com c/o Baltimore Rh Typing Laboratory, Inc. phone:410-225-9595