* Re: DU4.0B via NT lpd to HP Laser 4
1997-09-10 4:00 DU4.0B via NT lpd to HP Laser 4 Graham Jones
@ 1997-09-29 4:00 ` Ronald Speth
0 siblings, 0 replies; 2+ messages in thread
From: Ronald Speth @ 1997-09-29 4:00 UTC (permalink / raw)
To: Graham Jones
I don't know how to go through the NT box but I do know how to go direct to
the printer. You must write your own print filter. Then incorportate in that
filter the options you need portrait, landscape, font, paper tray, etc.
Here is a start:
Printers have entries in hosts file and Ip addresses.
Printcap file:
lp0|0|cis:\ Portrait queue
:if=/usr/lbin/hpfilter -Hcis:\
:lf=/usr/adm/lp0err:\
:lp=/dev/null:\
:sd=/usr/spool/lp0:
# landscape definition for HP4 in computer room
lp1|1|cis_land:\ Landscape queue
:if=/usr/lbin/hpfilter -Hcis -L:\
:lf=/usr/adm/lp1err:\
:lp=/dev/null:\
:sd=/usr/spool/lp1:
C code:
/*
This code was created to print to print to HP jet direct cards.
HP cards communicate on port number 9100.
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/errno.h>
#include <netinet/in.h>
#include <netdb.h>
#include <string.h>
#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
#include <fcntl.h>
#include <xti.h>
/* Jet direct server port is 9100 */
#define SERVER_PORT 9100
main(int argc, char *argv[])
{
int sockfd;
struct sockaddr_in serveraddr;
struct hostent *he;
int n;
int i;
char serverhost[30];
struct hostent *serverhostp;
char buffer[1024];
char inbuf[1024];
FILE *f;
int c;
int landscape;
int legal;
int stopflag;
int last_char;
int sleep_time;
landscape = 0;
legal = 0;
stopflag = 1;
sleep_time = 5;
for(i = 1; i < argc; i++)
{
if (argv[i][0] == '-')
{
switch (argv[i][1])
{
case 'H':
strcpy(serverhost, argv[i]+2);
break;
case 'L':
landscape = 1;
break;
case 'G':
legal = 1;
break;
}
}
}
while(stopflag)
{
/* Create a socket for the communications */
if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
{
perror("socket_create");
exit(1);
}
bzero((char *) &serveraddr, sizeof(struct sockaddr_in));
serveraddr.sin_family = AF_INET;
if ((serverhostp = gethostbyname(serverhost)) == (struct hostent *)NULL)
{
fprintf(stderr,"gethostbyname on %s failed\n", serverhost);
exit(1);
}
bcopy(serverhostp->h_addr, (char *)&(serveraddr.sin_addr.s_addr),
serverhostp->h_length);
serveraddr.sin_port = htons(SERVER_PORT);
/* Now connect to the server */
if (connect(sockfd, &serveraddr, sizeof(serveraddr)) < 0)
{
perror ("connect");
sleep(sleep_time);
sleep_time = sleep_time + 5;
if (sleep_time > 300)
sleep_time = 300;
}
else
stopflag = 0;
}
f = fdopen(sockfd, "w");
if (f == NULL)
{
perror("fdopen()");
exit(1);
}
fprintf(f, "\033E");
if(legal)
fprintf(f, "\033&l3A");
if (landscape)
{
fprintf(f, "\033&l1O");
fprintf(f, "\033&l8D");
fprintf(f, "\033(8U\033(s0p19.50h0s3b4102T");
}
else
fprintf(f, "\033(8U\033(s0p16.67h8.5v0s0b0T");
c = getchar();
if(c != '\f')
putc(c, f);
last_char = c;
while(!feof(stdin))
{
c = getchar();
if (c == '\n')
putc('\r',f);
if(last_char == '\f')
{
if(c != '\f')
putc(c, f);
}
else
putc(c, f);
last_char = c;
}
}
This code does not do any accounting and does not use many of the flags that
LPD can pass to it but it works great for us. You can modify it any way you
need.
Graham Jones wrote:
> Does anyone know the best way to print from a Digital Unix 4.0B box via an
> NT lpd server to a network attached HP Laser Jet 4.
>
> It doesn't sound difficult I know. We're able to print plain text to these
> printers OK, but can't get the formatting perfect. We need to be able to
> select pitch, landscape or portrait mode, weight etc.
>
> As I understand it, input, output and transfer filters are only used for
> directly attached printers. How can we make use of these options on a
> networked printer.
>
> Any help would be gratefully received. (Please e' me as well as posting)
>
> Regards
> Graham Jones
>
> graham@xliteyear.demon.co.uk
>
> Remove 'x' for reply
^ permalink raw reply [flat|nested] 2+ messages in thread