c#条形码打印为什么会打印时中间空几个纸张 就是每次打印是都是空5张纸 打印条形码 在空5张 纸 在打印 为什么 会出现中间空纸张的现象???
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Drawing.Printing;
using System.Windows.Forms;
namespace Code128Test
{
public partial class FrmTest : Form
{
string inputString;
public FrmTest()
{
InitializeComponent();
}
private string Get128CodeString(string inputData)
{
string result;
int checksum = 104;
for (int ii = 0; ii < inputData.Length; ii++)
{
if (inputData[ii] >= 32)
{
checksum += (inputData[ii] - 32) * (ii + 1);
}
else
{
checksum += (inputData[ii] + 64) * (ii + 1);
}
}
checksum = checksum % 103;
if (checksum < 95)
{
checksum += 32;
}
else
{
checksum += 100;
}
result = Convert.ToChar(204) + inputData.ToString() + Convert.ToChar(checksum) + Convert.ToChar(206);
return result;
}
public void PrintLable()
{
PrintDocument pd = new PrintDocument();
StandardPrintController controler = new StandardPrintController();
try
{
pd.PrintPage += new PrintPageEventHandler(this.PrintCustomLable);
pd.PrintController = controler;
Margins margins = new Margins(10, 10, 10, 10);
pd.DefaultPageSettings.Margins = margins;
pd.DefaultPageSettings.PaperSource.RawKind = 1;
pd.Print();
return;
}
catch (Exception err)
{
Console.WriteLine(err.Message);
return;
}
finally
{
pd.Dispose();
}
}
public void PrintCustomLable(Object Sender, PrintPageEventArgs av)
{
Font ft1 = new System.Drawing.Font("Times New Roman", 12, FontStyle.Regular, GraphicsUnit.World);
Font ft2 = new System.Drawing.Font("Code 128", 38, FontStyle.Regular, GraphicsUnit.World);
Brush br = new SolidBrush(Color.Black);
Margins margins = new Margins(50, 50, 50, 150);
av.PageSettings.Margins = margins;
av.Graphics.DrawString(Get128CodeString(inputString), ft2, br, 105, -3);
av.Graphics.DrawString(inputString, ft1, br, 130, 45);
av.HasMorePages = false;
// av.Graphics.PageUnit = GraphicsUnit.Millimeter;
}
private void btnPrint_Click(object sender, EventArgs e)
{
inputString = txtInput.Text;
lblBarCode.Text = Get128CodeString(inputString);
PrintLable();
}
}
}