473,322 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 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 1982

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Rob T | last post by:
I have a small VB program that has a printing module...very simple....and works great. However, If I try to print to a generic printer, I get the following error: "The data area passed to a...
2
by: Edvard Majakari | last post by:
Hi, My idea is to create a system working as follows: each module knows path to plugin directory, and that directory contains modules which may add hooks to some points in the code. Inspired...
0
by: SKa | last post by:
Hi there, Does anybody knows how to print a printer connected to LPT1, and installed as a Generic/Text Only printer? I'll send raw text commands so creating a PrintDocument won't work for me.
2
by: MPF | last post by:
Thanks in advance for any assistance. I've implemented the code found in the KB article below, but nothing is actually printing. I see the document being sent to the printer, but nothing gets...
7
by: Jean Paul Mertens | last post by:
Hello, Is there a way to send a string of text to a generic tekst printer under ..NET. Somethings as in the good old days File f = Open("LPT1"); f.Writeline("Blablabla"); The goal is to use...
1
by: franchdream | last post by:
IntPtr pBytes; Int32 dwCount; dwCount = szString.Length; pBytes = Marshal.StringToCoTaskMemAnsi(szString); string yang = Marshal.PtrToStringAnsi(pBytes); ........ WritePrinter(hPrinter, pBytes,...
0
by: James Wong | last post by:
Hi everybody, I'm facing a serious trouble relating to GDI+ generic error. The error message is "A Generic error occured in GDI+" and the following information is stored in Excepton object:...
14
by: James Wong | last post by:
Hi everybody, I'm facing a serious trouble relating to GDI+ generic error. The error message is "A Generic error occured in GDI+" and the following information is stored in Excepton object:...
2
by: Flying Kite | last post by:
Hi All, I want to know how to print chinese characters on Zebra Printer, following code working fine with English string, but it's not working for Chinese string. It shows ASCII characters instead...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.