Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 214,057 times

Contents

Related Categories

Printing in VB - The Basics

The Basics

Unsurprisingly, Visual Basic provides us with a Printer and Printers object which is available at runtime to all VB apps. The Printers object gives us information about all the available printers installed on the system. The Printer object controls all the output to the active printer, and retrieve information such as the printer name.

First of all, lets look at the basic steps involved in printing in VB. First off, we send all the data we want to print using the Print method. For example, if we wanted to print "Hello", we would call

Printer.Print "Hello"

Each time you call the Print method, your output will move to the next line. So,

Printer.Print "Hello"
Printer.Print "Goodbye!"

would appear as

Hello
Goodbye!

on paper.

If you want to output a new page, you simply call the NewPage method:

Printer.NewPage

Once you have finished outputting the data to the printer, you need to call the EndDoc method:

Printer.EndDoc

Windows will then spool your document to the printer.

James first started writing tutorials on Visual Basic in 1999 whilst starting this website (then known as VB Web). Since then, the site has grown rapidly, and James has written numerous tutorials, articles and reviews on VB, PHP, ASP and C#. In October 2003, James formed the company Developer Fusion Ltd, which owns this website, and also offers various development services. In his spare time, he's a 3rd year undergraduate studying Computer Science in the UK. He's also a Visual Basic MVP.

Comments

  • Posted by bakuretsu on 27 Sep 2005

    Can you tell me how to set the margins and printer orientation also using this method. It should work in VB .NET 2003 I'm assuming.

    I need to be able to control the printer margins and headers and...

  • Cannot print from Local printer connected on Win X

    Posted by vasanthi on 27 Sep 2005

    [Hi,

    Facing problem in printing from local printer connected to WinXp from VB6. I am able to capture Printer.devicename and thru this print to network printer. But when trying to print on Local pri...

  • problem in printing

    Posted by aadreja on 04 Jul 2005

    hi suhaas

    have u added new paper...

    now go to properties of your generic printer..
    in printing preferences select default paper instead of letter select ur created custom paper...

    now open ...

  • Posted by suhaas on 04 Jul 2005

    hi aadreja,

    thanks for your reply.

    I tried to do as per your reply. But this does not work with VB6. I am working on a invoice printing application where I am using Generic Text printer with VB6...

  • custom paper size in xp

    Posted by aadreja on 04 Jul 2005

    for setting custom paper size in xp
    u have to create form...

    go to start->settings->printers
    in file menu go to "server properties"
    create new from with desired paper size... and give name

    n...