Example for BarTender REST API Print Action Using TransformTextToRecordSetAction
Overview
When automating your label printing using the BarTender REST API, it is possible to override the a database connection for your label with custom data using text files without the need to modify your BTW file.
Using the TransformTextToRecordSetAction function during your API call converts the data in your text file into data records which then populate your label at print time.
This article will show you how to call this function using YAML.
For a general overview on how the REST API works you can have a look at this article.
Applicable to
BarTender 2022 and later
Automation edition and higher
Information
Create Your BarTender Document
- Create a database text file with the following format:
Field 1, Field 2, Field 3
Value 1, Value 2, Value 3
Value 4, Value 5, Value 6 - Save the file as dbfile.txt.
- Open BarTender Designer and create a new document.
- Add a text database connection for dbfile.txt.(Check this article for more information)
- Make sure your database connection is named dbfile:
- Add 3 text objects to the label and connect them to the database fields.
- Save the file under C:\Docs\APITest.btw.
Setup Your Environment
- Export your database connection setup:
- Save the file under C:\Docs\dbfolder\ConnectionSetup.xml.
- Create a data file with the following content:
Field 1, Field 2, Field 3
Value 7, Value 8, Value 9
Value 10, Value 11, Value 12 - Save it under C:\Docs\dbfolder\datafile.txt.
- Create a folder called Output under C:\Docs\.
Make Your API Call
- Open the following link in your browser:
http://localhost:5159/swagger/index.html
- At the top of the page click the Try it out button:
- Make sure the File parameter is empty.
- For Request body select text/vnd.yaml.
- In your request body, add the following two actions:
- TransformTextToRecordSetAction with parameters:
- ConnctionSetup: the xml file exported from your btw Connection setup.
- Text: the text file which contains the data to be inserted into your labels at print time.
- PrintBTWAction with paramters:
- DocumentFile: the path to your btw file to be printed.
- Printer: the printer to be used.
- PrintToFileFolder & PrintToFileFileName: the output location and filename used by the PDF printer.
- DatabaseOverrides: the database override settings. In this case, the database connection dbfile is overriden from the datum variable.
- TransformTextToRecordSetAction with parameters:
ActionGroup:
Actions:
- TransformTextToRecordSetAction:
ConnectionSetup:
File: C:\Docs\dbfolder\ConnectionSetup.xml
Text:
File: C:\Docs\dbfolder\datafile.txt
RecordSetVariableName: datum
- PrintBTWAction:
DocumentFile: C:\Docs\APITest.btw
Printer: PDF
PrintToFileFolder: C:\Docs\Output
PrintToFileFileName: test.pdf
DatabaseOverrides:
- Name: dbfile
- Type: VariableName
- DataSourceVariableName: datum
If the call was successful you should see the below message: