AS/400 >> Printing PDF with Java

by Mark » Wed, 22 Mar 2006 22:28:27 GMT

I am asked to print PDF's directly from the AS400 and to do this with
Java. I found an open source project PDFBOX and am trying to implement
this somehow.

This library uses java.awt.PrinterJob.getPrinterJob to setup a printer
job. This bombs out with a null pointer exception:

java.lang.NullPointerException
at java.lang.Class.forName(Class.java:242)
at java.awt.print.PrinterJob$1.run(PrinterJob.java:60)
at java.awt.print.PrinterJob.getPrinterJob(PrinterJob.java:54)
at org.pdfbox.pdmodel.PDDocument.print(PDDocument.java:708)
at org.pdfbox.PrintPDF.main(PrintPDF.java:97)

Any ideas how to do this on the AS400 platform ?


AS/400 >> Printing PDF with Java

by walker.l2 » Wed, 22 Mar 2006 23:25:38 GMT


I haven't used PDFBOX, but Java printing on the AS/400 can be tricky
because you generally only have Headless AWT available. (Consequently
we call COBOL programs to generate prints. For PDFs this probably isn't
an option; it is possible that some of the OS/400 advanced printing
options will allow you to print PDFs from OS/400, but I have no
experience with them.) Is PDFBOX compatible with Headless AWT?


"AWT headless mode compatibility
To take advantage of Abstract Windowing Toolkit (AWT) headless mode,
your Java code must be noninteractive, such as code that simply
generates image data, and must not construct any heavyweight AWT
components. Heavyweight components are designed primarily for
representing interactive objects. These components require the Java
virtual machine to use an underlying graphics engine that can process
interactive events, such as the X11 window system.

When you use AWT for strictly noninteractive purposes, you may still
encounter a java.awt.HeadlessException when running in AWT headless
mode. When you encounter such an error, check your code for calls to
the constructors of the following heavyweight AWT components:

Heavyweight AWT components
Applet
Button
Checkbox
Choice
Dialog
FileDialog
Frame
JApplet
JDialog
JFrame
JWindow
Label
List
Menu
MenuBar
MenuComponent
MenuItem
PopupMenu
Robot Scrollbar
ScrollPane
TextArea
TextComponent
Window


If your Java code does construct any heavyweight AWT components, you
cannot run in AWT headless mode. You have two options:

Run NAWT with full graphical user interface (GUI) support, which
requires additional setup requirements (for example, setting up a
Virtual Network Computing X Window server, and so on)
Revise your code to eliminate calls to the heavyweight AWT components "

AS/400 >> Printing PDF with Java

by poddys » Thu, 23 Mar 2006 00:34:48 GMT

Bradley Stone has some good inexpensive PDF creation tools
(www.bvstools.com).

If this is a viable solution, you can also install PDF Creator on a PC
and set up a Printer on the AS400 to link to this. Granted the PC
needs to be on and a Printer Session active for the print to work, but
you can setup PDF Creator to automatically name (Date/Time) documents
and to go to a specific folder. It has worked well for me in the past.

Hope this helps.

AS/400 >> Printing PDF with Java

by walker.l2 » Thu, 23 Mar 2006 00:54:47 GMT

There is a free Spool File to PDF conversion tool (
http://www.code400.com/cvt2pdf.php ). The PDF files it produces are
rather large though.

I get the impression that the OP might be trying to create a PDF
directly from Java, rather than trying to convert a spool file; but I
could be wrong.

AS/400 >> Printing PDF with Java

by ben » Thu, 23 Mar 2006 02:23:02 GMT

Hi Mark,

The org.pdfbox.PrintPDF does not support headless printing right now.
You will need to write some Java to do it without popping up a dialog.

Ben

AS/400 >> Printing PDF with Java

by Niko » Thu, 23 Mar 2006 15:01:43 GMT

"Mark" < XXXX@XXXXX.COM > wrote in message
news: XXXX@XXXXX.COM ...


Hi,

I have done this with iText and it is working wery well.

There is source of printing class..only you need to download iText pdf
library(google it)
and copy Courier.ttf to IFS folder where your class file is.


import java.io.*;
import com.ibm.as400.access.*;
import com.lowagie.text.*;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.pdf.BaseFont;

public class spltopdf extends Object{

public static void main(String[] parameters){
if (parameters.length != 7 ){
System.out.println("");
System.out.println("Parameters are not correct.");
System.out.println("");
System.out.println("Command syntax is: spltopdf path name rows
cols notes library file member");
System.out.println("");
System.out.println("Syntax example is: spltopdf /mypdf order 66
198 Demo qgpl tmpspool m000001");
System.out.println("");
System.exit(0);
}

try {
String PDFPATH = parameters[0];
String PDFNAME = parameters[1];
String ROWS = parameters[2];
String COLS = parameters[3];
String LIBRARY = parameters[4];
String FILE = parameters[5];
String MEMBER = parameters[6];

System.out.println(PDFPATH);
System.out.println(PDFNAME);
System.out.println(ROWS);
System.out.println(COLS);
System.out.println(LIBRARY);
System.out.println(FILE);
System.out.println(MEMBER);

int RecordLength = Integer.valueOf(COLS).intValue();
AS400 as400 = new AS400();

QSYSObjectPathName filename = new
QSYSObjectPathName(LIBRARY, FILE, MEMBER, "MBR");

SequentialFile file = new SequentialFile(as400,
filename.getPath());

// Retrieve the record format for the file
AS400FileRecordDescription recordDescription = new
AS400FileRecordDescription(as400, filename.getPath());
RecordFormat[] format =
recordDescription.retrieveRecordFormat();
file.setRecordFormat(format[0]);
file.open(SequentialFile.READ_ONLY, 100,
SequentialFile.COMMIT_LOCK_LEVEL_NONE);

System.out.println("Start Creation of "+ PDFPATH + "/" +
PDFNAME + ".pdf");
try {
// Create the courier.ttf font object
BaseFont courier = BaseFont.createFont("courier.ttf",
BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
Font font = new Font(courier, 10f); // The fontsize is
10

float f = courier.getWidthPoint("0123456789", 10f); //
length of 10 fixed characters width
float Xpoints = Float.valueOf(COLS).floatValue() * f /
10 + 72 ; // the page width in pixels

// leading = the space between two lines, that is 1.5
times the fontsize
int leading = 15 ;
float Ypoints = (Float.valueOf(ROWS).floatValue() + 5)
* leading + 72 ; //The page height in pixels

// Create the Rectangle object in a certain color and
use this as pageSize
Rectangle pageSize = new Rectangle(Xpoints, Ypoint

AS/400 >> Printing PDF with Java

by Mark » Thu, 23 Mar 2006 17:59:00 GMT

We don't want to create PDF files, but we want to print already made
PDF files directly from the AS400. The PDF's are created by a scanning
application which scans waybills. As they are a part of our legacy
system, these are stored in the IFS structure.

On the other side we have this runtime of a report generator which also
can generate PDF's for us. This is a java runtime. This is the reason
we are lookin for a java solution.

AS/400 >> Printing PDF with Java

by Steve » Thu, 23 Mar 2006 19:34:00 GMT

k, but your sample code is to create a PDF from a file.
Could you support me with an example of java code to print an IFS PDF file
on an As400 connected printer?
Thanks
Steve

"Niko" < XXXX@XXXXX.COM > ha scritto nel messaggio
news:dvth80$ckj$ XXXX@XXXXX.COM ...



AS/400 >> Printing PDF with Java

by Mark » Thu, 23 Mar 2006 20:35:18 GMT

Well, as it is now, it does this:

PrinterJob printJob = PrinterJob.getPrinterJob();
printJob.setPageable(this);
if( printJob.printDialog() )
{
printJob.print();
}

I will need to set the printer without the dialog. Ok, that's fine. But
it already gives an excepion on the getPrinterJob. So the question is,
why is that not working. Or can't this work and do I need an
alternative for this.

AS/400 >> Printing PDF with Java

by Niko » Thu, 23 Mar 2006 21:25:02 GMT

"Steve" < XXXX@XXXXX.COM > wrote in message
news:dvu13b$q9u$ XXXX@XXXXX.COM ...
file
rows
66
is
//
/
5)
java.awt.Color(0xFF,
Document(pageSize,36,36,36,36);
IFSFileOutputStream(as400,PDFPATH+"/"+PDFNAME+".pdf",IFSFileOutputStream.SHA
com.lowagie.text.Document
of
font));
work
+

Hi,

Maybe this will help..(I'am not sure is this available in Java on iSeries)
http://java.sun.com/j2se/1.4.2/docs/guide/jps/spec/JPSTOC.fm.html

You cannot print directly because AWT printing works with underlying canvas
of OS.
As iSeries is not GUI OS this is impossible.

Only way to do it is to generate image of every page and then convert them
into PCL or PS data stream and print it with printerwriter class from java
toolbox to outq as ascii stream.
Then you can release this spool to printer or to print to lpd port of remote
printer.

Niko.





AS/400 >> Printing PDF with Java

by Steve » Thu, 23 Mar 2006 22:12:23 GMT

Thanks Niko.....
I'll check...

AS/400 >> Printing PDF with Java

by Niko » Thu, 23 Mar 2006 22:40:57 GMT

I forgot to tell you...

I am working on v5r3 with JAVA1.3 and there is ibmjps.jar
in '/QIBM/ProdData/OS400/Java400/ext/ibmjps.jar'

See more on
http://publib.boulder.ibm.com/infocenter/iseries/v5r3/index.jsp?topic=/rzaha/jvprtsrv.htm

So, it could be possible.
Cheers, NIko.

AS/400 >> Printing PDF with Java

by benno.huber » Fri, 31 Mar 2006 00:33:49 GMT

Hello Mark,

Don't know, whats missing on your AS400! Got the same error.
You should try to push your PDF document directly to your AS400
connected printer.
Any printer conforming to KPDL3 or Adobe Postscript 3 language
(Kyocera/Xerox) can print your document, without intermediate
conversion!

Create a remote outqueue with parameter "transform=*NO" (do not
transform print stream on iSeries!) as an important setting an run the
following code:

String sys = "mySystem"; /* Insert ISeries server name
*/
String user = "username"; /* Insert ISeries user profile
name */
String pass = "abc"; /* Insert ISeries password */

AS400 system = new AS400(sys, user, pass);

/* Insert ISeries output queue */
String outqname = "/QSYS.LIB/qusrsys.LIB/D1531.OUTQ";
OutputQueue outq = new OutputQueue(system, outqname);
PrintParameterList parms = new PrintParameterList();
parms.setParameter(PrintObject.ATTR_OUTPUT_QUEUE,
outq.getPath());

try{
fileout = new SpooledFileOutputStream(system, parms, null,
null);
}
catch (Exception e)
{
System.out.println("error opening spool file: " +
e.getMessage());
}

FileInputStream bfr = null;
try {

bfr = new FileInputStream("c:/temp/testpdf.pdf");
byte[] buffer = new byte[bfr.available()];
bfr.read(buffer);
fileout.write(buffer);
fileout.flush();
} catch (FileNotFoundException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}



Mark kirjoitti:

Similar Threads

1. printing pdf from java

2. printing pdf with java / cups : working. - Java GUI Programming

3. How to print print pdf on the network with OS400 4.3

    Hello,

    I have an AS400 runing the 4.3 OS version. I would like to be able
to create pdf documents from the AS400 adding Company logo and all. I
know the OS version I have can not create them, but I have CUPS on my
Mac OS X machines.

    Does any one know how I can do this? If not is there another "cheap"
solution since we will change the machine in the coming months and I
don't really want to invest in software solutions that are not needed,
afak, when runing the latest OS versions.

    TIA

-- 
Les gens sans humour manquent de sieux.

4. How to print a pdf document through java script - Asp.Net

5. PDF printing through Java

Hi all,

Does anyone know a good way of printing a PDF through Java using
JDK1.3, paid or otherwise.

We can not use any version of JRE apart from JRE1.3. Runtime.Exec
Acrobat reader is not working out since we are not able to trap errors
properly.

Regards,
Chandan

6. Printing PDF files in Java - Java

7. CUPS printing to pdf writer from Java app fails

8. How to print a pdf/any file from Java - Java