Printing BarTender Documents

A BarTender document can be printed by calling either the Format.Print method or the Format.PrintOut method. The Format.Print method prints a job to a printer's spooler and returns a BtPrintResult enumeration value. It can either return immediately after it spools the print job or wait to return until the print job is complete.

The Format.PrintOut method runs a print job and gives you the option to display a print job status dialog and/or the print dialog.

The following sample code prints a BarTender document without displaying either the print job status dialog or the print dialog.

ClosedIn VB.NET

'Declare a BarTender application variable

Dim btApp As BarTender.Application

'Declare a BarTender document variable

Dim btFormat As BarTender.Format

'Create a new instance of BarTender

btApp = New BarTender.Application

'Open a BarTender document

btFormat = btApp.Formats.Open("c:\Format1.btw", False, "")

'Print the document

btFormat.PrintOut(False, False)

'End the BarTender process

btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges)

ClosedIn C#

// Declare a BarTender application variable

BarTender.Application btApp;

// Declare a BarTender document variable

BarTender.Format btFormat;

// Create a new instance of BarTender

btApp = new BarTender.Application();

// Open a BarTender document

btFormat = btApp.Formats.Open("c:\\Format1.btw", false, "");

// Print the document

btFormat.PrintOut(false, false);

// End the BarTender process

btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);

Displaying Messages while Printing

While the print job is running, one or more messages might be generated that indicate print success or error. These messages can be viewed by enumerating the Messages collection that is returned as a parameter from the Format.Print method. Each Message object in the collection contains a Message.Message property that gives a description of the message. Additional properties of the message can also be examined, such as the severity and type.

The following sample code displays any error or warning messages that BarTender encounters while it prints a document:

ClosedIn VB.NET

'Declare BarTender variables

Dim btApp As BarTender.Application

Dim btFormat As BarTender.Format

Dim btPrintRtn As BarTender.BtPrintResult

Dim btMsgs As BarTender.Messages = Nothing

'Create a new instance of BarTender variable

btApp = New BarTender.Application

'Set the BarTender application visible

btApp.Visible = True

'Open a BarTender document

btFormat = btApp.Formats.Open("c:\Format1.btw", False, "")

'Print the document

btPrintRtn = btFormat.Print("Job1", True, -1, btMsgs)

'Check to see if there are any error messages

Dim msg As BarTender.Message

If (btPrintRtn <> BarTender.btPrintResult.btSuccess) Then

For Each msg In btMsgs

MessageBox.Show(msg.Message)

Next msg

End If

'End the BarTender process

btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges)

ClosedIn C#

// Declare BarTender variables

BarTender.Application btApp;

BarTender.Format btFormat;

BarTender.BtPrintResult btPrintRtn;

BarTender.Messages btMsgs;

// Create a new instance of BarTender

btApp = new BarTender.Application();

// Set the BarTender application visible

btApp.Visible = true;

// Open a BarTender document

btFormat = btApp.Formats.Open("c:\\Format1.btw", false, "");

// Print the document

btPrintRtn = btFormat.Print("Job1", true, -1, out btMsgs);

// Check to see if there are any error messages

if (btPrintRtn != BarTender.BtPrintResult.btSuccess)

{

foreach(BarTender.Message msg in btMsgs)

{

MessageBox.Show(msg.Message);

}

}

// End the BarTender process

btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);

Configuring Your Print Job

Before you run the print job, you can configure exactly how your document is printed by using the following properties of the Format object before you call the Format.PrintOut method or the Format.Print method.

Related Topics