::: µ¨ÆÄÀÌ Tip&Trick :::

µ¨ÆÄÀÌ Tip&Trick ¼º°Ý¿¡ ¸ÂÁö ¾Ê´Â ±¤°í,ºñ¹æ,Áú¹®ÀÇ ±ÛÀº Áï½Ã »èÁ¦Çϸç
³»¿ëÀ» º¹»çÇÏ¿© »ç¿ëÇÒ °æ¿ì ¹Ýµå½Ã ÀÌ°÷(http://www.howto.pe.kr)À» Ãâó·Î ¸í½ÃÇÏ¿© ÁÖ¼¼¿ä


Category

  ±è¿µ´ë(2003-03-07 09:16:43, Hit : 5437, Vote : 1342
 ÇÁ¸°ÅÍ·Î escape ¹®ÀÚ Ãâ·ÂÇϱâ(raw print)

Stefano Rustioni wrote:
>
> Hello,
> i've got a little problem with my text-only printer:
> Is there a way to send escape codes to the printer for setting character
> size?
> I use a Generic-Text Only driver, and my escape codes are: #27 + #15 for
> start compress printing and #27 + #18 for ending print.
>
> What can I do to use this escape sequence?
>
> Is there some
>
> Thanks a lot,
> Stefano Rustioni


Question:
How do I write a raw string of a data to the printer?

The following unit "PrtRaw.pas" demonstrates a 16/32 bit
raw printing unit for Delphi and Borland C Builder.

Following the unit, is an exmaple on using the
PrtRaw unit.

Notes:

1) You are responsible for embedding all necessary
control codes that the printer may require (including
form feed codes).

2) You must specify a valid printer and port name.



unit PrtRaw;

{Copyright (c) 1998 by Joe C. Hecht - All rights Reserved}
{joehecht@gte.net You may use and share this unit}
{providing my name and the copyright notice stays intact.}

interface

uses
  WinTypes;

{$IFDEF WIN32}
type SpoolInt = DWORD;
{$ELSE}
type SpoolInt = integer;
{$ENDIF}

function StartRawPrintJob(PrinterName : pChar;
                          Port : pChar;
                          DocName : pChar) : THandle;

function StartRawPrintPage(hPrn : THandle) : integer;

function PrintRawData(hPrn : THandle;
                      Buffer : pointer;
                      NumBytes : SpoolInt) : integer;

function EndRawPrintPage(hPrn : THandle) : integer;

function EndRawPrintJob(hPrn : THandle) : integer;


implementation
uses
   WinProcs,
{$IFDEF WIN32}
WinSpool;
{$ELSE}
Print;
{$ENDIF}


function StartRawPrintJob(PrinterName : pChar;
                          Port : pChar;
                          DocName : pChar) : THandle;
{$IFDEF WIN32}
var
   hPrn : THandle;
   DocInfo1 : TDocInfo1;
{$ENDIF}
begin
{$IFDEF WIN32}
   if (OpenPrinter(PChar(PrinterName),
                   hPrn,
                   nil) = FALSE)  then begin
     Result := THandle(-1);
     Exit;
   end;
   DocInfo1.pDocName := DocName;
   DocInfo1.pOutputFile := Port;
   DocInfo1.pDataType := 'RAW';
   if (StartDocPrinter(hPrn,
                       1,
                       @DocInfo1) = 0) then begin
     Result := THandle(-1);
     exit;
   end;
   Result := hPrn;
{$ELSE}
  result := OpenJob(Port,
                    DocName,
                    0);
{$ENDIF}
end;

function StartRawPrintPage(hPrn : THandle) : integer;
begin
{$IFDEF WIN32}
   if (StartPagePrinter(hPrn) = FALSE) then begin
     Result := -1;
     exit;
   end;
   result := 1;
{$ELSE}
  result := StartSpoolPage(hPrn);
{$ENDIF}
end;


function PrintRawData(hPrn : THandle;
                      Buffer : pointer;
                      NumBytes : SpoolInt) : integer;
{$IFDEF WIN32}
var
  BytesWritten : DWORD;
{$ENDIF}
begin
  if (NumBytes = 0) then begin
    Result := 1;
    exit;
  end;
{$IFDEF WIN32}
   if (WritePrinter(hPrn,
                    Buffer,
                    NumBytes,
                    BytesWritten) = FALSE) then begin
     Result := -1;
     exit;
   end;
   if (NumBytes <> BytesWritten) then begin
     Result := -1;
     exit;
   end;
   Result := 1;
{$ELSE}
  result := WriteSpool(hPrn,
                       Buffer,
                       NumBytes);
{$ENDIF}
end;


function EndRawPrintPage(hPrn : THandle) : integer;
begin
{$IFDEF WIN32}
   if (EndPagePrinter(hPrn) = FALSE) then begin
     Result := -1;
     exit;
   end;
   Result := 1;
{$ELSE}
  result := EndSpoolPage(hPrn);
{$ENDIF}
end;


function EndRawPrintJob(hPrn : THandle) : integer;
begin
{$IFDEF WIN32}
   if (EndDocPrinter(hPrn) = FALSE) then begin
     Result := -1;
     exit;
   end;
   if (ClosePrinter(hPrn) = FALSE) then begin
     Result := -1;
     exit;
   end;
   Result := 1;
{$ELSE}
  result := CloseJob(hPrn);
{$ENDIF}
end;


end.

Example of use:

uses
  PrtRaw;


procedure TForm1.Button1Click(Sender: TObject);
var
  hPrn : THandle;
  Data : array[0..31] of char;
begin

  hPrn := StartRawPrintJob('Generic / Text Only',
                           'LPT1:',
                           'My Document');
  if (integer(hPrn) < 0) then begin
    ShowMessage('StartRawPrintJob Failed');
    exit;
  end;

  if (StartRawPrintPage(hPrn) < 0) then begin
    ShowMessage('StartRawPrintPage Failed');
    EndRawPrintJob(hPrn);
    exit;
  end;

  Data[0] := 'P';
  Data[1] := 'a';
  Data[2] := 'g';
  Data[3] := 'e';
  Data[4] := #32;
  Data[5] := '1';
  Data[6] := #13;
  Data[7] := #10;

  if (PrintRawData(hPrn,
                   @data,
                   8) < 0) then begin
    ShowMessage('PrintRawData Failed');
    EndRawPrintPage(hPrn);
    EndRawPrintJob(hPrn);
    exit;
  end;

  if (EndRawPrintPage(hPrn) < 0) then begin
    ShowMessage('EndRawPrintPage Failed');
    EndRawPrintJob(hPrn);
    exit;
  end;

  if (StartRawPrintPage(hPrn) < 0) then begin
    ShowMessage('StartRawPrintPage Failed');
    EndRawPrintJob(hPrn);
    exit;
  end;
  Data[0] := 'P';
  Data[1] := 'a';
  Data[2] := 'g';
  Data[3] := 'e';
  Data[4] := #32;
  Data[5] := '2';
  Data[6] := #13;
  Data[7] := #10;

  if (PrintRawData(hPrn,
                   @data,
                   8) < 0) then begin
    ShowMessage('PrintRawData Failed');
    EndRawPrintPage(hPrn);
    EndRawPrintJob(hPrn);
    exit;
  end;

  if (EndRawPrintPage(hPrn) < 0) then begin
    ShowMessage('EndRawPrintPage Failed');
    EndRawPrintJob(hPrn);
    exit;
  end;

  if (EndRawPrintJob(hPrn) < 0) then begin
    ShowMessage('EndRawPrintJob Failed');
    exit;
  end;

end;

end.





571   [À©µµ¿ìÁî API] À©µµ¿ìÁî '½ÃÀÛ' ¸Þ´º Refresh ½ÃÅ°±â  ±è¿µ´ë 2003/03/07 5065 1483
570   [À©µµ¿ìÁî API] ´Ù¸¥ ApplicationÀÇ È­¸é¿¡ ±ÛÀÚ,±×¸²À» Ãâ·ÂÇÏ±â  ±è¿µ´ë 2003/03/07 3719 934
569   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] WideString À» String À¸·Î ¹Ù²Ù±â  ±è¿µ´ë 2003/03/07 4933 1257
568   [À©µµ¿ìÁî API] À©µµ¿ìÁî Ž»ö±âÀÇ ÆÄÀÏ, ÄÄÇ»ÅÍ Ã£±â È­¸é ¶ç¿ì±â  ±è¿µ´ë 2003/03/07 6618 1710
567   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] MessageDlg()ÀÇ ÆùÆ®¸¦ ¹Ù²Ù¾î¼­ ¶ç¿ì±â  ±è¿µ´ë 2003/03/07 4223 1106
566   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] ListView ÀÇ item À» °­Á¦·Î ÆíÁý»óÅ·Π¸¸µé±â  ±è¿µ´ë 2003/03/07 4967 1272
565   [µ¥ÀÌÅͺ£À̽º] µ¿ÀûÀ¸·Î SELECTÀÇ GROUP BY ¹® ¸¸µé±â  ±è¿µ´ë 2003/03/07 4515 995
564   [À©µµ¿ìÁî API] ALT_F4 hot key °¡·Îä±â  ±è¿µ´ë 2003/03/07 6019 1711
563   [À©µµ¿ìÁî API] ·¹Áö½ºÆ®¸® Àüü °Ë»öÇÏ±â  ±è¿µ´ë 2003/03/07 4628 1201
562   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] TOpenDialog ÀÇ '¼±ÅÃ','Ãë¼Ò' ¹öÆ° À̸§ ¹Ù²Ù±â  ±è¿µ´ë 2003/03/07 4643 1392
561   [À©µµ¿ìÁî API] ¸ð¼­¸®°¡ µÕ±Ù(rounded ends) TEdit ¸¸µé±â  ±è¿µ´ë 2003/03/07 5467 1357
560   [½Ã½ºÅÛ] ÇÁ·Î±×·¥ÀÌ µ¿ÀûÀ¸·Î ÇÒ´ç¹ÞÀº ¸Þ¸ð¸® Å©±â ?  ±è¿µ´ë 2003/03/07 4865 1366
559   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] OnActivate À̺¥Æ® ³»¿¡¼­ Æû È®½ÇÈ÷ ´Ý±â  ±è¿µ´ë 2003/03/07 4514 1137
558   [µ¥ÀÌÅͺ£À̽º] QueryÇÑ °á°ú¸¦ ¼öÁ¤Çϱâ...  ±è¿µ´ë 2003/03/07 5207 1252
557   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] StringGridÀÇ CellÀ» °­Á¦·Î ´ÙÁß ¼±ÅÃ/ÇØÁ¦ ½ÃÅ°±â  ±è¿µ´ë 2003/03/07 4399 1059
556   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] TRichEditÀÇ Çà°£°Ý ¶ç¿ì±â(line spacing)  ±è¿µ´ë 2003/03/07 5835 1545
  [ÀϹÝ/ÄÄÆ÷³ÍÆ®] ÇÁ¸°ÅÍ·Î escape ¹®ÀÚ Ãâ·ÂÇϱâ(raw print)  ±è¿µ´ë 2003/03/07 5437 1342
554   [À©µµ¿ìÁî API] keyboard, mouse ¸Þ½ÃÁö ¹«½Ã(skip) ÇÏ±â  ±è¿µ´ë 2003/03/07 4789 1259
553   [À©µµ¿ìÁî API] À©µµ¿ìÁî Ä¿¼­(global cursor) ¹Ù²Ù±â  ±è¿µ´ë 2003/03/07 7577 2316
552   [½Ã½ºÅÛ] ÇöÀç ÇÁ¸°ÅÍÀÇ Ãâ·Â°¡´ÉÇÑ ¿ëÁöÁ¾·ù ±¸ÇÏ±â  ±è¿µ´ë 2003/03/07 6640 1748
551   [½Ã½ºÅÛ] ÇÁ¸°ÅÍ¿¡ ÀÛ¾÷ÁßÀÎ jobÀÇ ¸®½ºÆ® ±¸ÇÏ±â  ±è¿µ´ë 2003/03/07 5239 1299
550   [½Ã½ºÅÛ] Clipboard ÈÉÃ帱â(Clipboard hooking)  ±è¿µ´ë 2003/03/07 7384 1665
549   [À©µµ¿ìÁî API] ControlÀÇ repainting ±ÝÁöÇÏ¿© ±ô¹ÚÀÓ ÁÙÀÌ±â  ±è¿µ´ë 2003/03/07 6202 1335
548   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] ¹®ÀÚ¿­ÀÇ ³¡¿¡¼­ºÎÅÍ °Ë»öÇÏ´Â Pos() ÇÔ¼ö  ±è¿µ´ë 2003/03/07 5405 1224
547   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] µð·ºÅ丮¸í ¹Ù²Ù±â/À̵¿ ÇÏ±â  ±è¿µ´ë 2003/03/07 5668 1643
546   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] µð·ºÅ丮 º¯µ¿»çÇ×À» Ž»ö±â¿¡ ¾Ë¸®±â  ±è¿µ´ë 2003/03/07 5754 1659
545   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] Æû ÀμâÇϱâ 2  ±è¿µ´ë 2003/03/07 4155 1311
544   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] ¿¬¼ÓµÈ Å°º¸µåÀÇ Å° ¹ß»ý½ÃÅ°±â  ±è¿µ´ë 2003/03/07 4415 1169
543   [½Ã½ºÅÛ] Keyboard Hook  ±è¿µ´ë 2003/03/07 4481 939
542   [À©µµ¿ìÁî API] ·¹Áö½ºÆ®¸®ÀÇ Æ¯Á¤Å°¸¦ ÆÄÀÏ·Î ÀúÀå/º¹¿øÇÏ±â  ±è¿µ´ë 2003/03/07 7118 1603
541   [½Ã½ºÅÛ] PC¿¡ ¼³Ä¡µÈ DirectX ¹öÀü ÀÐ±â  ±è¿µ´ë 2003/03/07 4221 1273
540   [µ¥ÀÌÅͺ£À̽º] CD ¿¡ ÀÖ´Â DB Á¢±ÙÇÏ±â  ±è¿µ´ë 2003/03/07 4093 1140
539   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] Á¦¾îÆÇÀÇ applet ¸®½ºÆ® (17°³)  ±è¿µ´ë 2003/03/07 3645 1031
538   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] Åõ¸íÇÑ Bitmaps ÀÎ¼â  ±è¿µ´ë 2003/03/07 7932 1510
537   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] QReport ¸¦ bmp ·Î º¯È¯ÇÏ±â  ±è¿µ´ë 2003/03/07 3500 902
536   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] WMF ¸¦ BMP ·Î º¯È¯ÇÏ±â  ±è¿µ´ë 2003/03/07 4685 1405
535   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] MemoÀÇ ÀÔ·ÂÇà¼ö Á¦ÇÑÇÏ±â  ±è¿µ´ë 2003/03/07 4429 1217
534   [½Ã½ºÅÛ] PCÀÇ Àü¿ø»óÅ ¾Ë¾Æº¸±â  ±è¿µ´ë 2003/03/07 6198 3789
533   [À©µµ¿ìÁî API] ÆÄÀÏ¿¡¼­ ¾ÆÀÌÄÜ »©³»±â(32 * 32)  ±è¿µ´ë 2003/03/07 6722 1676
532   [À©µµ¿ìÁî API] ÆÄÀÏ¿¡¼­ ¾ÆÀÌÄÜ »©³»±â(16 * 16)  ±è¿µ´ë 2003/03/07 5124 1331

[ÀÌÀü 10°³] [1].. 11 [12][13][14][15][16][17][18][19][20]..[25] [´ÙÀ½ 10°³]
 

Copyright 1999-2024 Zeroboard / skin by zero