Print a Document

This process will prompt the user to select a file through a dialog box. It will then print the selected file, using the default printer.

Display.SelectFile Title:'Please select the file that you want to print' \
                    InitialDirectory:'' \
                    FileFilter:'*.txt' \
                    IsTopMost:False \
                    CheckIfFileExists:True \
                    SelectedFile=> FileToPrint \
                    ButtonPressed=> ButtonPressed

if ButtonPressed='Open' then
                System.PrintDocument DocumentPath: FileToPrint
end

Display.ShowMessage Title:'Example completed!' \
                    Message:'Example "Print Document" completed.' \
                    Icon:Display.Icon.None Buttons:Display.Buttons.OK \
                    DefaultButton:Display.DefaultButton.Button1 \
                    IsTopMost:False \
                    ButtonPressed=> ButtonPressed

In more detail:


The process will check whether the user has selected a file and, if so, will print it using the default printer. In the end, a message will be displayed to inform the user that the process is completed.

Step 1: Select a File

Prompt the user to select a file to be printed.

Display.SelectFile Title:'Please select the file that you want to print' \
                    InitialDirectory:'' \
                    FileFilter:'*.txt' \
                    IsTopMost:False \
                    CheckIfFileExists:True \
                    SelectedFile=> FileToPrint \
                    ButtonPressed=> ButtonPressed

Use the “Display.SelectFile” action. This action displays the “Select File” dialog and prompts the user to select a file:

  1. Set the “Title” argument to “Please select the file that you want to print”. Otherwise, the default title will be displayed, which is “Open”.
  2. Set the “CheckIfFileExists” argument to “True”. This arrangement informs the user if the file was not found and prompts them to check the filename and try again. Otherwise, the process will error out.
  3. Change the output variable’s name from “SelectedFile” to “FileToPrint”

Step 2: Print the file

Check whether the user selected a file, by checking the value of the “ButtonPressed” attribute of the previous action . If a file was selected, the attribute will hold the value “Open”. If so, print the file.

if ButtonPressed='Open' then
                System.PrintDocument DocumentPath: FileToPrint
end
  1. Use the “if” statement to check whether the user pressed the “Open” button in the “Select File” dialog.
  2. Use the “System.PrintDocument” action: set the “DocumentPath” argument to “FileToPrint”, which is an output variable of the “Display.SelectFile” action (used in the first step).
  3. Close the conditional block, using the “end” statement.

Step 3: Display a message when the process is completed

Inform the user when the process is completed.

Display.ShowMessage Title:Process completed!' \

                    Message:'Process "Print Document" completed.' \

                    Icon:Display.Icon.None \

                    Buttons:Display.Buttons.OK \

                    DefaultButton:Display.DefaultButton.Button1 \

                    IsTopMost:False \

                    ButtonPressed=> ButtonPressed

Use the “Display.ShowMessage” action

  1. Set the “title” argument to “Process Completed!”.
  2. Set the “Message” argument to “Process ‘Print Document’ completed”.