Concepts - Printing

Preparation

Install TFORMer Designer and TFORMer Runtime using the setup application. Besides TFORMer Designer (the graphical layout editor) the setup-application installs TFORMer Runtime. TFORMer Runtime is available as DLL, as COM component, as .NET assembly and as stand-alone application (tfprint). Both the COM component and the .NET assembly of TFORMer Runtime are registered automatically.
During the installation procedure, the Java package JTFORMer60.jar is copied into the Bin directory: it includes all classes that you need to create a TFORMer application with the Java language.
Note:
The JAR file is compatible with version 1.5 and higher of the Java Runtime Edition (JRE).

Design and Test a Form Layout

Use TFORMer Designer to create a FormLayout graphically.
In most cases your FormLayout contains dynamic data which is provided by your application during print-time (e.g. an article number for a product label or a ticket-number for an eTicket). TFORMer uses DataFields as place-holders for such dynamic data. These DataFields are declared as well as used within the FormLayout.

For testing purposes TFORMer Designer allows you to provide values for such DataFields manually or to import them from files or data-bases. Testing a FormLayout can therefore be done without any line of code.

Depending on your application choose between using stand-alone FormLayouts or Repository-based FormLayouts:

Create a Java Project

Create a new Java project or at least a new Java source file.

Link your application with the JTFORMer60.jar (the TFORMer package).
To do so, either use the classpath list in your IDE or use java -cp %CLASSPATH%

For creating a Java program with the TFORMer Java API, you need to import a few TFORMer Packages:

 import com.tecit.TFORMer.*;                   // Licensing, Errorhandling, Enumerations
 import com.tecit.TFORMer.Repository.*;        // Provides access to Repository elements 
 import com.tecit.TFORMer.Printing.*;          // Contains functionality for a printjob

License and Initialize TFORMer Runtime

Licensing is not required for evaluation purposes. For production use it is recommended to apply a license key to TFORMer Runtime before using any other properties or methods of TFORMer. This needs to be done only once, for example when initializing the application.

 TFORMer.license("John Doe", LicenseKind.Workstation, 1, "00000000000000000000000000000000"); 

Select the Form Layout to be used

Printing is done with the help of a print job. Create a job and select the FormLayout by setting the appropriate properties:

When you use a stand-alone FormLayout:

 Job printJob = new Job();
 printJob.setRepositoryName("MyPath\\myFormLayout.tff"); 
A repository-based FormLayout requires two more properties to be set:
 Job printJob = new Job();
 printJob.setRepositoryName ("MyPath\\myRepository.tfr"); 
 printJob.setProjectName ("MyProject");
 printJob.setFormName ("MyForm"); 

Provide Dynamic Data

A mentioned above a FormLayout usually contains DataFields which are used as place holders for dynamic data. Before printing a FormLayout you need to provide data for these DataFields. The required data is passed to TFORMer using different methods:

Pass Data via Program Code

This is the most direct method to pass data to TFORMer Runtime. In this case the developer provides names and values for the DataFields used in a FormLayout directly. The example below sets the values for the DataFields ArticleNo, ArticleName and ArticlePrice:
 // Supply some record sets
 JobDataRecordSet myData = new JobDataRecordSet();
 Record record = new JobDataRecordSet.Record();

 record.setData("ArticleName", "Speaker System HF1");
 record.setData("ArticleNo", "12001234");
 record.setData("ArticlePrice", "498.98");
 myData.add(record);
 
 record = new JobDataRecordSet.Record();
 record.setNumberOfCopies(2);
 record.setData("ArticleName", "Record Box 12 CDs");
 record.setData("ArticleNo", "12021231");
 record.setData("ArticlePrice", "8.85");
 myData.add(record);

Load Data from Files:

Note:
TFORMer Runtime is able to import data from text files, XML-files and from a database (ODBC).
You can load data either from XML or CSV/TXT files:

 // load a CSV file
 JobDataCsv jobData = new JobDataCsv("path\\data.csv", ',', '"');
 // load a XML file
 JobDataXml jobData = new JobDataXml("path\\data.xml");

Print the FormLayout (or save the output as PDF, PostScript, HTML, ...)

Print the FormLayout

Using the setPrinterName method you may specify the system printer to be printed to. Provide an empty string, if you want to send the output to the default printer.
 // Set the JobData that contains the data to be printed:
 printJob.setJobData(myData); 
 
 // Select the printer:
 printJob.setPrinterName("YourPrinterName"); 
 
 // Print the form:
 printJob.print(); 

Export as PDF, PostScript, HTML, ZPL-II or as an Image

Instead of sending the form directly to a printer, you can export the output as a PDF, PostScript, HTML, ASCII or image file. ZPL-II generation is supported too (the ZEBRA printer language). The procedure is the same as printing the form � but instead of setting a printer name, set the name and type of the output file:
 // Set the JobData that contains the data to be printed:
 printJob.setJobData (myData); 
 
 // Select the output file and type:
 printJob.setOutputName ("C:\\temp\\myForm.pdf");
 printJob.setPrinterType (EPrinterType.PDFFile);

 // Print the form:
 printJob.print(); 

Free the Resources allocated by TFORMer Java Instance

The Java package invokes the API of TFORMer runtime via Java Native Interface (JNI). In order to free the resources allocated by TFORMer Runtime, it's important to call the method dispose of the JTFormer classes.
For this reason, you should always add the following code:
 // free resources used by TFORMer Runtime
 printJob.dispose();

Note:
It's recommended to insert the source code that uses the Job instance into a try/catch block and insert the dispose procedure into the finally block. This tip helps you to dispose the instances even in case of exceptions.
 Job printJob = new Job();
 try {
   // ... use the Job instance
 }
 catch(TFormerException ex){
   // ... manage the exception
 }
 finally {
   // free resources used by TFORMer Runtime
   printJob.dispose();
   // it's a good idea to set the variable to null, because the object is now invalid internally.
   printJob = null;
 }

© 2006-2009 All rights reserved by TEC-IT Datenverarbeitung GmbH
Generated on Wed Sep 2 16:01:27 2009 for TFORMer Runtime JAVA Developer Reference with doxygen 1.5.8