Click here to Skip to main content
15,886,066 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi, I hope anyone here can help me.

We are busy converting a VB6 project to .net.
Some of our reports get build using the old VB6 printer object, when convered to .net we used "Microsoft.VisualBasic.PowerPacks.Printing.Compatibility.VB6.Printer", that works fine, but it's still technically pure .net code, it's basically to slow to use anymore.

How or what would I use to upgrade this to pure .net coding, using 3rd party dll's is fine like iTextSharp.

And the other issue is we really can't change much of how the design of it works because the data gets send through a string to the report builder and that string format can't be changed.

The current code is:
goPrinter is the VB6.Printer object
sReportData is an array string

Any help would be great, and thank you so long

VB
For iL = 1 To ICnt
      strItem = sReportData(iL)

      Select Case strItem.Trim()
          Case "<BR>" ' Line Feed
              LCnt += 1
              goPrinter.Write("")
          Case "<LF>"
              goPrinter.Print("")
          Case "" ' Bold On
              goPrinter.FontBold = True
          Case "" ' Bold Off
              goPrinter.FontBold = False
          Case "<NP>" ' Page Break
              goPrinter.NewPage()
          Case Else
              goPrinter.Print(strItem)            'Prints Entire Line In One Go
      End Select

  Next iL
  goPrinter.EndDoc()
  goPrinter.Print()
Posted
Comments
Sergey Alexandrovich Kryukov 12-Nov-15 21:06pm    
Just forget your VB6 printer, the take the easiest way. Perhaps development of the project from scratch would also be easier; it depends.
You need to always indicate what UI framework/library you are using.
—SA

Good evening,

For that there are already many solutions in .NET, you go through the assembly. Drawing.Printing. See the examples that you can find everywhere even here;)

PrintDocument Class
or
Basic Text and Image Printing
or
How to print more pages in C#
or
Printing in C#

In your case, the loop according to the switch, you will change the settings of e.Graphics.DrawString (make bold, etc ..)

Cordialement,
Claude T.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 12-Nov-15 21:01pm    
Sure, a 5. I added the link on WPF printing in Solution 2. Too bad the inquirer did not share with us what's used. :-(
-SA
Maciej Los 13-Nov-15 2:00am    
5ed!
It all depends on the UI framework/library you are using. For System.Windows.Forms, you should better use PrintDocument (See Solution 1). For WPF… see, for example, http://www.c-sharpcorner.com/uploadfile/mahesh/printing-in-wpf[^].

—SA
 
Share this answer
 
Comments
Maciej Los 13-Nov-15 2:00am    
5ed!
Sergey Alexandrovich Kryukov 13-Nov-15 2:16am    
Thank you, Maciej.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900