Create a PDF with Your Layout
Setup: Windows build. For a supplied project and layout, see the Quick Start.
The general native C workflow is:
- Define
TECIT_DLLIMPORTand includeTFormer.h. - Initialize the library with
TFormer_Init. - Select a stand-alone form layout or a repository, project, and form.
- Select the output type and destination.
- Add records and set the required data-field values.
- Generate the output with
TFormer_PrintorTFormer_PrintToStream. - Check each return code and release the handle with
TFormer_Exit.
For optional settings such as image resolution, use TFormer_SetPrintOptions; see Output Options. Options that affect field assignment must be set before supplying those fields, as described for unknown field names.
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 Windows example creates a PDF file and performs cleanup on every path. Place both code blocks in the same source file and build it as described in Build on Windows. For Linux, use the supplied Linux build script and sample.
#include <stdio.h>
#define TECIT_DLLIMPORT
#include "TFormer.h"
#undef TECIT_DLLIMPORT
#define CHECK(call) \
do { \
result = (call); \
if (result != ErrOk) { \
LPCSTR message = TFormer_GetLastErrorDescription(form); \
fprintf(stderr, "%s failed: %s\n", #call, \
message != NULL ? message : "no error description"); \
goto cleanup; \
} \
} while (0)
int main(void)
{
ERRCODE result = ErrOk;
HTFORM form = TFormer_Init(NULL);
if (form == NULL)
return 1;
CHECK(TFormer_SetRepositoryName(
form, "FILENAME_OF_YOUR_FORMLAYOUT.tff"));
CHECK(TFormer_SetPrinterType(form, ePrinterType_PDFFile));
CHECK(TFormer_SetOutputName(form, "output.pdf"));
CHECK(TFormer_NewRecord(form));
CHECK(TFormer_SetVarValue(
form, "NAME_OF_YOUR_DATAFIELD", "Value of the data field"));
CHECK(TFormer_Print(form));
cleanup:
if (form != NULL) {
ERRCODE exitResult = TFormer_Exit(form);
if (result == ErrOk)
result = exitResult;
}
return result == ErrOk ? 0 : 1;
}
Run the program from a writable working directory. On success, open output.pdf in that directory.
For a repository-based layout, call TFormer_SetRepositoryName, TFormer_SetProjectName, and TFormer_SetFormName. The maintained TFORMerSimple.c sample supplied with the Windows SDK demonstrates a repository-based job with several records and complete error reporting. Find it under the installed Windows samples; use its supplied repository and field names when running that sample.
After selecting a repository, project, or form again, supply your programmatically defined records again before generating output.