473,233 Members | 1,377 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,233 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 1971

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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
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...

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.