Java API

Java API Reference — Types, members and enumerations.

New to TFORMer? Create your first PDF with the Java Quick Start. It includes a complete Windows example and its form layout. Continue here for interface details and Linux setup.

Introduction

The Java interface is a Java Native Interface (JNI) layer over the TFORMer native runtime. A Java application needs three release-matched components:

  • Java API: JTFORMer9.jar
  • JNI bridge: TFORMer9JNI.dll for 32-bit Windows or TFORMer9JNIx64.dll for 64-bit Windows; Linux packages provide the corresponding libTFORMer9JNI.so shared-library chain
  • Native runtime: TFormer9.dll for 32-bit Windows or TFormer9x64.dll for 64-bit Windows; Linux packages provide the corresponding libTFORMer9.so shared-library chain

Add the JAR to the class path. Make the JNI library and native TFORMer runtime available through java.library.path or the supported platform library-search mechanism. Use Java 8 or later and keep all components from the same SDK release and architecture.

In an IDE such as Eclipse or NetBeans, add the JAR to the project's libraries and configure the native-library search path for its run configuration. A reusable user library is optional; adding the JAR alone does not configure the native runtime.

For SDK installation and component locations, see Windows installation or Linux installation.

Use a Configured Data Source

Select the ODBC source in the supplied picking-list layout, set PickingListParameter to 2, and write a PDF. The layout's stored query uses this parameter to select that picking list; the application does not supply a separate SQL statement or modify the database. For definition settings, field mappings and parameter rules, see Data Sources Defined in a Layout.

For a configured CSV source instead, adapt this program to choose the CSV file at runtime.

Before You Run

  • Set up the SDK for your language, including its native runtime and matching process architecture.
  • Locate (6) Samples_Picking List.tff in the SDK's Templates folder. The default Windows location is %ProgramData%\TEC-IT\TFORMer\9\Templates.
  • The layout uses DSN=TFORMer_Sample;, user admin, table tbl_PickingList, and the predefined parameter PickingListParameter. Its driver and DSN must match the application's architecture.
  • The sample database is ODBCReportPDF.mdb, installed under %ProgramData%\TEC-IT\TFORMer\9\Examples\Command Line\ODBCReportPDF. The sample DSN must point to this database. This particular example uses the Windows Access ODBC driver; it is not a Linux setup example.
  • Choose a new PDF path in an existing writable directory. The program refuses to overwrite an existing output file.

Run the Example

Pass the full layout path and PDF path as the two command-line arguments.

Save the program as ConfiguredSource.java. As in the Java Quick Start, add JTFORMer9.jar to the compiler and runtime class paths, and make the matching JNI library and its native dependencies available. Run ConfiguredSource with the two paths, quoted if they contain spaces.

Use setJobData(...) to attach the data object. The finally block calls dispose() even if printing fails.

Complete Example

import com.tecit.TFORMer.Printing.Job;
import com.tecit.TFORMer.Printing.JobDataDataSource;
import com.tecit.TFORMer.Enumerations.EPrinterType;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class ConfiguredSource {
    public static void main(String[] args) {
        if (args.length != 2) {
            System.err.println("Usage: ConfiguredSource <layout.tff> <output.pdf>");
            System.exit(1);
        }
        try {
            Path layout = Paths.get(args[0]).toAbsolutePath();
            Path output = Paths.get(args[1]).toAbsolutePath();
            if (!Files.isRegularFile(layout))
                throw new IllegalArgumentException("Layout not found: " + layout);
            if (Files.exists(output))
                throw new IllegalArgumentException("Choose a new output file: " + output);

            Job job = new Job();
            try {
                job.setRepositoryName(layout.toString());

                // Select the stored definition and override its parameter.
                JobDataDataSource data = new JobDataDataSource("ODBC");
                data.setParameterValue("PickingListParameter", "2");
                job.setJobData(data);

                // Generate a PDF; no physical printer is used.
                job.setPrinterType(EPrinterType.PDFFile);
                job.setOutputName(output.toString());
                job.print();
            } finally {
                job.dispose();
            }
            if (!Files.isRegularFile(output) || Files.size(output) == 0)
                throw new IllegalStateException("No PDF was created: " + output);
            System.out.println("Created PDF: " + output);
        } catch (Exception | LinkageError error) {
            System.err.println(error.toString());
            System.exit(1);
        }
    }
}

Check the Result

Open the PDF at the path reported by the program. Check that it contains picking list 2, not the layout parameter's default selection 1. Evaluation output may include a demo marking.

If no PDF is produced, check the reported error, layout path, ODBC driver, DSN and database before changing the parameter value. For the other data-input mechanisms, see Providing Job Data.

Apply a License

Apply your license during application initialization, before the first output operation. With Base64 license data supplied by TEC-IT, use:

com.tecit.TFORMer.TFORMer.licenseBase64(
    "BASE64_LICENSE_DATA_FROM_TEC_IT");

Replace the placeholder with your license data and keep it confidential. The call can throw TFormerException; catch it or declare it in the enclosing method, and do not continue to output after a failed call. See Licensing for license types, validity and file-based licensing.

Reference and Sample Links

Use the Java programming reference and the maintained programming samples supplied with the selected SDK release.

Find the installed samples under Windows: Sample Applications and Templates or Linux: Sample Applications. For installed and online references, see Interface Guides and API References.

The SDK also retains a legacy Java/J2EE servlet sample for historical reference. It generates a PDF and writes it to the HTTP response, but its build and deployment script is not current guidance.

Search documentation

Search in
More scopes
Additional scopes

All contents