{
PrintDialog printDialog = new();
printDialog.Document = printDocumentCustomer;
printDocumentCustomer.Print();
printDialog = new();
printDialog.Document = printDocumentMerchant;
printDocumentMerchant.Print();
}
private void DrawGraphics(PrintPageEventArgs e, string copyOf){
Graphics g = e.Graphics;
Font font = new("Courier New", 12, FontStyle.Bold);
StringFormat center = new(StringFormatFlags.FitBlackBox);
center.Alignment = StringAlignment.Center;
int y = 0;
g.DrawString($"** {Task.Run(async () => await CommonData.GetById("LocationTable", locationId)).Result.FirstOrDefault().Name} **", new Font("Courier New", 20, FontStyle.Bold), Brushes.Black, 25, y += 10);
g.DrawString($"----- {copyOf} Copy -----", font, Brushes.Black, 10, y += 40);
g.DrawString($"Slip No.: {slipId}", font, Brushes.Black, 10, y += 25);
g.DrawString($"DT: {transaction.DateTime.ToString("dd/MM/yy HH:mm")}", font, Brushes.Black, 10, y += 25);
g.DrawString($"Name: {Task.Run(async () => await PersonData.GetPersonByNumber(numberTextBox.Text)).Result.FirstOrDefault().Name}", font, Brushes.Black, 10, y += 20);
g.DrawString($"Contact: {numberTextBox.Text}", font, Brushes.Black, 10, y += 20);
if (loyaltyCheckBox.Checked) g.DrawString("Loyalty Member", font, Brushes.Black, 10, y += 20);
g.DrawString($"Reservation: {Task.Run(async () => await CommonData.GetById("ReservationTypeTable", transaction.ReservationType)).Result.FirstOrDefault().Name}", font, Brushes.Black, 10, y += 20);
g.DrawString("--------------------------", font, Brushes.Black, 10, y += 20);
g.DrawString($"Total Persons: {transaction.Male + transaction.Female}", font, Brushes.Black, 10, y += 20);
g.DrawString("Male\tFemale", font, Brushes.Black, 10, y += 20);
g.DrawString($"{transaction.Male}\t{transaction.Female}", font, Brushes.Black, 10, y += 20);
g.DrawString("--------------------------", font, Brushes.Black, 10, y += 20);
g.DrawString($"Total: {transaction.Cash + transaction.Card + transaction.UPI + transaction.Amex}", new("Courier New", 15, FontStyle.Bold), Brushes.Black, 10, y += 20);
g.DrawString($"{MakeStringHeaderAmount(transaction)}", font, Brushes.Black, 10, y += 20);
g.DrawString($"{MakeStringAmount(transaction)}", font, Brushes.Black, 10, y += 20);
g.DrawString("--------------------------", font, Brushes.Black, 10, y += 20);
if (transaction.ApprovedBy != null) g.DrawString($"Approved By: {transaction.ApprovedBy}", font, Brushes.Black, 10, y += 20);
g.DrawString($"Entered By: {Task.Run(async () => await CommonData.GetById("EmployeeTable", transaction.EmployeeId)).Result.FirstOrDefault().Name}", font, Brushes.Black, 10, y += 20);
g.DrawString("This coupon is non-transferable", new Font("Courier New", 8, FontStyle.Bold), Brushes.Black, 8, y += 30);
g.DrawString("to any person or any other outlet.", new Font("Courier New", 8, FontStyle.Bold), Brushes.Black, 8, y += 10);
g.DrawString("This coupon is to be redeemed", new Font("Courier New", 8, FontStyle.Bold), Brushes.Black, 8, y += 10);
g.DrawString("until the end of the operations", new Font("Courier New", 8, FontStyle.Bold), Brushes.Black, 8, y += 10);
g.DrawString("of the particular night:", new Font("Courier New", 8, FontStyle.Bold), Brushes.Black, 8, y += 10);
g.DrawString($"{transaction.DateTime.ToString("dd/MM/yy HH:mm")}", new Font("Courier New", 8, FontStyle.Bold), Brushes.Black, 8, y += 10);
g.DrawString("The hotel does not take liability", new Font("Courier New", 8, FontStyle.Bold), Brushes.Black, 8, y += 10);
g.DrawString("or responsibility if the coupon", new Font("Courier New", 8, FontStyle.Bold), Brushes.Black, 8, y += 10);
g.DrawString("is lost by the guest", new Font("Courier New", 8, FontStyle.Bold), Brushes.Black, 8, y += 10);
PaperSize ps58 = new("58mm Thermal", 220, y += 20);
printDocumentCustomer.DefaultPageSettings.PaperSize = ps58;
e.HasMorePages = false;}
private void printDocumentCustomer_PrintPage(object sender, PrintPageEventArgs e)
{
DrawGraphics(e, "Customer");
}
private void printDocumentMerchant_PrintPage(object sender, PrintPageEventArgs e)
{
DrawGraphics(e, "Merchant");
}
Этот код печатает содержимое на термопринтере, но после некоторых отпечатков обрезает правую сторону отпечатка. Ошибка возникает только в одной из копий. Какие могут быть возможные решения и почему это происходит. Сохраняется ли перезапуск диспетчера очереди печати после каждого сохранения? Помогите?
Распечатать копии
private void DrawGraphics(PrintPageEventArgs e, string copyOf){ Graphics g = e.Graphics; Font font = new("Courier New", 12, FontStyle.Bold);
StringFormat center = new(StringFormatFlags.FitBlackBox); center.Alignment = StringAlignment.Center;
int y = 0; g.DrawString($"** {Task.Run(async () => await CommonData.GetById("LocationTable", locationId)).Result.FirstOrDefault().Name} **", new Font("Courier New", 20, FontStyle.Bold), Brushes.Black, 25, y += 10); g.DrawString($"----- {copyOf} Copy -----", font, Brushes.Black, 10, y += 40); g.DrawString($"Slip No.: {slipId}", font, Brushes.Black, 10, y += 25); g.DrawString($"DT: {transaction.DateTime.ToString("dd/MM/yy HH:mm")}", font, Brushes.Black, 10, y += 25); g.DrawString($"Name: {Task.Run(async () => await PersonData.GetPersonByNumber(numberTextBox.Text)).Result.FirstOrDefault().Name}", font, Brushes.Black, 10, y += 20); g.DrawString($"Contact: {numberTextBox.Text}", font, Brushes.Black, 10, y += 20); if (loyaltyCheckBox.Checked) g.DrawString("Loyalty Member", font, Brushes.Black, 10, y += 20); g.DrawString($"Reservation: {Task.Run(async () => await CommonData.GetById("ReservationTypeTable", transaction.ReservationType)).Result.FirstOrDefault().Name}", font, Brushes.Black, 10, y += 20);
g.DrawString("--------------------------", font, Brushes.Black, 10, y += 20); g.DrawString($"Total Persons: {transaction.Male + transaction.Female}", font, Brushes.Black, 10, y += 20); g.DrawString("Male\tFemale", font, Brushes.Black, 10, y += 20); g.DrawString($"{transaction.Male}\t{transaction.Female}", font, Brushes.Black, 10, y += 20);
g.DrawString("--------------------------", font, Brushes.Black, 10, y += 20); g.DrawString($"Total: {transaction.Cash + transaction.Card + transaction.UPI + transaction.Amex}", new("Courier New", 15, FontStyle.Bold), Brushes.Black, 10, y += 20); g.DrawString($"{MakeStringHeaderAmount(transaction)}", font, Brushes.Black, 10, y += 20); g.DrawString($"{MakeStringAmount(transaction)}", font, Brushes.Black, 10, y += 20);
g.DrawString("--------------------------", font, Brushes.Black, 10, y += 20); if (transaction.ApprovedBy != null) g.DrawString($"Approved By: {transaction.ApprovedBy}", font, Brushes.Black, 10, y += 20); g.DrawString($"Entered By: {Task.Run(async () => await CommonData.GetById("EmployeeTable", transaction.EmployeeId)).Result.FirstOrDefault().Name}", font, Brushes.Black, 10, y += 20);
g.DrawString("This coupon is non-transferable", new Font("Courier New", 8, FontStyle.Bold), Brushes.Black, 8, y += 30); g.DrawString("to any person or any other outlet.", new Font("Courier New", 8, FontStyle.Bold), Brushes.Black, 8, y += 10); g.DrawString("This coupon is to be redeemed", new Font("Courier New", 8, FontStyle.Bold), Brushes.Black, 8, y += 10); g.DrawString("until the end of the operations", new Font("Courier New", 8, FontStyle.Bold), Brushes.Black, 8, y += 10); g.DrawString("of the particular night:", new Font("Courier New", 8, FontStyle.Bold), Brushes.Black, 8, y += 10); g.DrawString($"{transaction.DateTime.ToString("dd/MM/yy HH:mm")}", new Font("Courier New", 8, FontStyle.Bold), Brushes.Black, 8, y += 10); g.DrawString("The hotel does not take liability", new Font("Courier New", 8, FontStyle.Bold), Brushes.Black, 8, y += 10); g.DrawString("or responsibility if the coupon", new Font("Courier New", 8, FontStyle.Bold), Brushes.Black, 8, y += 10); g.DrawString("is lost by the guest", new Font("Courier New", 8, FontStyle.Bold), Brushes.Black, 8, y += 10);
private void printDocumentMerchant_PrintPage(object sender, PrintPageEventArgs e) { DrawGraphics(e, "Merchant"); } [/code] Этот код печатает содержимое на термопринтере, но после некоторых отпечатков обрезает правую сторону отпечатка. Ошибка возникает только в одной из копий. Какие могут быть возможные решения и почему это происходит. Сохраняется ли перезапуск диспетчера очереди печати после каждого сохранения? Помогите? Распечатать копии