打印系统开发(17)——C#打印操作 页面设置 打印机选择 打印预览

mac2025-05-15  13

private void CreateIDCardSample()         {             string ImageFile = Setting.GetPhotoFolder() + "\\" + lblIDCard.Text + ".jpg";             Bitmap bmTest = new Bitmap(3508, 2479);              Graphics g = Graphics.FromImage(bmTest);             g.Clear(Color.White);             int baseWidth = 713, baseHeight = 1036;             int manWidth = 313, manHeight = 386;             Rectangle recBase1 = new Rectangle(200, 200, baseWidth, baseHeight);             string ImageBaseFile1 = Application.StartupPath + "\\Image\\Badge Regular_gaitubao_com_464x731.png";             g.DrawImage(Image.FromFile(ImageBaseFile1), recBase1);             Rectangle recMan1 = new Rectangle(400, 480, manWidth, manHeight);             g.DrawImage(Image.FromFile(ImageFile), recMan1);             Font font = FrmMain.DefaultFont;//  "微软雅黑";             Font fnt = new Font("微软雅黑", 22, FontStyle.Bold);             Brush bursh = Brushes.Black;             g.DrawString("中国", fnt, bursh, 500, 1050);             g.DrawString("china", fnt, bursh, 450, 1100);             g.DrawString("8600", fnt, bursh, 500, 1150);             string TempImageFile1 = Application.StartupPath + "\\Image\\temp1.jpg";             bmTest.Save(TempImageFile1);             PrintDocument printDocument;             printDocument = new PrintDocument();             PageSetupDialog pageSetupDialog = new PageSetupDialog();             foreach (PaperSize ps in printDocument.PrinterSettings.PaperSizes)             {                  if (ps.Kind == PaperKind.A4)                 {                     printDocument.DefaultPageSettings.PaperSize = ps;                     break;                 }             }             printDocument.DefaultPageSettings.Landscape = true;             pageSetupDialog.Document = printDocument;             pageSetupDialog.ShowDialog();             PrintDialog printDialog1 = new System.Windows.Forms.PrintDialog();             if (printDialog1.ShowDialog() == DialogResult.OK)//弹出选择印表机的窗体             {                 printDocument.PrinterSettings.PrinterName = printDialog1.PrinterSettings.PrinterName;             }             PrintPreviewDialog printPreviewDialog = new PrintPreviewDialog();             printPreviewDialog.Document = printDocument;             printDocument.PrintPage += new PrintPageEventHandler(this.printDocument1_PrintPage);             try             {               printPreviewDialog.ShowDialog();             }             catch (Exception excep)             {                MessageBox.Show(excep.Message, "打印出错", MessageBoxButtons.OK, MessageBoxIcon.Error);             }               }         private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)         {             string TempImageFile1 = Application.StartupPath + "\\Image\\temp1.jpg";             //e.Graphics.DrawImage(Image.FromFile(TempImageFile1), 3508, 2479);             Rectangle recBase5 = new Rectangle(0, 0, 1178, 833);             e.Graphics.DrawImage(Image.FromFile(TempImageFile1), recBase5);             打印内容 为 自定义文本内容             //Font font = new Font("宋体", 12);             //Brush bru = Brushes.Blue;             //for (int i = 1; i <= 5; i++)             //{             //    e.Graphics.DrawString("打印啦意大利啦啦啦", font, bru, 0, i * 20);             //}         }

 

最新回复(0)