M
Mike Grace
Hi,
I have the following code which produces a printout to a user chosen printer
destination.
Is there a java method which will enable me to output the printout to a
TIF/BMP/JPG easily rather than the print destination?
I need it so that I can attach the tif image to an email or fax.
Regards
Mike
public class Print2DPrinterJob
implements Printable {
public Print2DPrinterJob() {
int f = 0;
String Test = "";
/* Construct the print request specification.
* The print data is a Printable object.
* the request additonally specifies a job name, 2 copies, and
* landscape orientation of the media.
*/
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(OrientationRequested.PORTRAIT);
aset.add(new Copies(1));
aset.add(new JobName("Test", null));
/* Create a print job */
PrinterJob pj = PrinterJob.getPrinterJob();
pj.setPrintable(this);
/* locate a print service that can handle the request */
PrintService[] services =
PrinterJob.lookupPrintServices();
if (services.length > 0) {
for (f = 0; f < services.length; f++) {
Test = services[f].getName();
if (Test.equals("Unimessage Pro") == true) {
break;
}
}
// System.out.println("selected printer " + services[f].getName());
try {
pj.setPrintService(services[f]);
//pj.pageDialog(aset);
if (pj.printDialog(aset)) {
pj.print(aset);
}
}
catch (PrinterException pe) {
System.err.println(pe);
}
}
}
public int print(Graphics g, PageFormat pf, int pageIndex) {
Font cmdfnt = new Font("Commands", Font.PLAIN, 12);
Font arialfnt = new Font("Arial", Font.PLAIN, 12);
if (pageIndex == 0) {
Graphics2D g2d = (Graphics2D) g;
// Sets the top left position on the page.
g2d.translate(pf.getImageableX(), pf.getImageableY());
g2d.setColor(Color.black);
g2d.setFont(cmdfnt);
g2d.drawString("[[TO=01293 786747]]", 0 * 72, 100);
g2d.setFont(arialfnt);
g2d.drawString("This is a fax", 1 * 72, 250);
g2d.setFont(cmdfnt);
g2d.drawString("[[END]]", 0 * 72, 300);
// g2d.fillRect(0, 0, 200, 200);
return Printable.PAGE_EXISTS;
}
else {
return Printable.NO_SUCH_PAGE;
}
}
}
I have the following code which produces a printout to a user chosen printer
destination.
Is there a java method which will enable me to output the printout to a
TIF/BMP/JPG easily rather than the print destination?
I need it so that I can attach the tif image to an email or fax.
Regards
Mike
public class Print2DPrinterJob
implements Printable {
public Print2DPrinterJob() {
int f = 0;
String Test = "";
/* Construct the print request specification.
* The print data is a Printable object.
* the request additonally specifies a job name, 2 copies, and
* landscape orientation of the media.
*/
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(OrientationRequested.PORTRAIT);
aset.add(new Copies(1));
aset.add(new JobName("Test", null));
/* Create a print job */
PrinterJob pj = PrinterJob.getPrinterJob();
pj.setPrintable(this);
/* locate a print service that can handle the request */
PrintService[] services =
PrinterJob.lookupPrintServices();
if (services.length > 0) {
for (f = 0; f < services.length; f++) {
Test = services[f].getName();
if (Test.equals("Unimessage Pro") == true) {
break;
}
}
// System.out.println("selected printer " + services[f].getName());
try {
pj.setPrintService(services[f]);
//pj.pageDialog(aset);
if (pj.printDialog(aset)) {
pj.print(aset);
}
}
catch (PrinterException pe) {
System.err.println(pe);
}
}
}
public int print(Graphics g, PageFormat pf, int pageIndex) {
Font cmdfnt = new Font("Commands", Font.PLAIN, 12);
Font arialfnt = new Font("Arial", Font.PLAIN, 12);
if (pageIndex == 0) {
Graphics2D g2d = (Graphics2D) g;
// Sets the top left position on the page.
g2d.translate(pf.getImageableX(), pf.getImageableY());
g2d.setColor(Color.black);
g2d.setFont(cmdfnt);
g2d.drawString("[[TO=01293 786747]]", 0 * 72, 100);
g2d.setFont(arialfnt);
g2d.drawString("This is a fax", 1 * 72, 250);
g2d.setFont(cmdfnt);
g2d.drawString("[[END]]", 0 * 72, 300);
// g2d.fillRect(0, 0, 200, 200);
return Printable.PAGE_EXISTS;
}
else {
return Printable.NO_SUCH_PAGE;
}
}
}