0

i want to create a little image containing a logo and multiple lines of text and send it directly to a printer. However im having trouble with textquality.

Currently im creating a Bitmap and render text to it via g.DrawString:

Bitmap bitmap = new Bitmap(240, 240);
Graphics g = Graphics.FromImage(bitmap);
g.SmoothingMode = SmoothingMode.AntiAlias;
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;  // or AntiAlias
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
g.DrawString("Charge: 1911", new Font("Arial Narrow", 8.0F, System.Drawing.FontStyle.Regular), Brushes.Black, new PointF(6,119));

PrintDocument pd = new PrintDocument();
[...]
pd.PrintPage += PrintPage;
    pd.Print();
g.Dispose();

This Code works so far as expected, except the textquality is too bad to actually print.
This is the current result:

with AntiAliasGridFit:

enter image description here

With AntiAlias:

enter image description here

This (or better) is the result that i want to achieve:

enter image description here

Now my question is, is there any way to get better textquality, maybe somehow using TextRenderer instead of Graphics? It doesnt have to be a bitmap that I print. I just need to be able to also write a pre-existing image to it and send the whole document to a Printer afterwards.

Clemens
  • 123,504
  • 12
  • 155
  • 268
madman
  • 1
  • 3
  • Whats Your DPI on that printer ? – Kuba Do Feb 03 '20 at 15:13
  • I can only check it in a few days, but its a labelprinter which is already printing very small text. – madman Feb 04 '20 at 16:34
  • Do You know model of this printer ? – Kuba Do Feb 05 '20 at 07:28
  • Hey, i was able to check just now. i will need to be able to print to a Zebra TLP3842 and a Brother QL-560. – madman Feb 05 '20 at 14:23
  • You can try different approach from [that post check how to send ZPL to printer](https://stackoverflow.com/questions/51754966/print-to-zebra-printer-tlp-3842) and from [this site](http://www.jcgonzalez.com/img-to-zpl-online) You can convert image to ZPL, [at this site You can check how label will look like](http://labelary.com/viewer.html). This will take You a while, but sending raw ZPL to printer will lead You to better quality – Kuba Do Feb 05 '20 at 15:03
  • Oh alright i haven't tought about this way yet, first time trying to send stuff to a printer. I will have to look into it. Thanks so far for your help! – madman Feb 05 '20 at 15:06

1 Answers1

0

After some more digging i found a solution to my problem.
Instead of creating a Bitmap and drawing text to it i directly draw text to the PrintPageEventArgs object of the PrintPage Method:

private void PrintPage(object o, PrintPageEventArgs e) {
    e.Graphics.DrawImage(logoImg, xCoordinate, yCoordinate, xSize, ySize);
    e.Graphics.DrawString("Charge: 19011", textFont, Brushes.Black, 0, 0, new StringFormat());
}

Im not 100% sure why this works but i now have perfectly clear text like with vector graphics.

Example

madman
  • 1
  • 3