hello experts How Can i set PrindCoument so that it can print on 210mm x 90 mm paper centrally In Landscape Mode.
i have written the following Methods.On A4 Size paper, portrait Orientation it prints ok,
what is wrong is that i used A4 instead of actual size 210mm x 90 mm ( Widthxheight) , bad practise
loading the paper in printer (Samsung ML-1520 or Hp 1218nf) the printer paper left/right guide automaticaly centers the paper
but as experts can see that page is 210mm x 90 mm ( Widthxheight) Landscape Size,
How Can i modify my methods ChequePrint( false) to tell them my paer size & orientation
in the above method if i set the pd.DefaultPageSettings.Landscape = true;
it prints to far left (0,0) left/ top.
private void ChequePrint( bool ispreview)
{
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(this.pd_Printcheque);
try
{
if (ispreview)
{
PrintPreviewDialog pp = new PrintPreviewDialog();
pp.Document = pd;
pp.FormBorderStyle = FormBorderStyle.Fixed3D;
pp.SetBounds(20, 20, this.Width, this.Height);
pp.ShowDialog();
}
else
pd.Print();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
//chequePrint
private void pd_Printcheque(object sender, PrintPageEventArgs ev)
{
ev.Graphics.PageUnit = GraphicsUnit.Millimeter;
ev.PageSettings.HardMarginY);
Font printFont =new Font("Arial Bold", 12);;
float XDate = 0, yDate = 0, XPay = 0, yPay = 0, XRupeesInWord = 0, yRupeesInWord = 0, XRupeesInAmt = 0, yRupeesInAmt = 0;
int namewidth=0, AmtWidth=0;
try
{
DataRow[] rows = ds.Tables["dayBookchequePara"].Select("daybookno='" + cmbDayBooks.SelectedValue + "'");
if (rows.Count() > 0)
{
foreach (DataRow r in rows)
{
float.TryParse(r["date_x"].ToString(),out XDate) ;
float.TryParse(r["date_y"].ToString(), out yDate);
float.TryParse(r["pay_x"].ToString(), out XPay);
float.TryParse(r["pay_y"].ToString(), out yPay);
int.TryParse(r["namewidth"].ToString(), out namewidth);
float.TryParse(r["amtWord_x"].ToString(), out XRupeesInWord) ;
float.TryParse(r["amtWord_y"].ToString(), out yRupeesInWord);
float.TryParse(r["amt_x"].ToString(), out XRupeesInAmt);
float.TryParse(r["amt_y"].ToString(), out yRupeesInAmt);
int.TryParse(r["AmtWidth"].ToString(), out AmtWidth);
break;
}
ev.Graphics.DrawString(dtpDocDate.Value.ToString("dd/MM/yyyy"), printFont, Brushes.Black, XDate, yDate, new StringFormat());
string name = txtChqName.Text.Trim(), name2 = "";
if (string.IsNullOrWhiteSpace(name))
name = txtSLName.Text;
if (string.IsNullOrWhiteSpace(name))
name = txtGLName.Text;
if (name.Length > namewidth)
{
name2 = name.Substring(namewidth + 1);
name = name.Substring(0, namewidth);
}
ev.Graphics.DrawString(name, printFont, Brushes.Black, XPay, yPay, new StringFormat());
if ( name2 != "")
ev.Graphics.DrawString(name2, printFont, Brushes.Black, XPay, yPay+printFont.Height, new StringFormat());
ev.Graphics.DrawString(txtAmt.Text, printFont, Brushes.Black, XRupeesInAmt, yRupeesInAmt, new StringFormat());
NumberToIndian amtinword = new NumberToIndian();
string word = amtinword.changeCurrencyToWords(txtAmt.Text)+" Only", word2 = "";
if (word.Length > AmtWidth)
{
word2= word.Substring(AmtWidth+1);
word=word.Substring(0,AmtWidth);
}
ev.Graphics.DrawString(word, printFont, Brushes.Black, XRupeesInWord, yRupeesInWord, new StringFormat());
if ( word2 != "")
ev.Graphics.DrawString(word2, printFont, Brushes.Black, XRupeesInWord, yRupeesInWord + printFont.Height, new StringFormat());
}
else
{
MessageBox.Show(@"Cheque Paratmers Not Found in Feed/Master/Daybooks");
}
ev.HasMorePages = false;
}
catch (Exception Ex)
{
MessageBox.Show("err in pd_PrintPage:-"+Ex.ToString());
}
}