473,666 Members | 2,250 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 sendStringToPri nter 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 SendStringToPri nter(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(StartDocPrin ter(hPrinter, 1, di))
{
if( StartPagePrinte r(hPrinter) )
{
for(int i=0; i<print.Count;i ++)
{
string s=(string)print[i];
bSuccess = WritePrinter(hP rinter, s, s.Length, out dwWritten);
}
EndPagePrinter( hPrinter);
}
EndDocPrinter(h Printer);
}
ClosePrinter(hP rinter);
}
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 2014

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

Similar topics

4
3154
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 system call is too small". I found the following article, that I assume is similar to my problem, which is of little help: http://support.microsoft.com/default.aspx?scid=kb;en-us;822779 Any suggestions?
2
2785
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 by http://www.python.org/pycon/2005/papers/7/pyconHooking.html I would create a class like this:
0
1501
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
4966
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 printed. I've tried printing to a network printer, as well as the local "Microsoft Office Document Image Writer". For the Microsoft Office Document Image Writer, the document seems to get "stuck" and never prompts to save the .mdi image.
7
2035
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 an old lineprinter as a log printer printing out each line (incomming allert) at a time without having to build a whole page
1
2591
by: franchdream | last post by:
IntPtr pBytes; Int32 dwCount; dwCount = szString.Length; pBytes = Marshal.StringToCoTaskMemAnsi(szString); string yang = Marshal.PtrToStringAnsi(pBytes); ........ WritePrinter(hPrinter, pBytes, dwCount, ref dwWritten); I want to know why I can't print Chinese used this method. I can only print the ASCII of these Chinese.
0
1240
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: System.Drawing.Graphics.CheckErrorStatus(Int32 status) System.Drawing.Graphics.DrawString(String s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format) System.Drawing.Graphics.DrawString(String s, Font font, Brush brush, PointF...
14
4103
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: System.Drawing.Graphics.CheckErrorStatus(Int32 status) System.Drawing.Graphics.DrawString(String s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format) System.Drawing.Graphics.DrawString(String s, Font font, Brush brush, PointF...
2
6705
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 of Chinese characters, on my machine I installed language pack and currently set language as Chinese PRC but still it's not working. Option Explicit Private Type DOCINFO pDocName As String pOutputFile As String pDatatype As String
0
8440
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8355
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8866
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8781
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8550
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7381
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
2769
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2006
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1769
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.