Create a PDF with Your Layout
Setup: .NET assemblies and NuGet package. For a supplied project and layout, see the Quick Start.
On Windows, either use the NuGet package or reference an assembly from the installed SDK. On Linux, use the assemblies and native libraries from the Linux SDK package.
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 general steps for using TFORMer from .NET are:
- Add a reference to the assembly that matches the application's target runtime.
- Import the
TECIT.TFORMernamespace. - Create a
Joband select a stand-alone form layout or a repository, project, and form. - Create a job-data source and assign it to the job.
- Set the output type and destination.
- Call
Print,PrintToStream, orPrintToStreams. - Dispose the job after use.
The following C# example uses an in-memory record and creates a PDF file:
using System;
using System.IO;
using TECIT.TFORMer;
static void CreatePdf()
{
try
{
using (Job job = new Job())
{
job.RepositoryName = "FILENAME_OF_YOUR_FORMLAYOUT.tff";
JobDataRecordSet data = new JobDataRecordSet();
Record record = new Record();
record.Data.Add(
"NAME_OF_YOUR_DATAFIELD", "Value of the data field");
data.Records.Add(record);
job.JobData = data;
job.PrinterType = PrinterType.PdfFile;
job.OutputName = Path.Combine(Path.GetTempPath(), "output.pdf");
job.Print();
}
}
catch (TFORMerException exception)
{
Console.Error.WriteLine(exception.Message);
}
}
Call CreatePdf() from your application. On success, open output.pdf in the temporary directory returned by Path.GetTempPath().
For a repository-based layout, set RepositoryName, ProjectName, and FormName. The maintained C# command-line sample supplied with the SDK demonstrates this workflow with BusinessCard_Multi and several in-memory records.