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 spooling the print job or wait to return until printing is complete.

The Format.PrintOut method will simply execute a print job, giving you the option to display a print job status dialog and/or the print dialog.

The following example 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 printing, one or more messages may be generated indicating print success or error. These messages can be viewed by enumerating the Messages collection returned as a parameter from the Format.Print method. Each Message object in the collection contains a Message.Message property giving a description of the message. Additional properties of the message can also be examined, such as the severity and type.

The following example displays any error or warning messages that BarTender encounters while printing 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 printing, you can configure exactly how your document will print by using the following properties of the Format object prior to calling the Format.PrintOut method or the Format.Print method.

Related Topics