我正在嘗試優化代碼并對舊的現有代碼進行一些更改。我必須實作從服務器端到客戶端的列印賬單我嘗試了太多方法但我沒有找到任何一個這是我的代碼
public void Print()
{
var doc = new PrintDocument();
string pkInstalledPrinters = string.Empty;
//var doc = new PrintDocument();
for (int i = 0; i < PrinterSettings.InstalledPrinters.Count;)
{
pkInstalledPrinters = PrinterSettings.InstalledPrinters[i];
break;
//comboInstalledPrinters.Items.Add(pkInstalledPrinters);
}
// doc.PrinterSettings.PrinterName = "\\\\W95053\\P12562PCL";
doc.PrinterSettings.PrinterName = pkInstalledPrinters;
doc.PrinterSettings.Copies = 2;
doc.PrintPage = new PrintPageEventHandler(ProvideContent);
doc.Print();
doc.Print();
這是用于列印的服務器端代碼
public void ProvideContent(object sender, PrintPageEventArgs e)
{
DateTime koDate = DateTime.Now.AddMinutes(-320);
string totalAmount = TotalAmount.Value;
//e.Graphics.DrawString("7 Plates Restaurant", new Font("Arial", 12), Brushes.Black, 50, 0);
//e.Graphics.DrawString("Item", new Font("Arial", 11), Brushes.Black, 15, 30);
//e.Graphics.DrawString("Qty", new Font("Arial", 11), Brushes.Black, 150, 30);
//e.Graphics.DrawString("Rate", new Font("Arial", 11), Brushes.Black, 185, 30);
string addressLine1 = hotel.Address;
string addressLine2 = "Bangalore 560046";
string phoneNo = "PH – " hotel.PhoneNo;
string date = koDate.Date.ToShortDateString();
string tin = "29061276984";
string time = koDate.ToShortTimeString();
string cashier = "Sameer";
e.Graphics.DrawString("7 Plates", new Font("Cambria", 24, FontStyle.Bold), Brushes.Black, 60, 0);
e.Graphics.DrawString("Restaurant", new Font("Cambria", 11), Brushes.Black, 90, 40);
e.Graphics.DrawString(addressLine1, new Font("Cambria", 11), Brushes.Black, 10, 60);
e.Graphics.DrawString(addressLine2, new Font("Cambria", 11), Brushes.Black, 65, 75);
e.Graphics.DrawString(phoneNo, new Font("Cambria", 11), Brushes.Black, 20, 90);
// e.Graphics.DrawString(webSite, new Font("Cambria", 11), Brushes.Black, 70, 90);
e.Graphics.DrawString("Order No: " orderNumber, new Font("Cambria", 11, FontStyle.Bold), Brushes.Black, 0, 110);
e.Graphics.DrawString("Bill No: " billNumber, new Font("Cambria", 11), Brushes.Black, 170, 110);
e.Graphics.DrawString("Date: " date, new Font("Cambria", 11), Brushes.Black, 0, 125);
e.Graphics.DrawString("Time: " time, new Font("Cambria", 11), Brushes.Black, 170, 125);
e.Graphics.DrawString("Tin: " tin, new Font("Cambria", 11), Brushes.Black, 0, 140);
e.Graphics.DrawString("No.", new Font("Cambria", 11, FontStyle.Bold), Brushes.Black, 0, 160);
e.Graphics.DrawString("Item", new Font("Cambria", 11, FontStyle.Bold), Brushes.Black, 25, 160);
e.Graphics.DrawString("Qty", new Font("Cambria", 11, FontStyle.Bold), Brushes.Black, 140, 160);
e.Graphics.DrawString("Rate", new Font("Cambria", 11, FontStyle.Bold), Brushes.Black, 175, 160);
e.Graphics.DrawString("Total", new Font("Cambria", 11, FontStyle.Bold), Brushes.Black, 220, 160);
int xAxis = 0;
int yAxis = 180;
int itemNo = 0;
int totalValue = 0;
foreach (DayEntryHR item in dayEntryList)
{
itemNo ;
string no = Convert.ToString(itemNo) ".";
string itemName = item.MasterItem.Item;
int rateMaster = item.MasterItem.KORate;
double rate1 = Convert.ToInt32(rateMaster / 1.12) 1;
string rate = Convert.ToString(rate1);
string total = Convert.ToString(rate1 * item.Quantity);
string quantity = Convert.ToString(item.Quantity);
totalValue = totalValue Convert.ToInt32(total);
//e.Graphics.DrawString(
// "Hello world",
// new Font("Arial", 12),
// Brushes.Black,
// e.MarginBounds.Left,
// e.MarginBounds.Top);
e.Graphics.DrawString(no, new Font("Cambria", 11), Brushes.Black, xAxis, yAxis);
xAxis = xAxis 25;
e.Graphics.DrawString(itemName, new Font("Cambria", 11), Brushes.Black, xAxis, yAxis);
xAxis = xAxis 120;
e.Graphics.DrawString(quantity, new Font("Cambria", 11), Brushes.Black, xAxis, yAxis);
xAxis = xAxis 30;
e.Graphics.DrawString(rate, new Font("Cambria", 11), Brushes.Black, xAxis, yAxis);
xAxis = xAxis 50;
e.Graphics.DrawString(total, new Font("Cambria", 11), Brushes.Black, xAxis, yAxis);
xAxis = 0;
yAxis = yAxis 15;
//e.Graphics.DrawString("2.", new Font("Cambria", 11), Brushes.Black, 0, 195);
//e.Graphics.DrawString(c, new Font("Cambria", 11), Brushes.Black, 25, 195);
//e.Graphics.DrawString("2", new Font("Cambria", 11), Brushes.Black, 145, 195);
//e.Graphics.DrawString("150", new Font("Cambria", 11), Brushes.Black, 175, 195);
//e.Graphics.DrawString("150", new Font("Cambria", 11), Brushes.Black, 225, 195);
//e.Graphics.DrawString("3.", new Font("Cambria", 11), Brushes.Black, 0, 210);
//e.Graphics.DrawString(d, new Font("Cambria", 11), Brushes.Black, 25, 210);
//e.Graphics.DrawString("5", new Font("Cambria", 11), Brushes.Black, 145, 210);
//e.Graphics.DrawString("150", new Font("Cambria", 11), Brushes.Black, 175, 210);
//e.Graphics.DrawString("300", new Font("Cambria", 11), Brushes.Black, 225, 210);
//e.Graphics.DrawString("4.", new Font("Cambria", 11), Brushes.Black, 0, 225);
//e.Graphics.DrawString(f, new Font("Cambria", 11), Brushes.Black, 25, 225);
//e.Graphics.DrawString("2", new Font("Cambria", 11), Brushes.Black, 145, 225);
//e.Graphics.DrawString("110", new Font("Cambria", 11), Brushes.Black, 175, 225);
//e.Graphics.DrawString("220", new Font("Cambria", 11), Brushes.Black, 225, 225);
}
int vat = ((totalValue * 12) / 100);
//e.Graphics.DrawString("Vat 5.5%:", new Font("Cambria", 11, FontStyle.Bold), Brushes.Black, 140, yAxis 5);
//e.Graphics.DrawString(Convert.ToString(Vat), new Font("Cambria", 11), Brushes.Black, 220, yAxis 5);
e.Graphics.DrawString("Total:", new Font("Cambria", 11, FontStyle.Bold), Brushes.Black, 140, yAxis 5);
e.Graphics.DrawString(Convert.ToString(totalValue), new Font("Cambria", 11), Brushes.Black, 220, yAxis 5);
e.Graphics.DrawString("Pay By: Cash", new Font("Cambria", 11, FontStyle.Bold), Brushes.Black, 140, yAxis 23);
e.Graphics.DrawString("To provide feedback call us", new Font("Cambria", 11), Brushes.Black, 35, yAxis 40);
e.Graphics.DrawString("Or", new Font("Cambria", 11), Brushes.Black, 100, yAxis 55);
e.Graphics.DrawString("Visit us on www.7plates.in", new Font("Cambria", 11), Brushes.Black, 37, yAxis 70);
e.Graphics.DrawString("Thank You", new Font("Cambria", 14, FontStyle.Bold), Brushes.Black, 75, yAxis 90);
string name = Customer.Value " " LastName.Value;
bool flag = false;
e.Graphics.DrawString(name, new Font("Cambria", 14), Brushes.Black, 75, yAxis 110);
if (Homedelevery.Checked == true)
{
string addressline1 = string.Empty;
string addressline2 = string.Empty;
string address = Address.Value;
if (address.Length > 28)
{
addressline1 = address.Substring(0, 28);
addressline2 = address.Substring(28);
flag = true;
}
e.Graphics.DrawString("Address:", new Font("Cambria", 11), Brushes.Black, 0, yAxis 140);
if (flag == true)
{
e.Graphics.DrawString(addressline1, new Font("Cambria", 11), Brushes.Black, 63, yAxis 140);
e.Graphics.DrawString(addressline2, new Font("Cambria", 11), Brushes.Black, 63, yAxis 160);
e.Graphics.DrawString("LandMark:", new Font("Cambria", 11), Brushes.Black, 0, yAxis 180);
e.Graphics.DrawString(Landmark.Value, new Font("Cambria", 11), Brushes.Black, 70, yAxis 180);
}
else
{
e.Graphics.DrawString(address, new Font("Cambria", 11), Brushes.Black, 63, yAxis 140);
e.Graphics.DrawString("LandMark:", new Font("Cambria", 11), Brushes.Black, 0, yAxis 160);
e.Graphics.DrawString(Landmark.Value, new Font("Cambria", 11), Brushes.Black, 73, yAxis 160);
}
}
if (Takeaway.Checked == true)
{
e.Graphics.DrawString("Phone:", new Font("Cambria", 11), Brushes.Black, 0, yAxis 140);
e.Graphics.DrawString(Phone1.Value, new Font("Cambria", 11), Brushes.Black, 50, yAxis 140);
e.Graphics.DrawString("TakeAway", new Font("Cambria", 14, FontStyle.Bold), Brushes.Black, 73, yAxis 160);
}
else if (Homedelevery.Checked == true)
{
if (flag == true)
{
e.Graphics.DrawString("Phone:", new Font("Cambria", 11), Brushes.Black, 0, yAxis 200);
e.Graphics.DrawString(Phone1.Value, new Font("Cambria", 11), Brushes.Black, 50, yAxis 200);
e.Graphics.DrawString("Home Delevery", new Font("Cambria", 14, FontStyle.Bold), Brushes.Black, 70, yAxis 220);
}
else
{
e.Graphics.DrawString("Phone:", new Font("Cambria", 11), Brushes.Black, 0, yAxis 180);
e.Graphics.DrawString(Phone1.Value, new Font("Cambria", 11), Brushes.Black, 50, yAxis 180);
e.Graphics.DrawString("Home Delevery", new Font("Cambria", 14, FontStyle.Bold), Brushes.Black, 70, yAxis 200);
}
}
Pen myPen = new Pen(System.Drawing.Color.Black, 1);
e.Graphics.DrawLine(myPen, 0, 176, 260, 176);
e.Graphics.DrawLine(myPen, 0, yAxis 5, 260, yAxis 5);
e.Graphics.DrawLine(myPen, 0, yAxis 21, 260, yAxis 21);
//e.Graphics.DrawString(no, new Font("Arial", 10), Brushes.Black, xAxis, yAxis);
//xAxis = xAxis 15;
//e.Graphics.DrawString(itemName, new Font("Arial", 10), Brushes.Black, xAxis, yAxis);
//xAxis = xAxis 145;
//e.Graphics.DrawString(quantity, new Font("Arial", 10), Brushes.Black, xAxis, yAxis);
//xAxis = xAxis 30;
//e.Graphics.DrawString(rate, new Font("Arial", 10), Brushes.Black, xAxis, yAxis);
//yAxis = yAxis 20;
//xAxis = 0;
}
我搜索了很多東西,我正在嘗試這樣做,但我無法傳遞我想列印的物件
protected void Submit(object sender, EventArgs e)
{
var doc = new PrintDocument();
doc.PrinterSettings.Copies = 2;
doc.PrintPage = new PrintPageEventHandler(ProvideContent);
//String msg = "alert('" doc "button)'";
ClientScript.RegisterStartupScript(this.GetType(), "alert", string.Format(@"
alert('u r inside a fucntion');
var prtwin = window.open('', 'PrintGridViewData', 'left=100,top=100,width=1000,height=100,tollbar=0,scrollbars=1,status=0,resizable=1');
prtwin.document.write('hello wolrd sjks');
prtwin.document.close();
prtwin.focus();
prtwin.print();
prtwin.close(); "
, new PrintPageEventHandler(ProvideContent)), true);
//ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('heelo world');", true);
}
感謝閱讀這個長問題
uj5u.com熱心網友回復:
每當您在 javascript 中使用列印物件時,我都會得到答案 ** 它讀起來像 HTML 頁面 **window.print();獲取整個頁面并列印但是當您
你可以看到我在下面的列印函式中寫了一個文本,我們可以像 html 頁面一樣撰寫和格式化,或者我們可以創建一個 html 頁面并傳遞然后列印該 html 頁面列印
prtwin.document.write('hello wolrd sjks')
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/385692.html
標籤:javascript 网站 网络 印刷
