IJob.PrintToStreams method
PrintToStreams
PrintToStreams()
Print the current Job using the selected FormLayout and current JobData.
The generated output is provided via StreamData as one (or multiple) data chunks which are available as variant byte arrays. In order to utilize streaming, the following event handlers need to be implemented: OnStreamOpen, OnStreamData, OnStreamClose.
Connect the Event Receiver
In VBA, declare an early-bound Job variable with WithEvents in a class module before creating the job:
' Declare printJob to have Events connected with it automatically '
'Dim WithEvents printJob As TFORMer9Lib.Job
' Create a new Job instance '
Set printJob = tformer.CreateJob
In VBScript, connect the job to its event handlers with WScript.ConnectObject:
Dim printJob
' Create a new Job instance '
Set printJob = tformer.CreateJob
' Connect events with our "printJob" functions '
WScript.ConnectObject printJob, "printJob_"
Handle the Streams
Retrieve and process each StreamData chunk inside OnStreamData; the chunk is no longer available after the event returns. A stream may arrive in several chunks.
'-------------------------------------------------------------------------------------------'
' Event handler to create a new stream '
' This event will be fired for each requested stream before any output is generated '
' You may use this event to open files or to reserve memory '
'-------------------------------------------------------------------------------------------'
Sub printJob_OnStreamOpen(name)
MsgBox "Open Stream: " & name
End Sub
'-------------------------------------------------------------------------------------------'
' Event handler to process stream data chunks '
' This event is fired when a new data chunk is available for the current stream. '
' The event will only be triggered while inside PrintToStreams. '
' Use StreamData StreamData inside this function to fetch and process the stream data. '
' The data will not be accessible anymore after the event. '
' This event may be triggered several times for each stream. '
'-------------------------------------------------------------------------------------------'
Sub printJob_OnStreamData()
MsgBox "Received StreamData"
' StreamData returns the current chunk of stream data as variant byte array '
printJob.StreamData
End Sub
'-------------------------------------------------------------------------------------------'
' Event handler to close a stream '
' This event will be fired for each requested stream if it is no longer used '
' You may use this event for cleanup purposes '
'-------------------------------------------------------------------------------------------'
Sub printJob_OnStreamClose()
MsgBox "Close Stream"
End Sub
Generate Output
This example selects PNG output, which can create a separate stream for each page:
' Generate a PNG image named StreamToFileExample.png '
' The provided OutputName is passed to CreateStream '
' **** If multiple pages are generated page numbers will get appended (e.g. StreamToFileExample_002.png) '
printJob.OutputName = "StreamToFileExample.png"
printJob.PrinterType = PrinterType_ImagePng
' Generate output with the streaming API using the specified events '
printJob.PrintToStreams