Can I output a printout as a tif?

Discussion in 'Java' started by Mike Grace, Aug 27, 2003.

  1. Mike Grace

    Mike Grace Guest

    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;
    }
    }

    }
    Mike Grace, Aug 27, 2003
    #1
    1. Advertising

  2. Mike Grace

    Mike Grace Guest

    Thanks Marco.

    I'll take a look.

    I am a bit of a Java newbie :)

    Mike

    "Marco Schmidt" <> wrote in message
    news:...
    > 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
    Mike Grace, Aug 27, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. TJS
    Replies:
    0
    Views:
    284
  2. Bill Dennis

    Imbedding Word Files in Printout

    Bill Dennis, Dec 5, 2003, in forum: Java
    Replies:
    0
    Views:
    307
    Bill Dennis
    Dec 5, 2003
  3. Replies:
    2
    Views:
    1,583
    Andrew Thompson
    May 19, 2007
  4. eric
    Replies:
    3
    Views:
    302
    Victor Bazarov
    Jul 13, 2011
  5. JeffP-> @discussions.microsoft.com>

    Can't Login to webapp, view tif's files when not logged in Server

    JeffP-> @discussions.microsoft.com>, Oct 21, 2005, in forum: ASP .Net Security
    Replies:
    0
    Views:
    131
    JeffP-> @discussions.microsoft.com>
    Oct 21, 2005
Loading...

Share This Page