WritePrinter/ Generic Only Text Printer

A

a_man

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;
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top