【问题标题】:How to send all images of a folder to printer如何将文件夹的所有图像发送到打印机
【发布时间】:2014-03-20 18:07:42
【问题描述】:

我需要一次将文件夹中的所有图像发送到打印机。这可以从 Windows 资源管理器中选择所有图像文件,右键单击并选择打印以将所有选定的图像发送到打印对话框,从中我们可以选择打印机设置并继续打印。如何在 c# windows 窗体应用程序中执行此操作?

编辑:我想出了这个,但它只打印最后一页。我应该如何修改?

private void printAllCardSheetBtn_Click(object sender, EventArgs e) {

        PrintDocument pdoc = new PrintDocument();
        pdoc.DocumentName = "cardsheets";
        PrintDialog pd = new PrintDialog();
        if(pd.ShowDialog() == DialogResult.OK)
        {

            PrinterSettings ps = pd.PrinterSettings;
            pdoc.PrinterSettings = ps;


            pdoc.PrintPage += pdoc_PrintPage;
            pdoc.Print();
        }



    }

    void pdoc_PrintPage(object sender, PrintPageEventArgs e)
    {
         Graphics g = e.Graphics;
         string[] sheetpaths = Directory.GetFiles(_sheetDirectory);
         Point point = new Point(0, 0);
         foreach (string s in sheetpaths)
         {
             g.DrawImage(new Bitmap(s), point);

         }



    }

【问题讨论】:

    标签: c# printing


    【解决方案1】:

    您可以使用PrintDocument

    只需从文件夹中获取所有图像,将它们加载到 Bitmap 并通过 For Loop 使用 PrintDocument 一张一张地打印。

    顺便说一句,使用PrintPage 事件和PrintPageEventArgs,您可以在文档中绘制图像以使用图形打印。

    干杯

    编辑:检查这个例子 -> Example

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-31
      • 2020-05-29
      • 2020-05-19
      相关资源
      最近更新 更多