Try including this in your java command line:
-Djava.awt.headless=true
The default is headless = false, which means you must have a VNC server running in PASE to provide the heavyweight graphics functions. If you don't have VNC server set up and don't have headless set to true, java will return null in methods that access the awt objects.
In headless mode, you can use the objects needed to do pdf printing as the heavyweight graphics objects aren't necessary. However, the code might access these heavyweight objects as they're convenient for establishing the lightweight graphics objects.
See:
http://publib.boulder.ibm.com/infocenter/iseries/v7r1m0/index.jsp?topic=%2Frzaha%2Fnawtsupport.htm
-----Original Message-----
From: java400-l-bounces@xxxxxxxxxxxx [mailto:java400-l-bounces@xxxxxxxxxxxx] On Behalf Of Paul Bailey
Sent: Monday, October 10, 2011 8:11 AM
To: Java Programming on and around the IBM i
Subject: RE: Printing from Java
Thanks,
But I get this when I run it:
" DEFAULT PRINTER:
null argument passed
PrintServiceLookup found 0 printers
Java program completed"
I'm guessing it can't find anything. Can you verify that it finds something on your system? I called it from a submitted RPGLE program first, then tried a direct call using the JAVA cl command. Same result both times.
Can you think what might be missing in my setup given that I have a large number of printers and OUTQs setup on the iSeries.
Paul.
-----Original Message-----
From: java400-l-bounces@xxxxxxxxxxxx [mailto:java400-l-bounces@xxxxxxxxxxxx] On Behalf Of Thorbjørn Ravn Andersen
Sent: 10 October 2011 12:37
To: 'Java Programming on and around the IBM i'
Subject: RE: Printing from Java
Add /QIBM/ProdData/OS400/Java400/ext/ibmjps.jar to your class path.
Then the javax.print.* stuff should work.
Try this:
import javax.print.DocFlavor;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
public class Printers {
/**
* @param args
*/
public static void main(String[] args) {
PrintService defaultPrintService;
defaultPrintService =
PrintServiceLookup.lookupDefaultPrintService();
System.out.println("DEFAULT PRINTER:");
describe(defaultPrintService);
System.out.println("");
PrintService[] services;
services = PrintServiceLookup.lookupPrintServices(null,
null);
System.out.println("PrintServiceLookup found " + services.length
+ " printers");
for (int i = 0; i < services.length; i++) {
PrintService service = services[i];
System.out.println("PRINTER " + i);
describe(service);
System.out.println("");
}
}
private static void describe(PrintService printService) {
if (printService == null) {
System.out.println("null argument passed");
return;
}
System.out.println("Name: " + printService.getName());
DocFlavor[] flavors = printService.getSupportedDocFlavors();
for (int i = 0; i < flavors.length; i++) {
DocFlavor flavor = flavors[i];
System.out.println("F " + flavor);
}
Class[] categories =
printService.getSupportedAttributeCategories();
for (int i = 0; i < categories.length; i++) {
Class class1 = categories[i];
System.out.println("A " + class1);
}
}
}
-----Original Message-----
From: java400-l-bounces@xxxxxxxxxxxx [mailto:java400-l-bounces@xxxxxxxxxxxx]
On Behalf Of Paul Bailey
Sent: 10. oktober 2011 12:53
To: JAVA400-L@xxxxxxxxxxxx
Subject: Printing from Java
Hi,
I am trying to print a PDF using Java called from RPGLE. I know there are all sorts of problems with PDF printing but I think I have a potential solution in using the PDFRenderer package from Sun. The problem I am currently having is that the java.awt.print.PrinterJob.getPrinterJob()
method is returning a nullpointer exception.
I'm thinking that I am going about this all wrong as AWT is not really implemented properly on the iSeries. What iSeries print options are available through java400? Can I send a spooled file to (or even use) an OUTQ at all? Or is that side of things totally disconnected when using Java?
Regards,
Paul.
------------------------------------------------------------
Important
This email transmission and any files with it are strictly confidential to the intended recipient and may be legally privileged. Any views or opinions presented are solely those of the author and do not necessarily represent those of BHSF. If you are not the intended recipient, you must not copy, disclose or distribute its contents in any way.
If you have received this e-mail in error, please notify the sender and delete the e-mail from your system.
We have taken steps to ensure this e-mail and attachments are free from any virus but do not accept any responsibility once this e-mail has been transmitted. You should scan any attachments for viruses.
No contract may be concluded on behalf of BHSF Limited by e-mail.
Registered Office:
BHSF Limited
Gamgee House, 2 Darnley Road, Birmingham B16 8TE.
www.bhsf.co.uk
Registered in England number 35500.
BHSF is authorised and regulated by the Financial Services Authority.
As an Amazon Associate we earn from qualifying purchases.