Automating Database Printing

By using BTXML script, you can automate a document to read data from several sources, including text files, a wide variety of database types, and user input.

ClosedUsing Text Files

The following example shows a BTXML script that prints the Document1.btw document by using the Data1.csv text data file.

<?xml version="1.0" encoding="utf-8"?>

<XMLScript Version="2.0">

<Command Name="Job1">

<Print>

<Format>c:\BarTender\Document1.btw</Format>

<RecordSet Name="Text File 1" Type="btTextFile">

<FileName>Data1.csv</FileName>

</RecordSet>

</Print>

</Command>

</XMLScript>

ClosedUsing Embedded Delimited Text

The following example shows a BTXML script that prints Document1.btw by using embedded comma-delimited text. You can pass comma-separated values (CSV) data, or you can delimit the text by using quotation marks, tabs, or a custom delimiter. Line breaks are used to separate each individual record.

<?xml version="1.0" encoding="utf-8"?>

<XMLScript Version="2.0">

<Command Name="Job1">

<Print>

<Format>c:\BarTender\Document1.btw</Format>

<RecordSet Name="Text File 1" Type="btTextFile">

<Delimitation>btDelimQuoteAndComma</Delimitation>

<UseFieldNamesFromFirstRecord>true</UseFieldNamesFromFirstRecord>

<TextData>

<![CDATA["FirstName","LastName","City","Zip Code"

"Adam","Jones","Bellevue","98008"

"John","Smith","Kirkland","98293"]]>

</TextData>

</RecordSet>

</Print>

</Command>

</XMLScript>

ClosedUsing SQL Statements

By using BTXML script, you can print BarTender documents that are connected to a wide variety of database types, including OLEDB and ODBC databases. The following example shows a BTXML script that prints database records by using an SQL statement, user ID, and password.

<?xml version="1.0" encoding="utf-8"?>

<XMLScript Version="2.0">

<Command Name="Job1">

<Print>

<Format>c:\BarTender\Document1.btw</Format>

<RecordSet Name="SQL_OLEDB" Type="btOLEDB">

<UserID>Admin</UserID>

<Password>seagull</Password>

<SQLStatement>SELECT ProductName FROM Products WHERE Supplier = 'Exotic Liquids'</SQLStatement>

</RecordSet>

</Print>

</Command>

</XMLScript>

ClosedUsing Query Prompts

You can configure BarTender to prompt the print operator to enter data at print time.

The following example shows a BTXML script that fills the prompt with default data by using the <DefaultReply> tag. When the query prompt appears at print time, the print operator can accept the default reply data or delete the default reply and then enter new data.

<?xml version="1.0" encoding="utf-8"?>

<XMLScript Version="2.0">

<Command>

<PrintJobName="EmployeeList"SaveAfterPrintCondition="IfSerialized">

<Format>c:\BarTender\Document1.btw</Format>

<QueryPrompt Name="Product">

<UserPrompt>Enter Product Name:</UserPrompt>

<DefaultReply>Exotic Liquids</DefaultReply>

</QueryPrompt>

</Print>

</Command>

</XMLScript>

ClosedUsing Table-Object Databases

You can configure automated printing for databases that are connected to table objects.

The following example shows a BTXML script that provides substitute content for a text file database. The database is specified by the Name attribute of the <RecordSet> tag ("Employees" in this example). This is the name of a database that is associated with the table object, not the name of the table object itself. The Name attribute is required.

Table-object database changes are always temporary and are reverted after the print job is finished.

<?xml version="1.0" encoding="utf-8"?>

<XMLScript Version="2.0" Name="09232006_103601_Job1" ID="123">

<Command Name="Job1">

<Print>

<PrintSetup>

<IdenticalCopiesOfLabel>1</IdenticalCopiesOfLabel>

</PrintSetup>

<FormatSaveAtEndOfJob="true">d:\tests\table_employees.btw</Format>

<RecordSet Type="btTextFile"AddIfNone="true" Name="Employees">

<Delimitation>btDelimMixedQuoteAndComma</Delimitation>

<UseFieldNamesFromFirstRecord>true</UseFieldNamesFromFirstRecord>

<TextData> <![CDATA[ID,LastName,Department,City
1245,Hughes,Engineering,"Seattle, Washington"
2568,Peters,Sales,"Minneapolis, Minnesota"
6582,Becker,HR,"Los Angeles, California"
]]>
</TextData>

</RecordSet>

</Print>

</Command>

</XMLScript>

Related Topics