C#从1个表单上的两台打印机打印文档

时间:2018-01-04 13:27:50

标签: c# pdf printing printers

在1表格上我有两个按钮(一个用于打印到PDF打印机,第二个用于普通打印机)。我打印一些位图图像。但是程序的行为很奇怪。有时两个按钮都按预期工作。有时普通打印机打印空白,而pdf打印正常,有时普通打印机不打印任何内容,而pdf打印机打印一些“代码”。

在我的代码下面

    private void printBtn_Click(object sender, EventArgs e)
            { ... BmpToPrint = new Bitmap(tmp_bmp);
              tmp_bmp.Dispose();
              string file = "sometext";

              pdoc.PrinterSettings.PrinterName = System.Configuration.ConfigurationManager.AppSettings["Printer"];
              pdoc.DocumentName = file;
              pdoc.DefaultPageSettings.Landscape = false;

              ppv.Document = pdoc; //printpreviewdialog ppv, printdocument pdoc
              printDialog1.Document = pdoc;

                if (printDialog1.PrinterSettings.IsValid) { pdoc.Print(); } }


    private void printPdfBtn_Click(object sender, EventArgs e)
            {... BmpToPrint = new Bitmap(tmp_bmp);
              tmp_bmp.Dispose();

                string file = "sometext" + ".pdf";
                if (!Directory.Exists(directory)) { directory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); }

                pdoc.PrinterSettings.PrinterName = System.Configuration.ConfigurationManager.AppSettings["PdfPrinter"];
                pdoc.PrinterSettings.PrintToFile = true;
                pdoc.DocumentName = file;
                pdoc.PrinterSettings.PrintFileName = Path.Combine(directory, file);
                pdoc.DefaultPageSettings.Landscape = false;

                ppv.Document = pdoc;
                printDialog1.Document = pdoc;
                if (printDialog1.PrinterSettings.IsValid) { pdoc.Print(); } }


private void pdoc_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            e.Graphics.Clear(Color.White);
            Point PktWst = new Point(5, 0);
            e.Graphics.DrawImage(BmpToPrint, PktWst);
            e.HasMorePages = false;
        }

sometimes in pdf instead of image appears this

有时它可以完美地将图像打印到pdf和打印机,而有时与以前相同的图像不打印/空白打印/或pdf具有此工件。

在使用第二台打印机或以某种方式清理某些数据时,我应该重置某些设置吗?

0 个答案:

没有答案