TFormer_PrintToStream
Definition
ERRCODE TFormer_PrintToStream(HTFORM pInstance, TFN_StreamWriteCallback fnWrite, LPARAM lParam);
Contract
Generates output through a callback using the current FormLayout with the adjusted DataSource.
Returns
ErrOk (0) in case of success, non-zero if an error occurred, ERR_TF_LICENSE_EXPIRED if a valid license is expired
Parameters
| Parameter / type | Description |
|---|---|
pInstanceHTFORM |
|
fnWriteTFN_StreamWriteCallback |
|
lParamLPARAM |
|
Remark
This function is similar to TFormer_Print, but delivers the generated output to fnWrite instead of writing output files or sending it directly to a printer. The same callback mechanism handles both cases below. Handle open, data and close events; data may arrive in multiple chunks for each stream.
One output stream
Formats that produce one output file, such as PDF, PostScript, Multipage TIFF and ZPL, use one stream for the output request. For example, collect the data chunks of PDF output in one application-owned buffer. This is the single-stream case of the same callback API, not a separate printing method.
Multiple output streams
Formats that produce one file per page, such as PNG or JPG, can produce several streams when the output has multiple pages. Use the open and close events to keep the streams separate; do not append data from different streams to one buffer.
Temporary files
Currently for PDF and image printer output (excluding multi-page TIFF), no temporary files are required on the file-system. All other output formats may require read/write file-system access for temporary files.
Example: PNG output with stream events
The callback skeleton below shows where to open a destination, process its data chunks and close it. Supply the application-specific handling in these branches.
// Define the call-back function for streaming
ERRCODE __stdcall StreamCallback (BYTE* pBuffer, INT nSizeBuffer, DWORD dwFlags, LPARAM lParam)
{
ERRCODE eCode = ErrOk;
if (dwFlags == eWriteCallBack_Data)
{
// Process data (copy or write the data to the stream)
}
else if (dwFlags == eWriteCallBack_Close)
{
// Close the current stream
}
else if (dwFlags == eWriteCallBack_Open)
{
// Open a new stream, the name which is set in TFormer_SetOutputName is provided via pBuffer (UTF8 encoded)
}
return eCode;
}
Select PNG output and call TFormer_PrintToStream with this callback. Each generated PNG page has its own stream.
// Generate a PNG image named StreamToFileExample.png
// The provided OutputName is passed to call-back function
// If multiple pages are generated page numbers will get appended (e.g. StreamToFileExample_002.png)
eCode = TFormer_SetOutputName (hTForm, "StreamToFileExample.png");
eCode = TFormer_SetPrinterType (hTForm, ePrinterType_ImagePng);
// Generate PNG output through the callback
// Instead of #TFormer_Print use #TFormer_PrintToStream and provide the callback function.
eCode = TFormer_PrintToStream (hTForm, StreamCallback, (LPARAM)0);
Related how-to
Generate a PDF in memory: complete C++ example using the native callback API and an application-owned byte buffer.