home *** CD-ROM | disk | FTP | other *** search
/ Point Programming 1 / PPROG1.ISO / pascal / swag / printing.swg / 0001_HP-ENVLP.PAS.pas next >
Encoding:
Pascal/Delphi Source File  |  1993-05-28  |  9.7 KB  |  318 lines

  1. {In a following message, the Complete Turbo Pascal source code For DJENV.PAS
  2. is presented For all who may be interested in what it does, or illustrates.
  3.  
  4. The Program prints the "return" and "to:" addresses on a long ("#10")
  5. business sized envelope in a HP DeskJet series Printer.
  6.  
  7. Along the way it illustrates:
  8.  
  9.   1) How to test For existence of a specific File
  10.  
  11.   2) How to Read from a structured-Type File
  12.  
  13.   3) How to Write to a structured-Type File
  14.  
  15.   4) How to do Text-Type output to any of: LPT1...LPT3, NUL, or a disk File
  16.      With the same code.
  17.  
  18.   5) How to change fonts in PCL 3 (although this is not explained, it is
  19.      done to give small print For the return address and larger print
  20.      For the to: address.)
  21.  
  22.   6) How to use TechnoJock's Turbo toolkit For "full-screen I/O".  There are
  23.      three Procedures in the Program which REQUIRE the toolkit to Compile.
  24.      These routines could be modified For non-Full-Screen action which
  25.      would allow you to not use the TT toolkit.  if you don't want to make
  26.      the modifications, and don't have the TT toolkit, you may File request
  27.  
  28.      DJENV.ZIP
  29.  
  30.      from my system at 1:106/100.  It has both the source code presented here
  31.      and a Compiled .EXE File, ready to roll.
  32.  
  33.   if you'd like to play With it, but don't have a DJ or LASERJET-Compatible
  34. Printer, then you may tell the Program to print to a disk File or even NUL
  35. instead of LPT1, etc.
  36.  
  37.   Whatever addresses you enter, plus the name of the "print device" you
  38. use, will be saved in the File DJENV.CFG .  With a little work, DJENV.CFG
  39. could easily become a mini-database and allow you to retrieve from any
  40. number of previous envelope setups, instead of just the last one you used.
  41. I may eventually do this, but no time frame is currently anticipated For
  42. it's Completion.
  43.  
  44.   You may print 1 to many copies of the setup after you have entered it's
  45. info. The Program paUses beFore each envelope and gently nudges you to
  46. prepare an envelope For printing and then to hit Return.  (Any key
  47. returning a key code will do as well as Return.)
  48.  
  49.   Loading the envelopes is a Complete MANUAL operation.  While the DJ
  50. has a software command to load envelopes, you must still manually
  51. position the envelope For loading.  if the envelope doesn't load cleanly
  52. (and in my experience, about 1 in every 10 or 15 will go in crooked...), I
  53. felt it would be better to deal With that BEForE attempting to print.  After
  54. the envelope is in position to load, then it is necessary to hit two of the
  55. panel buttons together to have the DJ500 to pull the envelope into
  56. position.  When that is acComplished correctly, then hit Return to print to
  57. the envelope.
  58.  
  59. Hope some of you find this useful/interesting/maybe even helpful!
  60. }
  61.  
  62. Program DJ_Envelopes;
  63.  
  64. {  This Program illustrates how to Program For envelope printing
  65.    With the HP DeskJet series of Printer.  It would possibly work
  66.    For any PCL 3 (or better) Printer which can load envelopes.
  67.  
  68.    note:  Loading envelopes on the DJ Printers *IS* a bit tricky
  69.           and requires cooperative envelopes.  Be sure to read the
  70.           part in your manual about use of envelopes, selecting good
  71.           Printer-use envelopes, and especially about LOADinG them
  72.           manually.  I have used the following inexpensive envelopes
  73.           With some degree of success.  They were purchased at a
  74.           discount business/office supply store, BIZMART, but as the
  75.           brand is national, you can probably find them most anywhere:
  76.  
  77.              MEAD Management Series, no. 75604
  78.              Number 10 size, 4-1/8" x 9-1/2"
  79.              BARCODE#   43100 75064
  80.  
  81.              (100 of them cost about $2.00)
  82.  
  83.  
  84.    This Program is PUBLIC doMAin and may be freely distributed, modified,
  85.    even SOLD. (if you can find somebody stupid enough to pay For a PD
  86.    Program, MorE POWER to YOU! I would ask that you at least send me
  87.    their names....)
  88.  
  89.    The author is: Justin Marquez FidoNet 1:106/100  Houston, TX  USA
  90. }
  91.  
  92. Uses
  93.    FASTTTT5, {Requires TechnoJock's Turbo toolkit Ver 5 or higher }
  94.    WinTTT5,  {Requires TechnoJock's Turbo toolkit Ver 5 or higher }
  95.    IOTTT5,   {Requires TechnoJock's Turbo toolkit Ver 5 or higher }
  96.    Crt,      { Crt Unit For ClrScr }
  97.    Dos;      { Req'd to be able to use the EXIST Procedure as I wrote it }
  98.  
  99. Const
  100.     Return_Size   = #27+'&l0O'+ #27+'(10U' +#27+'(s1p6v0s41010bt2Q';
  101.     Addressee_Size = #27+'&l0O'+ #27+'(10U' +#27+'(s1p12v0s4103b1t2Q';
  102.     Config_File = 'DJENV.CFG';
  103.  
  104. Type
  105.     Add_Strg = String[60];
  106.  
  107.     Address_Data = Record { this is the Format of the "config File" }
  108.       Who_from: Array[1..5] of Add_Strg;
  109.       Last_to : Array[1..5] of Add_Strg;
  110.       PRN_DEV : String;
  111.     end;
  112.  
  113. Var
  114.     Return_Address,
  115.     Address : Array[1..5] of Add_Strg;
  116.  
  117.     lst     : Text;
  118.  
  119.     Last_Data : Address_Data;
  120.     CF_Data   : File of Address_Data; { going to be the config File }
  121.  
  122.     Print_to: String;
  123.  
  124.     n,
  125.     Counter,
  126.     How_Many : Integer;
  127.  
  128. Function EXIST(Filename :String): Boolean;
  129. {  Determines if a File exists or not.  NO WILDCARDS!
  130.    Main Program or Unit MUST have "Uses Dos;" in it!
  131. }
  132. Var
  133.    Attr : Word;
  134.    f    : File;
  135. begin
  136.   Assign(f,Filename);
  137.   GetFAttr(f,Attr);
  138.   if Attr = 0 then
  139.     Exist := False else
  140.     Exist := True;
  141. end; { of exist Function }
  142.  
  143. Procedure DrawScreen1;
  144.   {Requires TechnoJock's toolkit, Used to set up For the full-screen I/O}
  145. begin
  146.   ClrScr;
  147.   WriteCenter(1,Blue,White,' Enter Address Info, and hit F10 when done ...');
  148.   WriteCenter(2,Blue,White,' (Use CURSor keys For up & dn, RETURN For left &
  149. right) ');
  150.   WriteAt( 1, 5, White,Blue,'RETURN ADDRESS inFO...');
  151.   WriteAt( 3, 6, White,Blue,'             Line #1 :');
  152.   WriteAt( 3, 7, White,Blue,'             Line #2 :');
  153.   WriteAt( 3, 8, White,Blue,'             Line #3 :');
  154.   WriteAt( 3, 9, White,Blue,'             Line #4 :');
  155.   WriteAt( 3,10, White,Blue,'             Line #5 :');
  156.   WriteAt( 1,13, White,Blue,'ADDRESSEE inFO ....   ');
  157.   WriteAt( 3,14, White,Blue,'             Line #1 :');
  158.   WriteAt( 3,15, White,Blue,'             Line #2 :');
  159.   WriteAt( 3,16, White,Blue,'             Line #3 :');
  160.   WriteAt( 3,17, White,Blue,'             Line #4 :');
  161.   WriteAt( 3,18, White,Blue,'             Line #5 :');
  162.   WriteAt( 3,20, White,Blue,'Send Output to :');
  163.   WriteAt( 3,21, White,Blue,'[ Ex: LPT1  or  LPT2 or NUL (For testing) ]');
  164.   WriteAt( 3,23, White,Blue,'Print How Many?:');
  165. end; { of pvt Procedure drawscreen1 }
  166.  
  167. Procedure FS_IO;
  168. { Requires TechnoJock's Turbo toolkit }
  169. Var
  170.   counter : Integer;
  171. begin
  172.   Create_Fields(12);
  173.   {          #  U  D  L  R  x  y   }
  174.   Add_Field( 1,12, 2,12, 2,27, 6);
  175.   Add_Field( 2, 1, 3, 1, 3,27, 7);
  176.   Add_Field( 3, 2, 4, 2, 4,27, 8);
  177.   Add_Field( 4, 3, 5, 3, 5,27, 9);
  178.   Add_Field( 5, 4, 6, 4, 6,27,10);
  179.   Add_Field( 6, 5, 7, 5, 7,27,14);
  180.   Add_Field( 7, 6, 8, 6, 8,27,15);
  181.   Add_Field( 8, 7, 9, 6, 9,27,16);
  182.   Add_Field( 9, 8,10, 8,10,27,17);
  183.   Add_Field(10, 9,11, 9,11,27,18);
  184.   Add_Field(11,10,12,10,12,27,20);
  185.   Add_Field(12,11, 1,11, 1,27,23);
  186.  
  187.   For n := 1 to 5 Do
  188.  
  189. String_Field(n,Return_Address[n],'**********************************************
  190. ****');
  191.   For n := 1 to 5 Do
  192.  
  193. String_Field(n+5,Address[n],'**************************************************'
  194. );
  195.  
  196. String_Field(11,Print_to,'**************************************************');
  197.   Integer_Field(12,How_Many,'',0,0);
  198.   PROCESS_inPUT(1);
  199.   Dispose_Fields;
  200. end; { of Procedure FS_IO }
  201.  
  202. Procedure Init;
  203. begin
  204.   if ParamCount < 1
  205.   then
  206.     Print_to := 'LPT1'
  207.   else
  208.     Print_to := ParamStr(1);
  209.   if Exist(config_File)
  210.   then
  211.     begin
  212.       Assign(CF_Data,ConFig_File);  { How to READ a Record from a File }
  213.       ReSet(CF_Data);
  214.       Seek(CF_Data,0);
  215.       Read(CF_DATA,Last_Data);
  216.       Close(CF_Data);
  217.       With Last_Data do
  218.       begin
  219.         For n := 1 to 5 do
  220.         begin
  221.           Return_Address[n] := Who_From[n] ;
  222.           Address[n]        := Last_to[n];
  223.         end;
  224.         Print_to := PRN_DEV;
  225.       end;
  226.     end
  227.   else
  228.     begin
  229.       Return_Address[1] :='';
  230.       Return_Address[2] :='';
  231.       Return_Address[3] :='';
  232.       Return_Address[4] :='';
  233.       Return_Address[5] :='';
  234.       Address[1] := '';
  235.       Address[2] := '';
  236.       Address[3] := '';
  237.       Address[4] := '';
  238.       Address[5] := '';
  239.     end;
  240.   How_Many := 1;
  241. end;
  242.  
  243. Procedure OutPut_to_DJ500;
  244. begin
  245.   Assign(lst,Print_to);
  246.   ReWrite(lst);
  247.   Write(Lst,#27+'&l8D');
  248.   Write(lst,Return_Size);
  249.   For n := 1 to 5 Do
  250.     WriteLn(lst,Return_Address[n]);
  251.   Write(Lst,#27+'&l5D');
  252.   Write(lst,Addressee_Size);
  253.   For n := 1 to 3 Do Writeln(lst);
  254.   For n := 1 to 5 Do
  255.     WriteLn(lst,'
  256.         ',Address[n]);
  257.   WriteLn(lst,#12);
  258.   WriteLn(lst,#27+'E');
  259.   close(lst)
  260. end;
  261.  
  262. Procedure Save_Config_File;
  263. begin
  264.   Assign(CF_Data,ConFig_File);      { How to Write a Record to a File }
  265.   ReWrite(CF_Data);
  266.   With Last_Data do
  267.   begin
  268.     For n := 1 to 5 do
  269.     begin
  270.       Who_From[n] := Return_Address[n];
  271.       Last_to[n]  := Address[n];
  272.     end;
  273.     PRN_DEV := Print_to;
  274.   end;
  275.   Seek(CF_Data,0);
  276.   Write(CF_DATA,Last_Data);
  277.   Close(CF_Data);
  278. end;
  279.  
  280. Procedure Pause;
  281. { Requires TechnoJock's Turbo toolkit }
  282. begin
  283.   TempMessageBOX(20,10,Green,Blue,2,'Load an envelope (manually) and Hit
  284. RETURN.');
  285. end;
  286.  
  287. Procedure PRinT_ENVELOPES;
  288. begin
  289.   ClrScr;
  290.   GotoXY(2,1);
  291.   Write('Printing Envelope #:');
  292.   Counter := 1;
  293.   if How_Many > 1
  294.   then
  295.     begin
  296.     For Counter := 1 to How_Many Do
  297.       begin
  298.         WriteLn('  ',Counter);
  299.         Pause;
  300.         OutPut_to_DJ500;
  301.       end;
  302.     end
  303.   else
  304.     begin
  305.       WriteLn('  ',Counter,' ( and only 1 ...)');
  306.       Pause;
  307.       OutPut_to_DJ500;
  308.     end;
  309. end;
  310.  
  311. begin
  312.   Init;
  313.   DrawScreen1;
  314.   FS_IO;
  315.   PRinT_ENVELOPES;
  316.   Save_Config_File;
  317. end.
  318.