Print Document Using Print Command Script (Video - 9:40)
Applies to: BarTender 2016 and later.
Overview
The goal of this example is to include a Print Command Script in a file integration.
This type of integration may be necessary for businesses that have different applications and databases with different printing needs scattered throughout their network. In such cases, the BarTender document to be printed can vary depending on the data included with the trigger file.
With little programming, these applications can be modified or configured to write to a text file with data that will be used for printing, as well as embedded command lines. The Integration Service can then read and execute these command lines, telling BarTender how to print the item depending on the specific instructions contained within the file.
Scenario
A company needs to print invoices that are entered by many different users across their network. Each user has access to a shared drive. However, the invoices are formatted differently depending on the user and the product being invoiced. The various departments each use a separate printer.
In this situation, an invoicing application can create, with each invoice, a text file containing both data and a Print Command Script, with the script instructing BarTender to:
- Open the specified BarTender document.
- Use the trigger file as the data file.
- Print to a specific printer.
- Delete the trigger file.
Implementation
The following procedures describe how to set up, deploy, and verify the integration for the scenario outlined above.
Set up the data files
- Create the network folder where the trigger files will be saved. This is the folder that the Integration Service will monitor. In this example, it will be called
\\InvoiceServer\NewInvoice
. - For each type of invoice, create a sample file in which the data is structured and delimited exactly as it will be in the real data files. In this example, there are two departments printing invoices.
- For the first, create a text file named
invoice1.txt
that contains two lines of comma-delimited data (as shown below).
BusinessName,ContactName,Position,Address1,City,State,Zip,Country,Phone1,Phone2
Around the Town,Jerome Davis,Buyer,1220 Governor Sq.,Haddonfield,GA,31002,USA,(706) 555-7788,(706) 555-6750 - For the second, create a text file named
invoice2.txt
that contains two lines of quote-and-comma-delimited data (as shown below).
"BusinessName","ContactName","Position","Address1","City","State","Zip","Country","Phone1","Phone2"
"Far Fetched Imports","Jerry Bom","manager","3320 Happy St.","Incident","Washington","98887","USA","(206) 555-7788","(206) 555-6750" - Save the text files to the directory created in Step 1,
\\InvoiceServer\NewInvoice
.
Create the BarTender documents
- Following the same steps as the Create the BarTender Document section of Print document using a data file, create a BarTender document for the first department, using
invoice1.txt
as the database. - Save the document as
HardwareInvoice.btw
. - Following the same steps again, create a second BarTender document for the second department, using
invoice2.txt
as the database, making sure to specify the delimitation type as "Quote and Comma". - Save the document as
SoftwareInvoice.btw
. - Move both sample database files out of the folder that the Integration Service will be scanning and into another folder.
- Close BarTender.
Add Print Command Script to the trigger files
- Open
invoice1.txt
and add the following two lines to the beginning of the file. (The only hard carriage returns are immediately before and immediately after%END%
.)
%BTW% /AF=c:\command\HardwareInvoice.btw /D="%Trigger File Name%" /PRN="EasyCoder F4 (203 dpi)" /R=3 /P /DD
%END%
So the entire file now contains the following:
%BTW% /AF=c:\command\HardwareInvoice.btw /D="%Trigger File Name%" /PRN="EasyCoder F4 (203 dpi)" /R=3 /P /DD
%END%
BusinessName,ContactName,Position,Address1,City,State,Zip,Country,Phone1,Phone2
Around the Town,Jerome Davis,Buyer,1220 Governor Sq.,Haddonfield,GA,31002,USA,(706) 555-7788,(706) 555-6750 - Save the document as
invoice1.dat
. - Open
invoice2.txt
and add the following two lines to the beginning of the file. (The only hard carriage returns are immediately before and immediately after%END%
.)
%BTW% /AF=c:\command\SoftwareInvoice.btw /D="%Trigger File Name%" /PRN="Datamax 4400" /R=3 /P /DD
%END% - So the entire file now contains the following:
%BTW% /AF=c:\command\SoftwareInvoice.btw /D="%Trigger File Name%" /PRN="Datamax 4400" /R=3 /P /DD
%END%
"BusinessName","ContactName","Position","Address1","City","State","Zip","Country","Phone1","Phone2"
"Far Fetched Imports","Jerry Bom","manager","3320 Happy St.","Incident","Washington","98887","USA","(206) 555-7788","(206) 555-6750" - Save the document as
invoice2.dat
.
Create and deploy the integration file
Create
- Open BarTender Integration Builder.
- Click Create New Integration to open the New Integration dialog.
- Click File and then click OK.
- In the File Integration pane, select Integration.
- In the Properties pane, enter the Name of your integration as Each Order.
- From the Start Integration menu, select Automatic.
- Under User Account, specify user credentials. See Print Document Using an Empty File for details.
- In the File Integration pane, select File Detection.
- In the Properties pane, under Detection Options, select Computer/Network from the Location list.
- For the Folder to Scan option, type the path or browse to the folder that you want the Integration Service to monitor. In this case, specify the \\InvoiceServer\NewInvoice folder that you created in the Set up the data files section, above.
- In the File Pattern field, type *.dat.
- Scroll down to the Actions After Detection section. From the Action menu, select Rename File.
-
In the New Extension field, enter .txt . This extension cannot be the same one specified in File Pattern.
- In the File Integration pane under Actions, click at the right of Print Document to remove the default action.
- Select Actions, and click to open the New Action dialog.
- Select Print from the list of action types in the left Navigation Pane, and then select Print Command Script.
- Click OK to close the New Action dialog.
- Click in the top left corner of Integration Builder to save the integration file as
VariantInvoices.btin
.
Deploy
- Click Deploy Integration to open the New Deployment dialog.
- Enter a name and description for the deployment.
- Ensure that the Integration File setting lists VariantInvoices.btin. Otherwise, click Browse and browse to and select
VariantInvoices.btin
. - For Target Servers, add the server(s) you want to deploy the integration file to.
- Specify the desired Error Handling settings.
- Click OK to close the dialog and deploy the integration file.
- Administration Console will open on the Integrations node, displaying your integration.
Understanding and Customizing the Print Command Script
%BTW%
is the Print Command Script command that tells the Integration Service to launch BarTender and to use the string that follows as a BarTender command line.
%END%
tells the Integration Service that the command line is finished and what follows is data.
You will need to edit the Print Command Script for both trigger files as follows:
- Replace the path and printer name following the
/PRN
command with the path and printer name for your own printers. - Replace
c:\command\
with the path where you saved your BarTender documents.
Also note the following:
- If any of the paths, file names, or printer names used in your Print Command Script contain spaces, you must enclose the entire path in quotes.
- Administrative Console will recognize
%Trigger File Name%
as a variable and will automatically replace it with the latest trigger file name before it passes the parameter to BarTender. Do not replace %Trigger File Name% with the name of the database file. - The
/R=3
command tells BarTender to treat the third line in the trigger file as the data record. - When using Print Command Script to print a label that has an inner join on two databases, where 1 database is a text file and the other is a database of any type other than text, and a database override on the text database is being performed using the
/D
command, the/R
command should be set to/R=1
instead of/R=3
. - The
/P
command tells BarTender to print the item. - The
/DD
command tells BarTender to delete the trigger file after reading it.
Run the scenario and view integration processing
- In Administration Console, click the integration name Each Order to open a detailed view of the integration.
- As you run the example scenario in the next step, you can observe the processing steps of the integration in the Output section of this view.
- Using Windows Explorer, copy the text file
invoice1.dat
to the folder\\InvoiceServer\NewInvoice
. - The integration begins almost immediately, detecting the file
invoice1.dat
, renaminginvoice1.dat
toinvoice1.txt
. - BarTender launches in the background (you won't even see it open) and sends the .txt file to the command line contained within the trigger file, inserting
invoice1.txt
for the variable%Trigger File Name%
- BarTender then opens
HardwareInvoice.btw
, reads the data frominvoice1.txt
, prints the item, and deletesinvoice1.txt
. - Using Windows Explorer, copy the text file
invoice2.dat
to the folder\\InvoiceServer\NewInvoice
. - The integration begins almost immediately, detecting the file
invoice2.dat
, renaminginvoice2.dat
toinvoice2.txt
. - BarTender opens and sends the .txt file to the command line contained within the trigger file, inserting
invoice2.txt
for the variable%Trigger File Name%
- BarTender then opens
SoftwareInvoice.btw
, reads the data frominvoice2.txt
, prints the item, and deletesinvoice2.txt
.