Concepts - Printing


Preparation

Install TFORMer Designer and TFORMer Runtime using the setup application. Besides TFORMer Designer (the graphical layout editor) the setup-application installs and registers the COM component as well as the .NET assembly of TFORMer Runtime automatically. The .NET assembly is automatically registered in the GAC.

Design and Test a FormLayout

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:

Stand-Alone FormLayouts

TFORMer Designer creates stand-alone FormLayouts by default. A stand-alone FormLayout can be used on its own. Such a FormLayout contains all the necessary information which is required for printing (layout information, DataField definitions, JobTrayControl, DataSource definitions).

Repository-based FormLayouts

If you prefer to organize your FormLayouts and DataFields in a structured way or if you plan to create multiple FormLayouts which use the same data basis (e.g. same DataField definitions), the use of a so-called Repository is recommended. A Repository is a central database for FormLayouts, DataField definitions, JobTrayControl-settings and DataSource definitions. Form layouts, DataField- and DataSource- definitions are stored within a Repository on a per “Project” base. A Project defines DataFields, DataSources and holds (better: refers) FormLayouts. Each of the DataFields defined in a Project is accessible within every FormLayout contained in that Project. A Repository can contain multiple Projects and one special Global Project. DataFields defined within the Global Project may be used by all FormLayouts in all Projects.

Create a .NET Project

Create a new .NET based project. In Visual Studio right-click on your project in the Solution Explorer window and select Add Reference. Open the .NET tab and select TFORMer 6.0 Runtime. Alternatively open the Browse tab and select the TFORMer .NET assembly called TECIT.TFORMer.dll.

Add the namespace TECIT.TFORMer in each source file that uses TFORMer Runtime:

using TECIT.TFORMer;

License 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 FormLayout 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.RepositoryName = @"MyPath\myFormLayout.tff";

A repository-based FormLayout requires two more properties to be set:

Job printJob = new Job();
printJob.RepositoryName = @"MyPath\myRepository.tfr";
printJob.ProjectName = "MyProject";
printJob.FormName = "MyForm";

Note: See Methods for Passing Files for additional methods for passing a FormLayout or a Repository to TFORMer Runtime.

Provide Dynamic Data

As 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 can be 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();

myData.Records.Add(new Record());
myData.Records[0].Data.Add("ArticleName", "Speaker System HF1");
myData.Records[0].Data.Add("ArticleNo", "12001234");
myData.Records[0].Data.Add("ArticlePrice", "498.98");

myData.Records.Add(new Record());
myData.Records[1].NumberOfCopies = 2;
myData.Records[1].Data.Add("ArticleName", "Record Box 12 CDs");
myData.Records[1].Data.Add("ArticleNo", "12021231");
myData.Records[1].Data.Add("ArticlePrice", "8.85");

Load Data from Files or Databases

TFORMer Runtime is able to import data from text-/XML-files or from a database (ODBC). The filenames, DSNs or SQL-SELECT statements are specified directly. Take care, that the field-names available in the DataSource (e.g. the column names returned by a SQL-SELECT statement) are equal to the names of the DataFields used in a FormLayout.

Load Data from Files:

You can load data either from XML or CSV/TXT files:

// load a XML file
JobDataXml myData1 = new JobDataXml(@"path\data.xml");

// load a CSV file
JobDataCsv myData2 = new JobDataCsv(@"path\data.csv", ',', '"');

Load Data from Database:

You can load data from an ODBC database:

// load data via an ODBC connection
JobDataOdbc myData3 = new JobDataOdbc("DSN ", "Username", "Password", "SQL select statement");

Load Data from a User-Defined DataSource

DataSources can also be defined by the user with TFORMer Designer as part of a FormLayout. Such a DataSource defines how data is retrieved (e.g. from an ODBC database), the field-mappings and optional DataSource parameters. If you want to use such a DataSource, select it by name as shown below. Use optional DataSource parameters to control certain aspects during runtime (e.g. filenames, SQL statement or an ODBC-DSN).

// retrieve data using the predefined datasource myTextDataSource
JobDataDataSource myData4 = new JobDataDataSource("myTextDataSource");

// set the value of the user-defined DataSource-Parameter parFile (defined in myTextDataSource)
myData4.ParameterValues.Add("parFile", "/YourPath/InputData.txt");

Methods for Passing Files

If properties are requesting filenames (e.g. FormLayouts or file-based data-sources (like XML or CSV)), these may be passed in the following ways:
Note: BASE64 encoded strings must start with the sequence BASE64:. When passing a zipped file TFORMer expects a real WinZip compatible format. A zipped stream is not suitable! For more details please refer to TFORMer Developer Manual.
 

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

Print the FormLayout on a Printer

Using the PrinterName property 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.JobData = myData;

// Select the printer:
printJob.PrinterName = "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.JobData = myData;

// Select the output file and type:
printJob.OutputName = @"C:\temp\myForm.pdf";
printJob.PrinterType = TECIT.TFORMer.PrinterType.PdfFile;

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


© 1998-2010
TEC-IT Datenverarbeitung GmbH
Hans-Wagner Strasse 6
A-4400 Austria
t +43 (0)7252 72720
f +43 (0)7252 72720 77
http://www.tec-it.com
office@tec-it.com