PC Review


Reply
Thread Tools Rate Thread

Printing to Generic Printer

 
 
Rob T
Guest
Posts: n/a
 
      15th Jun 2004
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.


 
Reply With Quote
 
 
 
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      15th Jun 2004
* "Rob T" <(E-Mail Removed)> 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/>
 
Reply With Quote
 
 
 
 
Rob T
Guest
Posts: n/a
 
      15th Jun 2004
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(sender As Object, ev As PrintPageEventArgs)
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.GetHeight(ev.Graphics)

' Iterate over the file, printing each line.
While count < linesPerPage
line = streamToPrint.ReadLine()
If line Is Nothing Then
Exit While
End If
yPos = topMargin + count * printFont.GetHeight(ev.Graphics)
ev.Graphics.DrawString(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(filePath)
Try
printFont = New Font("Arial", 10)
Dim pd As New PrintDocument()
AddHandler pd.PrintPage, AddressOf pd_PrintPage
' Print the document.
pd.Print()
Finally
streamToPrint.Close()
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.Environment.GetCommandLineArgs()
Dim sampleName As String = args(0)
If args.Length <> 1 Then
Console.WriteLine("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(object sender, PrintPageEventArgs 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.GetHeight(ev.Graphics) ;

// Iterate over the file, printing each line.
while (count < linesPerPage &&
((line=streamToPrint.ReadLine()) != null))
{
yPos = topMargin + (count * printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString (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 PrintPageEventHandler(pd_PrintPage);
// Print the document.
pd.Print();
}
finally
{
streamToPrint.Close() ;
}
}
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.GetCommandLineArgs()[0];
if(args.Length != 1)
{
Console.WriteLine("Usage: " + sampleName +" <file path>");
return;
}
filePath = args[0];
new PrintingExample();
}
}
"Herfried K. Wagner [MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> * "Rob T" <(E-Mail Removed)> 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/>



 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      15th Jun 2004
* "Rob T" <(E-Mail Removed)> 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.microsoft.com/?scid=kb;EN-US;322090>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
 
Reply With Quote
 
Rob T
Guest
Posts: n/a
 
      15th Jun 2004
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]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> * "Rob T" <(E-Mail Removed)> 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.microsoft.com/?scid=kb;EN-US;322090>
>
> --
> Herfried K. Wagner [MVP]
> <URL:http://dotnet.mvps.org/>



 
Reply With Quote
 
personalisedpens4u.co.uk@gmail.com
Guest
Posts: n/a
 
      27th Jun 2012
hi if you found solution then why you question other, why you west your time you study that article then solved your problem

thnks

On Tuesday, June 15, 2004 9:38:29 PM UTC+5:30, Rob T wrote:
> 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Emitting a Generic Type that has a Generic Base Class =?Utf-8?B?UGF0cmljaw==?= Microsoft Dot NET Framework 1 7th Jun 2006 05:14 PM
error C2955: 'Vector' : use of class generic requires generic argument list Herby Microsoft VC .NET 5 14th Mar 2006 04:55 PM
Generic Collection of deferred generic types Steven Cummings Microsoft C# .NET 8 17th Feb 2006 11:42 PM
Generic class derived from NameObjectCollectionBase and generic constraints Gabriel Lozano-Morán Microsoft Dot NET Framework 1 10th Dec 2005 12:11 PM
DotNet 2.0: Is a generic of a subclass a subclass of the generic of its base? Richard Corfield Microsoft Dot NET Framework 5 9th Dec 2004 02:43 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:39 AM.