Printing is one of the most common requirements in enterprise applications built with Oracle Forms. Traditionally, Oracle developers have relied on Oracle Reports Builder to generate and send reports to printers. However, there are situations where using Reports Builder is not desirable or even possible. For example, you may want to print simple documents such as receipts, invoices, or labels directly from Oracle Forms without the overhead of designing and deploying a report.
In this guide, we will explore various methods to print directly from Oracle Forms without using Reports Builder. You will learn how to send data to a printer, use host commands, and integrate with external utilities, along with practical examples and tips.
A. Why Avoid Reports Builder?
While Oracle Reports is powerful, it introduces complexity. Avoiding Reports Builder makes sense in scenarios such as:
- Simple Output: You only need to print plain text or structured output.
- Lightweight Applications: No need for large reporting infrastructure.
- Faster Development: Quicker to implement printing directly in Forms.
- Cost Savings: Less dependency on additional licensing and support.
B. Methods to Print Directly from Oracle Forms
There are multiple approaches to bypass Reports Builder and still achieve direct printing. The choice depends on your environment, printer setup, and complexity of output.
B.1 Using HOST Built-in to Send Print Commands
Oracle Forms provides the HOST built-in, which can be used to call operating system commands. You can leverage this to send text output to a printer.
Example (Windows environment):
DECLARE
v_file VARCHAR2(200) := 'C:\temp\invoice.txt';
BEGIN
-- Write content to file
UTL_FILE.PUT_LINE(UTL_FILE.FOPEN('TEMP_DIR', 'invoice.txt', 'W'), 'Invoice #12345');
UTL_FILE.FCLOSE_ALL;
-- Send file to printer using HOST command
HOST('print ' || v_file, NO_SCREEN);
END;
Key Points:
- Works well for text files.
- Platform-dependent (
lpcommand on Linux/Unix,printon Windows). - Printer must be accessible from the application server.
B.2 Writing Directly to the Printer Port
On older setups, you can write output directly to the printer device (e.g., LPT1 on Windows or /dev/lp0 on Unix).
Example (Windows):
HOST('copy C:\temp\label.txt LPT1:', NO_SCREEN);
Example (Linux/Unix):
HOST('lp /u01/forms/temp/receipt.txt', NO_SCREEN);
This approach bypasses spooling tools and works best for dot-matrix or thermal printers.
B.3 Using UTL_FILE to Generate Print Files
You can use the UTL_FILE package to generate structured text files, and then trigger printing through the operating system.
Steps:
- Create a directory object in the database pointing to a file system location.
- Use
UTL_FILEto write the file. - Use
HOSTor external scripts to send it to the printer.
This method is flexible and allows you to build formatted output before sending it.
B.4 Integrating with Java Stored Procedures
Oracle Forms allows Java integration. You can use Java to interact with printers directly via the Java Printing API.
Advantages:
- Full control over fonts, alignment, and page layout.
- Works with modern printers that support advanced printing features.
Disadvantage:
- Requires additional setup of Java classes in the database.
B.5 Using Third-Party Utilities
Many organizations rely on external utilities for simplified printing. Examples include Ghostscript, PDF printers, or spoolers that monitor a folder and automatically print files placed there.
Typical Workflow:
- Forms writes a file (e.g., TXT or PDF).
- Utility monitors a directory.
- Files are auto-sent to the designated printer.
This is highly reliable in production environments.
C. Practical Example: Printing a Receipt
Here’s a step-by-step example of printing a simple receipt without Reports Builder:
DECLARE
v_file UTL_FILE.FILE_TYPE;
BEGIN
-- Step 1: Open file
v_file := UTL_FILE.FOPEN('TEMP_DIR', 'receipt.txt', 'W');
-- Step 2: Write content
UTL_FILE.PUT_LINE(v_file, '*** RECEIPT ***');
UTL_FILE.PUT_LINE(v_file, 'Date: ' || TO_CHAR(SYSDATE, 'DD-MON-YYYY'));
UTL_FILE.PUT_LINE(v_file, 'Item: Laptop');
UTL_FILE.PUT_LINE(v_file, 'Price: $1200');
UTL_FILE.PUT_LINE(v_file, 'Thank you for your purchase!');
-- Step 3: Close file
UTL_FILE.FCLOSE(v_file);
-- Step 4: Send to printer
HOST('lp /u01/forms/temp/receipt.txt', NO_SCREEN);
END;
This script generates a text file and sends it directly to the printer. It is quick, lightweight, and requires no reporting tools.
D. Things to Consider
When printing directly from Oracle Forms without Reports Builder, you must handle some practical challenges:
- Printer Compatibility: Ensure the printer supports plain text or PCL/PostScript if using direct commands.
- Error Handling: Build logic to handle cases where printing fails.
- Security Restrictions:
HOSTcommands may be restricted in some environments. - Cross-Platform Issues: Commands differ between Windows and Unix/Linux.
E. Best Practices
To ensure smooth printing without Reports Builder:
- Keep Layout Simple – Avoid complex formatting; stick to plain text where possible.
- Use Database Directory Objects – For safe file operations with
UTL_FILE. - Centralize Scripts – Place printing scripts on the server and call them from Forms.
- Test on Multiple Printers – Verify formatting across different models.
- Log Print Jobs – Maintain a table of print logs for troubleshooting.
Conclusion
Printing directly from Oracle Forms without Reports Builder is not only possible but often practical for lightweight and straightforward requirements. By using HOST commands, UTL_FILE, direct port access, or Java integration, you can implement flexible printing solutions that avoid the overhead of Oracle Reports. The right method depends on your application’s needs, platform, and infrastructure.
If your goal is to print simple documents such as receipts, invoices, or tickets, the approaches discussed here will give you the control and efficiency you need.

