I have made this program for one of my client,who want to give one print command to print a document on different printers in different location simultaneously which are connected to server. RPC should be activated on server to use this program.
- string FilePath = strPathToUpload + "\\" + fUpload.FileName;
- if (strExt.ToUpper().Equals("TXT"))
- {
- fUpload.SaveAs(strPathToUpload + "\\" + fUpload.FileName);
- Printer1(FilePath);
- Printer2(FilePath);
- }
- else
- {
- lblMessage.Text="Invalid File Seleected";
- }
- public void Printer1(string FilePath)
- {
- sr = new StreamReader(FilePath);
- f = new Font("Courier New", 14);
- PrintDocument pd = new PrintDocument();
- pd.PrintPage += new PrintPageEventHandler(pqr);
- pd.PrinterSettings.PrinterName = "PDF995";
- if (pd.PrinterSettings.IsValid)
- {
- pd.Print();
- }
- sr.Close();
- }
- public void Printer2(string FilePath)
- {
- sr = new StreamReader(FilePath);
- f = new Font("Courier New", 14);
- PrintDocument pd2 = new PrintDocument();
- pd2.PrintPage += new PrintPageEventHandler(pqr);
- pd2.PrinterSettings.PrinterName = "Real PDF Printer";
- if (pd2.PrinterSettings.IsValid)
- {
- pd2.Print();
- }
- sr.Close();
- }
- void pqr(object o, PrintPageEventArgs e)
- {
- float lpp = e.MarginBounds.Height / f.GetHeight(e.Graphics);
- int c = 0;
- String s = null;
- while (c < lpp && ((s = sr.ReadLine()) != null))
- {
- float y = e.MarginBounds.Top + (c * f.GetHeight(e.Graphics));
- e.Graphics.DrawString(s, f, Brushes.Black, e.MarginBounds.Left, y);
- c++;
- }
- if (s != null)
- e.HasMorePages = true;
- else
- e.HasMorePages = false;
- }