如何从WPF控件打印发票
我正在WPF中创建一个销售点系统。我想在订单完成时打印发票。数据将从发票文本框中提供:如何从WPF控件打印发票,wpf,image,barcode-printing,Wpf,Image,Barcode Printing,我正在WPF中创建一个销售点系统。我想在订单完成时打印发票。数据将从发票文本框中提供:txtinvoices、txtQty、txtTotalPrice、txtAmountPaid和txtDate是我想在发票上打印的一些文本框。对于需要在发票上打印的每个订单,也有一个条形码图像 我能够使用flow文档打印所有内容。但是我无法打印这个条形码图像 //InvoiceID Generate txtInvoiceID.Text = DateTime.Now.ToString("sMMHHmyyyydd"
txtinvoices
、txtQty
、txtTotalPrice
、txtAmountPaid
和txtDate
是我想在发票上打印的一些文本框。对于需要在发票上打印的每个订单,也有一个条形码图像
我能够使用flow文档打印所有内容。但是我无法打印这个条形码图像
//InvoiceID Generate
txtInvoiceID.Text = DateTime.Now.ToString("sMMHHmyyyydd" + userId);
//Barcode Generation
BarcodeEncoder enc = new BarcodeEncoder();
WriteableBitmap image = enc.Encode(BarcodeFormat.Code39, txtInvoiceID.Text);
barCodeImage.Source = image;
有人能帮我用WPF打印吗?在我的脑海中,使用下面的代码(未经测试)
我不知道为什么,但它给了我错误:无法隐式地将类型“System.Windows.Media.Imaging.WriteableBitmap”转换为“System.Drawing.Bitmap”
//InvoiceID Generate
txtInvoiceID.Text = DateTime.Now.ToString("sMMHHmyyyydd" + userId);
//Barcode Generation
BarcodeEncoder enc = new BarcodeEncoder();
System.Windows.Controls.Image imgBarCode = new System.Windows.Controls.Image();
System.Drawing.Bitmap bm = enc.Encode(BarcodeFormat.Code39, txtInvoiceID.Text);
using (MemoryStream ms = new MemoryStream())
{
bm.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
byte[] byteImage = ms.ToArray();
Convert.ToBase64String(byteImage);
imgBarCode.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(byteImage);
}
// do whatever you want with imgBarCode now.