C# 多页打印(附代码)

1 篇文章 0 订阅
1 篇文章 0 订阅
int b = 0;
int c = 0;
int d = 0;
private void form2_Load(object sender, EventArgs e)
{
    foreach (PaperSize ps5 in pdc.PrinterSettings.PaperSizes)
    {
        if (ps5.PaperName == "A4")
        {
            printDocument1.DefaultPageSettings.PaperSize = ps5;
        }
    }
    int a = Ds.Tables[0].Rows.Count;   //a 原始总共有多少行
    if (a % 16 == 0)
        c = a / 16;  //c 计算共有多少页,每16笔分页
    else
        c = a / 16 + 1;            
    printPreviewControl1.Zoom = 1.0;
    printPreviewControl1.Document = pdc;
    pdc.DocumentName = c.ToString(); //此处显示共多少页
    b = 0;
    d = c;
    pdc.PrintPage += new PrintPageEventHandler(zdy); //使用自定义 zdy

}


private void zdy(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
    y = 381;
    for (int p = 0; p < k; p++)
    {
        y += 18;
        e.Graphics.DrawString(Ds.Tables[0].Rows[0]["请购原因详细说明"].ToString().Trim().Substring(55 * p, 55) + '\r' + '\n', PrintFont, Brushes.Black, 20, y, new StringFormat());//因每行的长度是55,故55是固定不变的
    }
    e.Graphics.DrawString(Ds.Tables[0].Rows[0]["请购原因详细说明"].ToString().Trim().Substring(55 * k, m - 55 * k) + '\r' + '\n', PrintFont, Brushes.Black, 20, 399 + 18 * k, new StringFormat());//最后一点尾数的字符处理
    e.Graphics.DrawString(Ds.Tables[0].Rows[0]["请购单号"].ToString().Trim(), PrintFont, Brushes.Black, 80, 780, new StringFormat());  //请购单号
    b += 1;


    if (b < d)
        e.HasMorePages = true;  //此处决定是否打印多页内容
    else
        e.HasMorePages = false;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值