No announcement yet.

printing scanned signature in dot matrix printer?

  • Filter
  • Time
  • Show
Clear All
new posts

  • printing scanned signature in dot matrix printer?

    How I can print a signature or a logo scanned in a
    dot-matrix printer (C.Itoh C-650 that Epson Esc P2
    emulates)?. Where I get the code in powerbasic 3.5
    or pb/dll 6.0 that makes?


  • #2
    You may want to look at the file ALLPRINT.ZIP on the PB XTRA CD. Graphic programming
    with dot matrix printers is complex to say the least.

    There are many code snippets around regarding this but much of it
    is dated, so you will have to search




    • #3

      the following code prints a black and white image got from SCREEN 11 by
      means of a GET statement. I adapted it from a QBasic program I wrote
      time ago (never thought I would use it again!). It works fine on my
      Epson 24-pin printer which uses the ESC-P2 command language. You will
      have to check if the commands for your printer are identical.

      In fact, all you need to know are the details of the printer instructions,
      and the exact data format how the image is stored and how the printer
      receives data, and then convert the former format into the latter.

      The format of an array got by GET is:
      WORD = image width in pixels
      WORD = image height in pixels
      Image data follows line by line, starting at the top left corner. Detail
      (for B+W images): The first pixel corresponds to the value of Bit 7 (not
      0) in the first byte (which is the fifth byte in the array).

      The printer (24-pin) receives data in columns of 24 dots, which correspond
      to 3 bytes each. Here also, the top-most dot corresponds to Bit 7 (not 0)
      in the first byte.

      If you want to print images from other formats (e.g. BMP files), all you
      need is the information about the data format and you can write a similar
      conversion routine. For a B+W standard BMP file, your program will have to
      check the following:
      - Signature "BM" at offset 0
      - Offset of image data = LONG at offset 10 (should be 62 for B+W)
      - Image width in pixels = LONG at offset 18
      - Image height in pixels = LONG at offset 22
      - Bits per pixel = WORD at offset 28 (should be 1 for B+W)
      - Size of image data in bytes = LONG at offset 34
      - Image data: line by line, starting at the BOTTOM left corner and each
      line padded with zero-bytes up to a multiple of 4 bytes.

      Hope this helps you!

      Hans Ruegg.

      P.S: Does anybody know a more effective way of sending binary data to the
      printer, instead of PRINT CHR$(n) ? Using PUT did not work, opening the
      printer in binary mode did neither.

      Code follows:

      DEFINT A-Z
      DECLARE SUB PrintGraph (graph?())
      DECLARE SUB PrintGraphLine (graph?(), prn?(), w, h, StartLine, PrinterHandle)
      SCREEN 11
      FOR x = 5 TO 45 STEP 5    '(draw something on the screen ...)
         LINE (x,100)-(x+4,150)
      NEXT x
      REDIM g?(1000), p?(0)
      GET (0,100)-(49,149), g?  '(... GET it ...)
      PrintGraph g?()           '(... and print it.)
      SCREEN 0
      SUB PrintGraph (graph?())
      'Prints a black and white image stored in graph?() by a GET statement in
      'a monochrome screen mode (e.g. SCREEN 11).
      'For 24-pin dot-matrix ESC-P2 Printer on port LPT 1.
      '(Tested with Printer Epson LQ-1070+.)
      Handle = FREEFILE
      OPEN "LPT1:" AS #Handle
      WIDTH #Handle, 255   		      '(suppress automatic CR/LF)
      PRINT #Handle, CHR$(27)+"@";          'Initialize Printer
      PRINT #Handle, CHR$(27)+"U"+CHR$(1);  '(Unidirectional printing)
      PRINT #Handle, CHR$(27)+"3"+CHR$(24); '(Set Line Spacing to 24 dots)
      w = graph?(0) + 256*graph?(1)         'image width in pixels
      h = graph?(2) + 256*graph?(3)         'image height in pixels
      REDIM p?(0)
      FOR PrintLine = 0 TO (h-1)\24
        PrintGraphLine graph?(), p?(), w, h, PrintLine*24, Handle
      NEXT PrintLine
      PRINT #Handle, CHR$(12);              '(Form Feed = Eject sheet)
      CLOSE #Handle
      END SUB
      SUB PrintGraphLine (graph?(), prn?(), w, h, StartLine, PrinterHandle)
      'Prints a 24-dot graphics line from the image stored in graph?().
      'Array prn?() is returned by this subroutine in case you want to store
      'the printer data for future use.
      'See other comments under SUB PrintGraph.
      BytesPerLine = (w+7)\8
      BitsPerLine = BytesPerLine * 8
      BitOffset = BitsPerLine * StartLine
      MaxBitOffset = BitsPerLine * h
      REDIM prn?(3*BitsPerLine)
      counter = 0
      FOR GraphByte = 1 TO BytesPerLine
        FOR Column = 0 TO 7
          OffsetNow = BitOffset + 7 - Column
          FOR PrnByte = 0 TO 2
             prn?(counter) = 0
             FOR PrnBit = 7 TO 0 STEP -1
                SHIFT LEFT prn?(counter), 1
                IF OffsetNow < MaxBitOffset THEN
                  prn?(counter) = prn?(counter) OR BIT(graph?(4), OffsetNow)
                END IF
                OffsetNow = OffsetNow + BitsPerLine
             NEXT PrnBit
             INCR counter
          NEXT PrnByte
        NEXT Column
        BitOffset = BitOffset + 8
      NEXT GraphByte
      PRINT #PrinterHandle, CHR$(27); "*'"; CHR$(w AND 255); CHR$(w\256);
      	'(Instruction "Print BitImage 180x180 dpi, w columns")
      FOR i = 0 TO 3*w-1
        PRINT #PrinterHandle, CHR$(prn?(i));
      	'(Sending image data to the printer)
      NEXT i
      PRINT #PrinterHandle, CHR$(13); CHR$(10);
      	'(Carriage return and Line feed)
      END SUB


      • #4

        Visit this site:

        This site has excellent information about everything related to DOS programming
        and printing to inkjets/dotmatrix/lasers you name it