Search code examples
c#winformsprintingbarcode

printing barcode from winforms application


I want to print barcodes in a winforms application with the normal printing facilities, not through a ZPL like language. I can print anything just not a regular barcode

using (PrintDocument pd = new PrintDocument())
{
    pd.PrintController = new StandardPrintController();
    pd.PrinterSettings.PrinterName = "Printer";
    pd.PrintPage += new PrintPageEventHandler(pd_PrintLabel);
    pd.Print();
}

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

    using (Font f = new Font(FontFamily.GenericSansSerif, 6))
    {
       g.DrawString(????????? what to do for barcode????);
    }
}

Solution

  • We were using Barcode Rendering Framework:

    BarcodeDraw bdraw = BarcodeDrawFactory.GetSymbology(BarcodeSymbology.Code128);
    Image barcodeImage = bdraw.Draw("barcodetext", barcodeImageHeight);
    g.DrawImage(barcodeImage, barcodeRect);