san san

san san

  • NA
  • 4
  • 5.1k

Printing Dot Matrix Dynamic Papersize

Jun 8 2015 4:16 AM
Hi Guys,
 
i have problem to print dot matrix using C#. My problem is that some how i cant set the paper size dynamically. For example, if the user only bought 1 item, my program will print the bill as big as the default paper size on printdialog (A4,letter,etc). 
 
I'm trying to print as much as its needed (paper size dynamic) by using this code below:
printDoc.DefaultPageSettings.PaperSize = new PaperSize("First custom size", 830, paperheight);
 
my program will print the bill and eject the paper as long as A4 size paper (Default paper size on the printdialog is A4). Is there anyway i can fix this. or is there anyway i can set the papersize. Because the project will use Epson LX 300+ with roll paper. Thanks in advance
 
 
NB : here is my code
 
public Form1()
{
InitializeComponent();
}
public void printrecipe()
{
PrintDialog printDia = new PrintDialog();
PrintDocument printDoc = new PrintDocument();
printDia.Document = printDoc;
printDoc.DefaultPageSettings.PaperSize = new PaperSize("First custom size", 830, 100);
printDoc.PrintPage +=new PrintPageEventHandler(printDoc_PrintPage);
DialogResult result = printDia.ShowDialog();
if (result == DialogResult.OK)
{
printDoc.Print();
}
}
void printDoc_PrintPage(object sender, PrintPageEventArgs e)
{
e.PageSettings.PaperSize = new PaperSize("First custom size", 830, 100);
Graphics graphic = e.Graphics;
Font barcode20 = new Font("Free 3 of 9 Extended", 21);
Font code3920 = new Font("Bar-Code 39", 14);
Font namabar = new Font("Agency FB", 6);
Font price = new Font("Times New Roman", 8);
Font code = new Font("Agency FB", 6);
int startX = 10;
int offset = 40;
string space40 = " "; // barcode20 40space 21 43space
graphic.DrawString("STLA RED KID BOBOIBOY 1-3",namabar , new SolidBrush(Color.Black), startX, offset);
graphic.DrawString(textBox1.Text+space40+"BM09", code, new SolidBrush(Color.Black), startX, offset+namabar.GetHeight()); //40spaces
graphic.DrawString("*" + textBox1.Text + "*", code3920, new SolidBrush(Color.Black), startX, offset + namabar.GetHeight() + code.GetHeight());
graphic.DrawString("50,500", price, new SolidBrush(Color.Black), startX, offset + namabar.GetHeight() + code3920.GetHeight() + code.GetHeight());
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (Convert.ToInt32(e.KeyChar) == 13)
{
printrecipe();
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
textBox2.Text = textBox1.Text;
}
}
 
 
 
 
Best Regards,
 
 
San