C# Programming
06-18-2009, 07:00 PM
Hello,
In my application, I want to print some informations.
I can print this informations with e.Graphics.DrawString () .
The problem that I want to print in the same page ,that contains informations printed with e.Graphics.DrawString () I want to print command PCL but the problem is that I have in the result 2 pages.
- the first one contains informations printed with e.Graphics.DrawString ().
- The second contains informations of PCL command
The problem that I want in the result 1 page that contains both information.
I send To you a part of my code:
code use e.Graphics.DrawString ():
PrintDocument Page = new PrintDocument(); Page.PrintPage += new PrintPageEventHandler(cardDocument_Page); Page.Print();
Code of cardDocument_Page(....):
e.Graphics.DrawString("String1", cardFont, Brushes.Black, 400, 300);
e.Graphics.DrawString("String2", cardFont, Brushes.Black, 500, 300);
Code that send commande directely to the printer:
DOCINFO di = new DOCINFO();
int pcWritten = 0;
PrintDirect.OpenPrinter("\\\\10.1.0.40\\HPLaserJ", ref lhPrinter, 0);
PrintDirect.StartDocPrinter(lhPrinter, 1, ref di);
PrintDirect.StartPagePrinter(lhPrinter);
string st1;
st1 = "\x1b**1M\x1b(14Y\x1b(s0p8.00h12.0v0s0b105T" + Strin+ "\x1b**0M";
PrintDirect.WritePrinter(lhPrinter, st1, st1.Length, ref pcWritten);
PrintDirect.EndPagePrinter(lhPrinter);
PrintDirect.EndDocPrinter(lhPrinter);
PrintDirect.ClosePrinter(lhPrinter);
classes used by PrintDirect:
public class PrintDirect { [DllImport("winspool.drv", CharSet = CharSet.Unicode, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
public static extern long OpenPrinter(string pPrinterName, ref IntPtr phPrinter, int pDefault);
[DllImport("winspool.drv", CharSet = CharSet.Unicode, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
public static extern long StartDocPrinter(IntPtr hPrinter, int Level, ref DOCINFO pDocInfo);
[DllImport("winspool.drv", CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern long StartPagePrinter(IntPtr hPrinter);
[DllImport("winspool.drv", CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern long WritePrinter(IntPtr hPrinter, string data, int buf, ref int pcWritten);
[DllImport("winspool.drv", CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern long EndPagePrinter(IntPtr hPrinter);
[DllImport("winspool.drv", CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern long EndDocPrinter(IntPtr hPrinter);
[DllImport("winspool.drv", CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern long ClosePrinter(IntPtr hPrinter);
I want to print informations (PCL and other) in the same page, but not in 2 pages.
Thank you for your Help.
In my application, I want to print some informations.
I can print this informations with e.Graphics.DrawString () .
The problem that I want to print in the same page ,that contains informations printed with e.Graphics.DrawString () I want to print command PCL but the problem is that I have in the result 2 pages.
- the first one contains informations printed with e.Graphics.DrawString ().
- The second contains informations of PCL command
The problem that I want in the result 1 page that contains both information.
I send To you a part of my code:
code use e.Graphics.DrawString ():
PrintDocument Page = new PrintDocument(); Page.PrintPage += new PrintPageEventHandler(cardDocument_Page); Page.Print();
Code of cardDocument_Page(....):
e.Graphics.DrawString("String1", cardFont, Brushes.Black, 400, 300);
e.Graphics.DrawString("String2", cardFont, Brushes.Black, 500, 300);
Code that send commande directely to the printer:
DOCINFO di = new DOCINFO();
int pcWritten = 0;
PrintDirect.OpenPrinter("\\\\10.1.0.40\\HPLaserJ", ref lhPrinter, 0);
PrintDirect.StartDocPrinter(lhPrinter, 1, ref di);
PrintDirect.StartPagePrinter(lhPrinter);
string st1;
st1 = "\x1b**1M\x1b(14Y\x1b(s0p8.00h12.0v0s0b105T" + Strin+ "\x1b**0M";
PrintDirect.WritePrinter(lhPrinter, st1, st1.Length, ref pcWritten);
PrintDirect.EndPagePrinter(lhPrinter);
PrintDirect.EndDocPrinter(lhPrinter);
PrintDirect.ClosePrinter(lhPrinter);
classes used by PrintDirect:
public class PrintDirect { [DllImport("winspool.drv", CharSet = CharSet.Unicode, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
public static extern long OpenPrinter(string pPrinterName, ref IntPtr phPrinter, int pDefault);
[DllImport("winspool.drv", CharSet = CharSet.Unicode, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
public static extern long StartDocPrinter(IntPtr hPrinter, int Level, ref DOCINFO pDocInfo);
[DllImport("winspool.drv", CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern long StartPagePrinter(IntPtr hPrinter);
[DllImport("winspool.drv", CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern long WritePrinter(IntPtr hPrinter, string data, int buf, ref int pcWritten);
[DllImport("winspool.drv", CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern long EndPagePrinter(IntPtr hPrinter);
[DllImport("winspool.drv", CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern long EndDocPrinter(IntPtr hPrinter);
[DllImport("winspool.drv", CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern long ClosePrinter(IntPtr hPrinter);
I want to print informations (PCL and other) in the same page, but not in 2 pages.
Thank you for your Help.