Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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????);
    }
}
like image 267
Serve Laurijssen Avatar asked Dec 21 '22 00:12

Serve Laurijssen


2 Answers

We were using Barcode Rendering Framework:

BarcodeDraw bdraw = BarcodeDrawFactory.GetSymbology(BarcodeSymbology.Code128);
Image barcodeImage = bdraw.Draw("barcodetext", barcodeImageHeight);
g.DrawImage(barcodeImage, barcodeRect);
like image 179
FireShock Avatar answered Dec 22 '22 14:12

FireShock


void printDoc()
{

    PrintDocument document = new PrintDocument();
    BarcodeDraw bdraw = BarcodeDrawFactory.GetSymbology(BarcodeSymbology.Code128);
    Image barcodeImage = bdraw.Draw("PO7120172733039800", 50);

    document.PrintPage += delegate(object sender, PrintPageEventArgs e)
    {
        e.Graphics.DrawImage(barcodeImage, 0, 0);
        e.Graphics.DrawString("PO7120172733039800", new Font("arial", 8), new SolidBrush(Color.Black),0,50);
    };
    document.Print();
}
like image 25
Maganjo Avatar answered Dec 22 '22 13:12

Maganjo