Overview

This document provides an instructional guide on how to print PDFs within the server domain using the TPrintPDF.exe utility. It explains how to automate PDF printing in server scripts by creating a new process, triggered via a method in the ServerMain class, as shown in the attached example.

On this page:


What is the DataAccess API?

TPrintPDF is a module that handles the output of PDF documents during runtime. It integrates with applications to automate the process of sending PDFs to a printer without manual steps, streamlining the workflow within the runtime environment.

Module Requirements and Usage Instructions

The module requires the inclusion of System.Diagnostics in the namespace declarations, as it will be invoked using the Process method.

To use the utility, three parameters must be set: the file path for the PDF location, the printer to be used, and the page orientation. The page orientation options are 0 for the default setting, 1 for Portrait, and 2 for Landscape. If no value is provided for the page orientation, it defaults to 0.

Note: Regarding the printer name, you can locate it by searching for "Printers & Scanners" in Windows.

Once the setup is complete, pass the necessary information to a new Process as follows:

 ProcessStartInfo startInfo = new ProcessStartInfo
    {
        FileName = fileExec,
        Arguments = arguments,
    };


Here, FileName is the path to the module, with the default location in the FrameworX folder, accessible via:
Path.Combine(@Info.Product.GetProductPath(), "TPrintPDF.exe");

The Arguments parameter includes the PDF file path, printer name, and orientation, formatted as:

"c:/ExamplePath/Example.pdf" "Printer 1" 1

It then attempts to initiate a new process using the specified startInfo, waiting for the process to complete before continuing execution. The Using statement ensures that all resources associated with the process are properly disposed of after it finishes running.


Sample Method Implementation

The method implemented below demonstrates a standard application of the TPrintPDF utility. It can be invoked from any location, allowing the caller to customize the file path, printer name, and orientation as needed for each specific instance.

public void PrintPDF(string filePath, string printerName, int orientation)
{
	@Info.Trace(@Info.Product.GetProductPath());
	string fileExec = Path.Combine(@Info.Product.GetProductPath(), "TPrintPDF.exe");
	string arguments = $"\"{filePath}\" \"{printerName}\" {orientation}";
	
    ProcessStartInfo startInfo = new ProcessStartInfo
    {
        FileName = fileExec,
        Arguments = arguments,
    };

    try
    {
        using (Process process = Process.Start(startInfo))
        {
			@Info.Trace(arguments);
            process.WaitForExit();
        }
    }
    catch (Exception ex)
    {
       @Info.Trace($"Error starting the process: {ex.Message}");
    }
}

In this section...

  • No labels