Using the Format Object

The Format object represents a BarTender document (*.btw). Format objects are opened in an instance of the BarTender application, which provides access to a wide range of BarTender functionality. When you use the Format object, you can easily open, save, and print documents; change database options; and modify text and barcode data.

Use the Format object to manipulate existing documents by changing print settings and accessing object properties. You cannot use this object to modify the layout of templates in a document or to create new documents.

The Application object contains a list of all documents that are currently open in BarTender and which are accessed through the Application object's Formats collection object. This collection object also provides a way to open, close, and save BarTender documents.

Opening BarTender Documents

A BarTender document is opened by calling the Formats collection object's Open method. This method returns a Format object, which represents the document that was just opened. The Formats.Open method has three arguments. The first argument is required and specifies the document to open. The second argument is a Boolean: if it is true, the method closes the default blank "Document1" document that BarTender automatically opens when it starts. (It cannot close documents that have any other name.) The third argument specifies a printer to use.

The following sample code shows how to open a BarTender document.

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 variable

btApp = New BarTender.Application

'Open a BarTender document

btFormat = btApp.Formats.Open("c:\Format1.btw", 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 variable

btApp = new BarTender.Application();

// Open a BarTender document

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

// End the BarTender process

btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);

Closing BarTender Documents

You can close a BarTender document by calling the Format.Close method. The following sample code shows how to close a document.

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 variable

btApp = New BarTender.Application

'Open a BarTender document

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

'Close the document and save changes

btFormat.Close(BarTender.BtSaveOptions.btSaveChanges)

'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 variable

btApp = new BarTender.Application();

// Open a BarTender document

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

// Close the document and save changes

btFormat.Close(BarTender.BtSaveOptions.btSaveChanges);

// End the BarTender process

btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);

The Format.Close method takes a BtSaveOptions parameter, with which the user can choose whether to save, prompt for save, or discard changes that were made to the document.

When a Format object is no longer in use by your client application, the Format.Close method should be called. Failure to do so leaves a document open in BarTender unnecessarily and consumes resources.

Related Topics