开发者

Print in Arial Font or any other font by sending raw data to the printer

开发者 https://www.devze.com 2023-02-06 20:20 出处:网络
private void printfunction(string cmd) { string command = cmd; // Create a buffer with the command Byte[] buffer = new byte[command.Length];
private void printfunction(string cmd)
  {
   string command = cmd;

   // Create a buffer with the command
   Byte[] buffer = new byte[command.Length];
   buffer = System.Text.Encoding.ASCII.GetBytes(command);

   // Use the CreateFile external functo connect to the LPT1 port
   SafeFileHandle printer = CreateFile("LPT1:", FileAccess.ReadWrite, 0, IntPtr.Zero, FileMode.Open, 0, IntPtr.Zero);

   // Aqui verifico se a impressora é válida
   if (printer.IsInvalid == true)
   {
    MessageBox.Show("Printer not found!", "Error"开发者_如何学Go, MessageBoxButtons.OK, MessageBoxIcon.Error);
    return;
   }

   // Open the filestream to the lpt1 port and send the command
   FileStream lpt1 = new FileStream(printer, FileAccess.ReadWrite);
   lpt1.Write(buffer, 0, buffer.Length);

   // Close the FileStream connection
   lpt1.Close();
  }

I've been using the code function above to send raw data to my ESC/POS supported EPSON TM88III printer.

I've only 3 sent of fonts by default in printer. But I wan't to print in ARIAL FONT. How can we print in Arial font.

Please don't suggest me to use windows print spooler or printer driver. I want to print by sending raw data.

How can we do this?

The coding is done in C#.NET using Visual Studio 2008.


This is technically possible by putting the printer in graphics mode and sending pixel data. You'll have to create a monochrome bitmap in your program, the Bitmap and Graphics classes can get the job done. You'd use Graphics.DrawText with a Font initialized with Arial to get the text the way you want it. Encoding the bitmap pixels into printer commands is the non-trivial part, be sure to have a decent programming manual for the printer.

This is otherwise exactly what the printer driver does. It will be just as slow.


As far as I know, the TM88's windows driver simply sends the print output as a bitmap to the printer, because the TM88 does not natively support anything more than fixed-width text, barcodes, and bitmaps.

You can use escape codes to switch between serif and sans-serif fonts, but they will both be fixed-width.


That cannot be done. Raw text is, by convention, printed using a monospace font (such as Courier).

If you only need it to work with your particular printer model, you could try using Postscript, but it is unlikely that your printer will have Arial installed; Helvetica is more likely.


Depending on your printer, you should use other codes.

This wikipededia entry on the EPSON ESC/P explains a lot.

Sending "ESC k 1" (ESC = code 27) to the printer, puts it in Sans Serif font. But I don't think it is proportional.

If you really want to use your own font. You could render it (in black/white) to an Image/Bitmap object. Put the printer in graphics mode, and then print pixel by pixel. (Actually you print per 8 or 9 pixels).

0

精彩评论

暂无评论...
验证码 换一张
取 消