我正在使用以下代码
public void PrintMethod()
{
PrintPg print1 = new PrintPg();
print1.RefrencePro = comboBoxRefrence1.Text;
print1.print();
MessageBox.Show("Bill Printed Successfully");
}
private void Save_Print_Click(object sender, EventArgs e)
{
PrintMethod();
}
class PrintPg
{
PrintDocument pdoc = null;
String Reference;
public string RefrencePro
{
set { this.Reference = value; }
get { return this.Reference; }
}
public PrintPg(string Reference)
{
this.Refrence = Refrence;
}
public void print()
{
PrintDialog pd = new PrintDialog();
pdoc = new PrintDocument();
PrinterSettings ps = new PrinterSettings();
Font font = new Font("Courier New", 15);
PaperSize psize = new PaperSize("Custom", 100, 200);
//ps.DefaultPageSettings.PaperSize = psize;
pd.Document = pdoc;
pd.Document.DefaultPageSettings.PaperSize = psize;
//pdoc.DefaultPageSettings.PaperSize.Height =320;
pdoc.DefaultPageSettings.PaperSize.Height = 820;
pdoc.DefaultPageSettings.PaperSize.Width = 520;
pdoc.PrintPage += new PrintPageEventHandler(pdoc_PrintPage);
DialogResult result = pd.ShowDialog();
if (result == DialogResult.OK)
{
PrintPreviewDialog pp = new PrintPreviewDialog();
pp.Document = pdoc;
//pp.Dispose();
result = pp.ShowDialog();
if (result == DialogResult.OK)
{
pdoc.Print();
}
}
}
void pdoc_PrintPage(object sender, PrintPageEventArgs e)
{
Graphics graphics = e.Graphics;
Font font = new Font("Courier New", 10);
float fontHeight = font.GetHeight();
int startX = 50;
int startY = 55;
int Offset = 40;
graphics.DrawString("Reference:", new Font("Courier New", 14), new SolidBrush(Color.Black), startX, startY + Offset);
Offset = Offset + 20;
graphics.DrawString(this.RefrencePro, new Font("Courier New", 6), new SolidBrush(Color.Black), startX, startY + Offset);
Offset = Offset + 20;
}
它的打印非常完美,但是当我打印时,单词会出现在图片中所示的绝版页面上。我在Microsoft One Note中打印。他们以任何方式限制这一点,并在Page范围结束后在新行(Make reference address multiline)中进行引用吗?
答案 0 :(得分:1)
您需要先调用fiddle,以便确定适合多行所有文本所需的矩形。您需要按如下方式调整代码:
for (var i = 0; i < data.length; i++) {
for (var j = 0; j < data[i].state.length; j++) {
if(data[i].state[j].state_code === "AD1"){
console.log(data[i].state[j].state_description)
}
};
};