0 votes

How to print barcode directly through printer? Without saving it into image.

private void pd_PrintLabel(object sender, PrintPageEventArgs ev)
{
    Graphics g = ev.Graphics;

    using (Font f = new Font(FontFamily.GenericSansSerif, 6))
    {
        BaseBarcode barcode = BarcodeFactory.GetBarcode(Symbology.Code128);
        barcode.Number = "1999999999999";
        barcode.ChecksumAdd = true;

        ///what to do for printing
    }
}
by (300 points)

1 Answer

0 votes

Use BaseBarcode.Render method:

private void pd_PrintLabel(object sender, PrintPageEventArgs ev)
{
    ev.Graphics.PageUnit = GraphicsUnit.Pixel;

    BaseBarcode b = BarcodeFactory.GetBarcode(Symbology.Code128);
    b.Number = "1999999999999";
    b.ChecksumAdd = true;

    b.Height = CentimetersToPixels(
        2.5, 
        ev.Graphics.DpiY);                      // 2.5 cm

    b.NarrowBarWidth = CentimetersToPixels(
        0.05, 
        ev.Graphics.DpiX);                      // 0.05 cm = 0.5 mm

    b.Render(
        ev.Graphics, 
        CentimetersToPixels(1.0, ev.Graphics.DpiX), 
        CentimetersToPixels(1.0, ev.Graphics.DpiY));
}
by (301k points)
...