Create a PDF with Your Layout

Setup: Java interface. For a supplied project and layout, see the Quick Start.

The general steps for using TFORMer from Java are:

  1. Import the com.tecit.TFORMer, enumeration, and printing packages.
  2. Create a Job.
  3. Select a stand-alone form layout or a repository, project, and form.
  4. Create a job-data source and assign it to the job.
  5. Set the output type and destination.
  6. Call print, printToStream, or printToStreams.
  7. Call dispose in a finally block.

For optional settings such as image resolution, call Job.setOptions before generating output; see Output Options.

Before running this example, create a stand-alone .tff file in TFORMer Designer or use an existing one. Replace FILENAME_OF_YOUR_FORMLAYOUT.tff with its path and NAME_OF_YOUR_DATAFIELD with the exact name of a data field used by that layout. See Designer documentation for layout authoring and installed sample locations for the supplied programming examples.

The following example uses an in-memory record and creates a PDF file:

import com.tecit.TFORMer.*;
import com.tecit.TFORMer.Enumerations.*;
import com.tecit.TFORMer.Printing.Job;
import com.tecit.TFORMer.Printing.JobDataRecordSet;
import com.tecit.TFORMer.Printing.JobDataRecordSet.Record;
import java.io.File;

public static void createPdf() {
    Job job = null;
    try {
        job = new Job();
        job.setRepositoryName("FILENAME_OF_YOUR_FORMLAYOUT.tff");

        JobDataRecordSet data = new JobDataRecordSet();
        Record record = new JobDataRecordSet.Record();
        record.setData(
            "NAME_OF_YOUR_DATAFIELD", "Value of the data field");
        data.add(record);
        job.setJobData(data);

        job.setPrinterType(EPrinterType.PDFFile);
        job.setOutputName(System.getProperty("java.io.tmpdir")
                + File.separator + "output.pdf");
        job.print();
    } catch (TFormerException exception) {
        exception.printStackTrace();
    } finally {
        if (job != null) {
            try {
                job.dispose();
            } catch (TFormerException exception) {
                exception.printStackTrace();
            }
        }
    }
}

Add the method to your application class, place the imports at the top of the source file, and call createPdf(). On success, open output.pdf in the temporary directory given by java.io.tmpdir.

For a repository-based layout, call setRepositoryName, setProjectName, and setFormName. The maintained Java command-line sample uses the installed demo repository and BusinessCard_Multi.

Search documentation

Search in
More scopes
Additional scopes

All contents