473,756 Members | 8,174 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Printing to Generic Printer

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...b;en-us;822779

Any suggestions?

Thanks. -Rob T.
Nov 20 '05 #1
4 3170
* "Rob T" <RT*********@DO NTwalchemSPAM.c om> scripsit:
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".


Post the code you are using to print to the printer.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #2
It's the code taken right from the MSDN example. Try it...if you install a
generic printer (or print to a file as generic) it will fail.
;-)

Public Class PrintingExample
Private printFont As Font
Private streamToPrint As StreamReader
Private Shared filePath As String

Public Sub New()
Printing()
End Sub

' The PrintPage event is raised for each page to be printed.
Private Sub pd_PrintPage(se nder As Object, ev As PrintPageEventA rgs)
Dim linesPerPage As Single = 0
Dim yPos As Single = 0
Dim count As Integer = 0
Dim leftMargin As Single = ev.MarginBounds .Left
Dim topMargin As Single = ev.MarginBounds .Top
Dim line As String = Nothing

' Calculate the number of lines per page.
linesPerPage = ev.MarginBounds .Height /
printFont.GetHe ight(ev.Graphic s)

' Iterate over the file, printing each line.
While count < linesPerPage
line = streamToPrint.R eadLine()
If line Is Nothing Then
Exit While
End If
yPos = topMargin + count * printFont.GetHe ight(ev.Graphic s)
ev.Graphics.Dra wString(line, printFont, Brushes.Black,
leftMargin, _
yPos, New StringFormat())
count += 1
End While

' If more lines exist, print another page.
If Not (line Is Nothing) Then
ev.HasMorePages = True
Else
ev.HasMorePages = False
End If
End Sub

' Print the file.
Public Sub Printing()
Try
streamToPrint = New StreamReader(fi lePath)
Try
printFont = New Font("Arial", 10)
Dim pd As New PrintDocument()
AddHandler pd.PrintPage, AddressOf pd_PrintPage
' Print the document.
pd.Print()
Finally
streamToPrint.C lose()
End Try
Catch ex As Exception
MessageBox.Show (ex.Message)
End Try
End Sub 'Printing

' This is the main entry point for the application.
Public Shared Sub Main()
Dim args() As String = System.Environm ent.GetCommandL ineArgs()
Dim sampleName As String = args(0)
If args.Length <> 1 Then
Console.WriteLi ne("Usage: " & sampleName & " <file path>")
Return
End If
filePath = args(0)
End Sub
End Class

[C#]
public class PrintingExample
{
private Font printFont;
private StreamReader streamToPrint;
static string filePath;
public PrintingExample ()
{
Printing();
}

// The PrintPage event is raised for each page to be printed.
private void pd_PrintPage(ob ject sender, PrintPageEventA rgs ev)
{
float linesPerPage = 0;
float yPos = 0;
int count = 0;
float leftMargin = ev.MarginBounds .Left;
float topMargin = ev.MarginBounds .Top;
String line=null;

// Calculate the number of lines per page.
linesPerPage = ev.MarginBounds .Height /
printFont.GetHe ight(ev.Graphic s) ;

// Iterate over the file, printing each line.
while (count < linesPerPage &&
((line=streamTo Print.ReadLine( )) != null))
{
yPos = topMargin + (count * printFont.GetHe ight(ev.Graphic s));
ev.Graphics.Dra wString (line, printFont, Brushes.Black,
leftMargin, yPos, new StringFormat()) ;
count++;
}

// If more lines exist, print another page.
if (line != null)
ev.HasMorePages = true;
else
ev.HasMorePages = false;
}

// Print the file.
public void Printing()
{
try
{
streamToPrint = new StreamReader (filePath);
try
{
printFont = new Font("Arial", 10);
PrintDocument pd = new PrintDocument() ;
pd.PrintPage += new PrintPageEventH andler(pd_Print Page);
// Print the document.
pd.Print();
}
finally
{
streamToPrint.C lose() ;
}
}
catch(Exception ex)
{
MessageBox.Show (ex.Message);
}
}

// This is the main entry point for the application.
public static void Main(string[] args)
{
string sampleName = Environment.Get CommandLineArgs ()[0];
if(args.Length != 1)
{
Console.WriteLi ne("Usage: " + sampleName +" <file path>");
return;
}
filePath = args[0];
new PrintingExample ();
}
}
"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:2j******** ****@uni-berlin.de...
* "Rob T" <RT*********@DO NTwalchemSPAM.c om> scripsit:
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".


Post the code you are using to print to the printer.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #3
* "Rob T" <RT*********@DO NTwalchemSPAM.c om> scripsit:
It's the code taken right from the MSDN example. Try it...if you install a
generic printer (or print to a file as generic) it will fail.


I remember I posted this link some days ago...

HOW TO: Send Raw Data to a Printer by Using Visual Basic .NET
<URL:http://support.microso ft.com/?scid=kb;EN-US;322090>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #4
Thanks. This seems like a complex way to simply print some raw data. I'm
curious to find how Microsoft print their 'test page' in the printer
properties... I would have thought that they would have just stripped out
the graphics and printed the text......
"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:2j******** ****@uni-berlin.de...
* "Rob T" <RT*********@DO NTwalchemSPAM.c om> scripsit:
It's the code taken right from the MSDN example. Try it...if you install a generic printer (or print to a file as generic) it will fail.


I remember I posted this link some days ago...

HOW TO: Send Raw Data to a Printer by Using Visual Basic .NET
<URL:http://support.microso ft.com/?scid=kb;EN-US;322090>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #5

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

Similar topics

19
3212
by: dcrespo | last post by:
Hi all... Is there a way to print a PDF file directly from Python without having Acrobat installed? I know about ReportLab. It's a python module that lets you create almost any PDF document, but I still don't know if it supports printing, so I'm looking for a Python module that could do it. I want to print a PDF file just like if I were doing it from Acrobat. Daniel.
5
1916
by: jho | last post by:
I have an Epson LQ-570+ and a preprinted triplacate form. How would I go about Inputing data and getting it to print on the form in the desired place. I noticed that making a template in word doesn't work very well. Thanks julian
0
2285
by: G.Esmeijer | last post by:
Friends, I would like to print to a Zebra 4M printer. This printer expects REAL text. Defining it at an IP address as a generic Text printer does not help. How do I send REAL text to that printer with C#. I seems to me that C# does not send real text but some graphical stuff to that printer. Stand printing in c# does not work In vb6 it worked fine with the Printer.Print "123456" line of code.
3
3326
by: Les | last post by:
I have made an app with vb.net 2002 and compiled it in the XP environment. It works great in this environment but when I install it to a computer running win98, I cannot communicate with the printer. I know the printer is communicating with the OS because I can print text with notepad. Does this application need to be compiled under the win98 evironment? Or is there a fix for this type of problem? Any suggestions would be appreciated.
2
9576
by: Simon Verona | last post by:
I have a receipt printer that is set up using a generic/text print driver. I want to send a print to it. The standard vb.net printing methodology seems a little bit of overkill. Is there any way that I can simply "print" the data to the printer without worrying about paging, fonts etc. ie something like:
2
3700
by: Beginner | last post by:
I have to print a Fedex shipping label on a Zebra(thermal) printer. I initially had the label information in a base64 string which I decoded into a memory stream. Now I need to send this memory stream to a thermal/label printer. How do I do this? Thanks for any help.
8
41878
by: Microsoft News | last post by:
Greetings community at large. I have a c# app that generates a PDF file. I have a printer that prints PDF natively. But I cannot figure out how to programatically print in C# ... I can generate the PDF as a file or a stream .. but cannot figure out how to send either to the printer. the only events I can use seem to be e.Graphics.DrawImage( ) or
8
5911
by: Neo Geshel | last post by:
Greetings. BACKGROUND: My sites are pure XHTML 1.1 with CSS 2.1 for markup. My pages are delivered as application/xhtml+xml for all non-MS web clients, and as text/xml for all MS web clients (Internet Explorer). My flash content was originally brought in via the “flash satay” method, but I have since used some server-side magic do deliver one <objecttag
1
13747
by: Glenn | last post by:
I am writing a program for field work that will use a receipt printer. I need to be able to adjust the page settings prior to printing depending on how much needs to be printed. I have been able to print to this printer but cannot figure out how to overwrite the page settings. Below is the code so far: Private Sub m_PrintDocument_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles...
0
9384
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, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9212
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
9973
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...
1
9779
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,...
1
7186
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6473
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5247
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3742
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
3
2612
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.