Automating Database Printing

Using BTXML Script you can automate a document to read data from several sources including text files, OLEDB/ODBC databases, and user prompts.

ClosedUsing Text Files

The following example prints the document Document1.btw, using the text data file: Data1.csv.

<?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 prints Document1.btw, using embedded comma delimited text. You can pass CSV data (Comma Separated Values) or you can delimit the text using quotes, 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

BTXML Script supports printing BarTender documents connected to OLEDB and ODBC databases. The example below demonstrates how to print database records using a 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

At print time, BarTender can prompt the user for data.

The following example fills the user prompt with default data using the default reply tag. When the query prompt appears, the user can choose to accept the default reply data or delete the default reply and enter new data.

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

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

<Command Name="Job1">

<Print>

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

<QueryPrompt Name="Product">

<UserPrompt>Enter Product Name:</UserPrompt>

<DefaultReply>Exotic Liquids</DefaultReply>

</QueryPrompt>

</Print>

</Command>

</XMLScript>

Related Topics