RE: printer question follow up

new topic     » topic index » view thread      » older message » newer message

> Is it possible to print to a printer in a non
> graphics/bitmap way..... Like a non windows
> OS  does?  --george
 
Here is an example in C. It could be translated into E for exw.

// lhp.c   --link with winspool.lib

#include <stdio.h>
#include <string.h>
#include <windows.h>
#include <winspool.h>

char msg1[] = "usage:  lhp file1 file2 ..";
char prname[] = "\\\\kenneth\\hp";
char set[] = "\033E\033(s12H\033&l6d6e54F\033&a9l90M\033&k2G";
// EscE      --reset
// Esc(s12H  --12 cpi
// Esc&l6D   --6 lpi
// Esc&l6E   --6 line top mrgn
// Esc&l54F  --54 lines per page
// Esc&a9L   --col 9 end left mrgn
// Esc&a90M  --col 90 begin right mrgn
// Esc&k2G   --lf=cr+lf, ff=cr+ff

void list(FILE *p1, FILE *f1);

int main(int argc, char **argv)
  {
  FILE *f1, *p1;
  DOC_INFO_1 di;
  if(argc<2) { printf("%s\n",msg1); return 0; }
  while(--argc)
    {
    printf(*++argv);
    f1=fopen(*argv,"rb");
    if(f1)
      {
      OpenPrinter(prname,&p1,NULL);
      di.pDocName=*argv;
      di.pOutputFile=NULL;
      di.pDatatype="RAW";
      if(StartDocPrinter(p1,1,&di) > 0)
        {
        StartPagePrinter(p1);
        list(p1,f1);
        printf(" is queued on %s\n",prname);
        EndPagePrinter(p1);
        EndDocPrinter(p1);
        }
      else printf("\ncan't open %s\n",prname);
      ClosePrinter(p1);
      fclose(f1);
      }
    else printf(" not found\n");
    }
  return 0;
  }

void list (FILE *p1, FILE *f1)
  {
  DWORD nr, nw;
  char buf[129], last='\0';
  WritePrinter(p1,set,strlen(set),&nw);
  do
    {
    nr=fread(buf,1,128,f1);
    if(nr==0) break;
    buf[nr]='\0';
    WritePrinter(p1,buf,nr,&nw);
    last=buf[nr-1];
    } while(nr==128);
  if(last!='\f') WritePrinter(p1,"\f",2,&nw);
  }

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu