Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Can I output a printout as a tif?

Reply
Thread Tools

Can I output a printout as a tif?

 
 
Mike Grace
Guest
Posts: n/a
 
      08-27-2003
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;
}
}

}


 
Reply With Quote
 
 
 
 
Mike Grace
Guest
Posts: n/a
 
      08-27-2003
Thanks Marco.

I'll take a look.

I am a bit of a Java newbie

Mike

"Marco Schmidt" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Mike Grace:
>
> [...]
>
> >Is there a java method which will enable me to output the printout to a
> >TIF/BMP/JPG easily rather than the print destination?

>
> Create a BufferedImage, call getGraphics on it and use that Graphics
> object to draw as you do with your g2d object. Then save the image to
> a file:
> <http://www.geocities.com/marcoschmidt.geo/java-image-coding.html>.
>
> Gruß,
> Marco
> --
> Please reply in the newsgroup, not by email!
> Java programming tips: http://jiu.sourceforge.net/javatips.html
> Other Java pages: http://www.geocities.com/marcoschmidt.geo/java.html



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
simple sorting a Range program can not run(work or printout) eric C++ 3 07-13-2011 11:36 AM
TreeMap printout order chunji08@gmail.com Java 3 03-08-2006 05:14 AM
Imbedding Word Files in Printout Bill Dennis Java 0 12-05-2003 09:50 PM
updated exam printout Mark Scott MCSE 3 11-02-2003 02:18 PM
printout of object property settings TJS ASP .Net 0 10-17-2003 05:17 PM



Advertisments