在同一张纸上多次打印图像c#

时间:2018-07-08 02:00:21

标签: c# printing barcode

嗨,我想在一张纸上打印产品条形码,但是如果用户在库存中写了6种产品,那么它必须在纸上打印此代码六倍,我有一个代码,但是每张图像仅打印一个代码,请参阅在下面。

private void generar_codigo_btn_Click(object sender, EventArgs e)
    {
        string codigo_generado = nom_prd_txt.Text; 
        BarcodeLib.Barcode Codigo = new BarcodeLib.Barcode();
        Codigo.IncludeLabel = true;
        codigo_pic.BackgroundImage = Codigo.Encode(BarcodeLib.TYPE.CODE128, codigo_generado, Color.Black, Color.White, 173, 102);

        PrintDialog pd = new PrintDialog();
        PrintDocument doc = new PrintDocument();
        doc.PrintPage += Doc_PrintPage;
        pd.Document = doc;
        if (pd.ShowDialog() == DialogResult.OK)
            doc.Print();
    }

    private void Doc_PrintPage(object sender, PrintPageEventArgs e)
    {
        Bitmap bm = new Bitmap(codigo_pic.Width, codigo_pic.Height);
        codigo_pic.DrawToBitmap(bm, new Rectangle(5, 5, codigo_pic.Width, codigo_pic.Height));
        e.Graphics.DrawImage(bm, 0, 0);
        bm.Dispose();
    }

2 个答案:

答案 0 :(得分:0)

您必须在位图中多次绘制条形码

-no-hygeine

请注意,您必须更改NoOfTimesToPrint变量才能根据需要使用此代码

答案 1 :(得分:0)

int NumOfLabel = Convert.ToInt16(textBox_StockAddQuntity_StockEntry.Text); /* here for example i set to total copy */

PrintDialog pDlg = new PrintDialog();
pDlg.Document = printDocument_Barcode;
pDlg.AllowSelection = true;
pDlg.AllowSomePages = true;
pDlg.PrinterSettings.Copies = (short)NumOfLabel;
printDocument_Barcode.Print();