Print Document Using Print Command Script (Video - 9:40)


Applies to: BarTender 2016

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:

  1. Open the specified BarTender document.
  2. Use the trigger file as the data file.
  3. Print to a specific printer.
  4. 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

  1. 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.
  2. 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"
  3. Save the text files to the directory created in Step 1, \\InvoiceServer\NewInvoice.

Create the BarTender documents

  1. 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.
  2. Save the document as HardwareInvoice.btw.
  3. 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".
  4. Save the document as SoftwareInvoice.btw.
  5. Move both sample database files out of the folder that the Integration Service will be scanning and into another folder.
  6. Close BarTender.

Add Print Command Script to the trigger files

  1. 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="%FilePath%" /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="%FilePath%" /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
  2. Save invoice1.txt.
  3. 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="%FilePath%" /PRN="Datamax 4400" /R=3 /P /DD 
    %END%
  4. So the entire file now contains the following:
    %BTW% /AF=c:\command\SoftwareInvoice.btw /D="%FilePath%" /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"
  5. Save invoice2.txt.

Create and deploy the integration file

Create

  1. Open BarTender Integration Builder.
  2. Click Create New Integration to open the New Integration dialog.
  3. Click File and then click OK.
  4. In the File Integration pane, select Integration.
  5. In the Properties pane, enter the Name of your integration as "Each Order".
  6. From the Start Integration dropdown list, select Automatic.
  7. Under User Account, specify user credentials. See Print Document Using an Empty File for details.
  8. In the File Integration pane, select File Detection.
  9. In the Properties pane, under Detection Options, select "Computer/Network" from the Location dropdown list.
  10. 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.
  11. In the File Pattern field, type "*.dat". (Do not include the quotation marks.)
  12. Scroll down to the Actions After Detection section. From the Action dropdown list, select Rename File.
  13. In the New Extension field, enter ".txt" (without the quotation marks). This extension cannot be the same one specified in File Pattern.

  14. In the File Integration pane under Actions, click  at the right of Print Document to remove the default action.
  15. Select Actions, and click  to open the New Action dialog.
  16. Select Print from the list of action types in the left Navigation Pane, and then select Print Command Script.
  17. Click OK to close the New Action dialog.
  18. Click  in the top left corner of Integration Builder to save the integration file as VariantInvoices.btin.

Deploy

  1. Click  Deploy Integration to open the New Deployment dialog.
  2. Enter a name and description for the deployment.
  3. Ensure that the Integration File setting lists VariantInvoices.btin. Otherwise, click Browse and browse to and select VariantInvoices.btin.
  4. For Target Servers, add the server(s) you want to deploy the integration file to.
  5. Specify the desired Error Handling settings.
  6. Click OK to close the dialog and deploy the integration file.
  7. 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 %FilePath% as a variable and will automatically replace it with the latest trigger file name before it passes the parameter to BarTender. Do not replace %FilePath% 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.
  • 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

  1. In Administration Console, click the integration name "Each Order" to open a detailed view of the integration.
  2. 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.
  3. Using Windows Explorer, copy the text file invoice1.txt to the folder \\InvoiceServer\NewInvoice.
  4. The integration begins almost immediately, detecting the file invoice1.txt, renaming invoice1.txt to invoice1.dat, and deleting invoice1.txt.
  5. BarTender launches in the background (you won't even see it open) and sends the .dat file to the command line contained within the trigger file, inserting invoice1.dat for the variable %FilePath%
  6. BarTender then opens HardwareInvoice.btw, reads the data from invoice1.dat, prints the item, and deletes invoice1.dat.
  7. Using Windows Explorer, copy the text file invoice2.txt to the folder \\InvoiceServer\NewInvoice.
  8. The integration begins almost immediately, detecting the file invoice2.txt, renaming invoice2.txt to invoice2.dat, and deleting invoice2.txt.
  9. BarTender opens and sends the .dat file to the command line contained within the trigger file, inserting invoice2.dat for the variable %FilePath%
  10. BarTender then opens SoftwareInvoice.btw, reads the data from invoice2.dat, prints the item, and deletes invoice2.dat.
Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments

Please sign in to leave a comment.