Print to a Printer

Start with the createPdf() method in Create a PDF with Your Layout. Keep its layout and data setup, exception handling, and dispose() in the finally block. Replace the three PDF output calls (setPrinterType, setOutputName, and print()) with one of the variants below. These calls submit a print job instead of creating a PDF file.

Windows: Default or Named Printer

To use the current user's default Windows printer through GDI:

job.setPrinterType(EPrinterType.Win32);
job.setPrinterName("");
job.print();

For a named printer, replace the empty string with its installed Windows printer name, for example job.setPrinterName("YOUR_WINDOWS_PRINTER");. The printer must be available to the account running the application. setPrinterName selects the printer; setOutputName, if used for Windows printing, supplies the spool-job title.

Linux: Named CUPS Printer

Use the Linux JNI and runtime libraries, with CUPS installed and a queue configured for the runtime account. Replace YOUR_CUPS_QUEUE with that queue's name:

job.setPrinterType(EPrinterType.Cups);
job.setPrinterName("YOUR_CUPS_QUEUE");
job.print();

After the output call succeeds, check the printer queue and printed output instead of opening output.pdf.

Search documentation

Search in
More scopes
Additional scopes

All contents