471,334 Members | 1,420 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,334 software developers and data experts.

WritePrinter/ Generic Only Text Printer

Hi everyone
Im writing an application in c# and I want to print directly to a
printer with some printer specific commands than only the printer
understands. Below is my code.
I have an arraylist with strings that are the commands to be executed.
This arraylist is passed to a function called sendStringToPrinter with
a printername:
ArrayList al= new ArrayList();
String s="! 0 100 290 1"; these are the printer language
al.Add(s);
s="PITCH 200"; this
al.Add(s);
s="INDEX"; and this
al.Add(s);
s="VARIABLE NORMAL"; and this
al.Add(s);
s="VARIABLE DARKNESS 80"; and this
al.Add(s);
s="T 4(0,0,1,1) 60 1 11 1234"; and this 11 1234 is the data to be
printed
al.Add(s);
s="END"; and this
al.Add(s);

public static bool SendStringToPrinter(ArrayList print,string
szPrinterName)
{
Int32 dwWritten = 0;
IntPtr hPrinter = new IntPtr(0);
DOCINFOA di = new DOCINFOA();
bool bSuccess = false; // Assume failure unless you specifically
succeed.
di.pDocName = "My C#.NET RAW Document";
di.pDataType = "RAW";
if( OpenPrinter( szPrinterName, out hPrinter, 0 ) )
{
if(StartDocPrinter(hPrinter, 1, di))
{
if( StartPagePrinter(hPrinter) )
{
for(int i=0; i<print.Count;i++)
{
string s=(string)print[i];
bSuccess = WritePrinter(hPrinter, s, s.Length, out dwWritten);
}
EndPagePrinter(hPrinter);
}
EndDocPrinter(hPrinter);
}
ClosePrinter(hPrinter);
}
return true;
}

Now from what i have found out, this should cause the printer to print
11 1234 at a certain position that i have specified. But nothing
happens. I can print the strings out if I choose a "normal printer" but
when I choose a generic printer nothing happens.

! 0 100 290 1
PITCH 200
INDEX
VARIABLE NORMAL
VARIABLE DARKNESS 80
T 4(0,0,1,1) 60 1 11 1234
END
When i write the above into notepad and choose a generic/ only text
printer and print it
it outputs what i want the data 11 1234.

Can anyone thell me what is wrong with my code

Thank you in advance
Amir

Jan 5 '06 #1
0 1816

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Rob T | last post: by
2 posts views Thread by Edvard Majakari | last post: by
reply views Thread by SKa | last post: by
2 posts views Thread by MPF | last post: by
7 posts views Thread by Jean Paul Mertens | last post: by
1 post views Thread by franchdream | last post: by
reply views Thread by James Wong | last post: by
14 posts views Thread by James Wong | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.