Danieboy
Danieboy

Reputation: 4521

How to insert Barcode image into PrintDialog?

I have this program where I print some information about a pallet (logistics) and I need to add a barcode to this. I was looking around and found that http://www.codeproject.com/Articles/20823/Barcode-Image-Generation-Library did seem very promising.

I've added the .dll reference and added the code below:

using BarcodeLib;

// Create barcode size 100, 100 with the ordernumber in type EAN13
    Barcode b = new Barcode(order.OrderNr);
    b.Encode(TYPE.EAN13, order.OrderNr, 100, 100);

Now what I need to know is how to add this to a specific position on the page. The way I currently add the text looks something like this:

private void PrintLabel(PrintPageEventArgs e, Graphics g)
{
    marginTop = 8;
    marginLeft = 5;
    int row = marginTop;

    g.DrawString("Order nr: ", headerTitleFont, blackText, marginLeft, row);
    g.DrawString(order.OrderNr, headerTextFont, blackText, marginLeft + 120, row);
    row += 22;
    ...etc...

    Barcode b = new Barcode(order.OrderNr);
    b.Encode(TYPE.EAN13, order.OrderNr, 100, 100);
    // Print the label b here on position: marginLeft, row
}

Upvotes: 2

Views: 96

Answers (1)

Yeldar Kurmangaliyev
Yeldar Kurmangaliyev

Reputation: 34199

According to the given documentation, Encode returns System.Drawing.Image.

It is very convenient, because it allows you to simply draw it to graphics using:

Barcode b = new Barcode(order.OrderNr);
Image barcodeImage = b.Encode(TYPE.EAN13, order.OrderNr, 100, 100);

g.DrawImage(barcodeImage, marginLeft, row);

Upvotes: 1

Related Questions