Print Document Using BTXML Over a Network Socket (Video - 7:30)

 
Applies to: BarTender 2016

Overview

The goal of this example is to create a network socket integration that includes BTXML Script in an action. BarTender XML Script (BTXML Script) provides the ability to easily automate BarTender while allowing 3rd party programmers a simple way to integrate BarTender into their applications.

An XML response is created after running a BTXML script. The XML response provides you with valuable information about the print job, such as the printer used to complete the job, BarTender's settings during the print job, and complete details about the labels printed.

Scenario

A company needs to send a print job containing 100 serialized items to Tray 1 of their HP LaserJet printer. The print job will execute when data--in this case, a BTXML Script--is sent over a network socket, and read by the BarTender Integration Service.

Implementation

The following procedures describe how to set up, deploy, and verify the integration for the scenario outlined above.

Create the BarTender document

  1. Open BarTender.
  2. From the File menu, select New to open the New Document Wizard.
  3. Select Blank Template, and then click Finish to close the New Document Wizard. A new document appears in BarTender.
  4. From the File menu, select Print to open the Print dialog.
  5. From the Name dropdown list, select the printer you want to use. Be sure to change the printer name in the BTXML Script to the printer you select here.
  6. Click Close to close the Print dialog.
  7. From the File menu, select Page Setup to open the Page Setup dialog and configure your page as needed.
  8. When you're finished configuring your page, click OK to close the Page Setup dialog.
  9. From the Create menu, select template objects and configure your BarTender document as desired.
  10. From the File menu, select Save As, and save the BarTender document under the name Scriptdoc.btw.
  11. Close BarTender.

Create the BTXML Script trigger document

<?xml version="1.0" encoding="utf-8"?>		
<XMLScript Version="2.0">
	<Command Name="Job1">
		<Print>
			<Format>c:\BarTender\Scriptdoc.btw</Format>
			<PrintSetup>
			        <NumberSerializedLabels>100</NumberSerializedLabels>
				<Printer>HP LaserJet</Printer>
				<PaperTray>Tray 1</PaperTray>
			</PrintSetup>
		</Print>
	</Command>
</XMLScript>

NOTE: Make sure that the path and filename match those of the document you created for this example.

Paste the BTXML script into a text file, and save it under the name BTXMLScript.txt.

Create the Integration File: Select a Network Socket Integration

  1. Open Integration Builder.
  2. Click Create New Integration to open the New Integration dialog.
  3. Click Network Socket and then click OK.
  4. In the Network Socket Integration pane, select Integration.
  5. In the Properties pane, enter the Name of your integration as "Print 100".
  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 Network Socket Integration pane, select Socket.
  9. In the Properties pane, set your Protocol and Port information.
  10. Under Network Address, select Listen on all network interfaces. Alternatively, select Listen on specific IP address and select an IP address from the dropdown list, or enter an IP address by hand.
  11. Set your Communication Settings and Connection Protocol if you wish.
  12. In the Network Socket Integration pane, select Input Data.
  13. In the Properties pane, select Unicode (UTF-8) for the Encoding property.
  14. For Stop Reading When, select Sequence of Characters Received.
  15. In the Characters field, enter </XMLScript>.
  16. Enable Include sequence in input data contents.
  17. For Input Data Format, select BTXML Script.
  18. In the Network Socket Integration pane, select Response.
  19. In the Properties pane, select your response options.

Create the Integration File: Add an Action to the Network Socket Integration

  1. In the Network Socket Integration pane, select Actions.
  2. In the Properties pane, for Execute Actions, select Sequentially.
  3. For Repeat actions, specify "1".
  4. In the Network Socket Integration pane under Action, click  at the right of Print Document to remove the default action.
  5. Select Action and click  Add to open the New Action dialog.
  6. Select Print from the list of action types in the left Navigation Pane, and then select Print BTXML Script
  7. Click OK to close the New Action dialog.
  8. The action Print BTXML Script appears in the Network Socket Integration pane under Actions.
  9. If not already selected, click Print BTXML Script in the Network Socket Integration pane.
  10. In the Properties pane under Action, enter a name and description for the Print BTXML Script action.
  11. Under Script, select Variable from the Script Source dropdown list.
  12. If it's not already selected, choose EventData from the Variables dropdown list.
  13. Click  in the top left corner of Integration Builder to save the integration file as BTXML_Integration.btin.

Test the Print BTXML Script Action (Not the Entire Integration)

In order to test a "Print BTXML Script" action, you must change some settings for the test, then restore them to their original state afterward.

  1. In the Network Socket Integration pane under Actions, select Print BTXML Script.
  2. In the Properties pane under Script, select Embedded Script from the Script Source dropdown list.
  3. Click the Import button to import your BTXML file, or just paste the contents of the file in the provided window.
  4. Click the Test button at the right of the script window.
  5. If your "Print BTXML Script" action passes testing, in the Network Socket Integration pane under Actions, select Print BTXML Script once more.
  6. In the Properties pane, set the Script type back to Variable, and the Variable type back to %EventData%.
NOTE: This unit test is only verifying the BTXML script is correct, and the selected user account can access and print the BarTender file to the designated printer. It does not test the triggering conditions. See the next section.

Test and Deploy the Integration File

  1. Click  Test Integration in the Integration Builder toolbar.
  2. If your integration passes testing, click  Deploy Integration to open the New Deployment dialog.
  3. Enter a name and description for the deployment.
  4. Ensure that the Integration File setting lists BTXML_Integration.btin. Otherwise, click Browse and browse to and select BTXML_Integration.btin.
  5. For Target Servers, add the server(s) you want to deploy the integration file to.
  6. Specify the desired Error Handling settings.
  7. Click OK to close the dialog and deploy the integration file.
  8. Administration Console will open on the Integrations node, displaying your integration

Run the scenario and view integration processing

  1. The BarTender Integration Service is monitoring the selected network socket. Send the contents of BTXMLScript.txt over the network socket using your preferred method.
  2. The Integration Service passes the BTXML Script to BarTender.
  3. BarTender performs the actions specified in the BTXML Script, printing 100 copies of the document Scriptdoc.btw using tray 1 of the specified printer.
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.