Using the Format Object

The Format object represents a BarTender document (with the extension *.btw). Format objects are opened in an instance of the BarTender application, giving access to a wide range of BarTender functionality. When using the Format object, developers can easily open, save, and print document, as well as change database options and modify text and barcode data.

The Format object allows you to manipulate existing documents by changing print settings and accessing object properties. It does not allow you to modify the layout of templates in a document or to create new documents.

The Application object contains a list of all documents currently open in BarTender, 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, representing 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 will close the default blank document called "Document1" 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 code demonstrates 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

Closing a BarTender document is achieved by calling the Format.Close method. The following code provides an example of 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. This allows the user to choose whether to save, prompt for save, or discard changes made to the document.

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

Related Topics