How do i use java printing api 1.4

How can i print documents using jdk1.4 api.
I have used the following program for printing.
import java.io.*;
import java.awt.*;
import java.awt.print.*;
import javax.print.*;
import javax.print.attribute.*;
import javax.print.attribute.standard.*;
public class Print2DtoStream implements Printable{
public Print2DtoStream() {
/* Use the pre-defined flavor for a Printable from an InputStream */
DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
/* Specify the type of the output stream */
String psMimeType = DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType();
/* Locate factory which can export a GIF image stream as Postscript */
StreamPrintServiceFactory[] factories =
StreamPrintServiceFactory.lookupStreamPrintServiceFactories(flavor, psMimeType);
if (factories.length == 0) {
System.err.println("No suitable factories");
System.exit(0);
try {
/* Create a file for the exported postscript */
FileOutputStream fos = new FileOutputStream("out.ps");
/* Create a Stream printer for Postscript */
StreamPrintService sps = factories[0].getPrintService(fos);
/* Create and call a Print Job */
DocPrintJob pj = sps.createPrintJob();
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
Doc doc = new SimpleDoc(this, flavor, null);
pj.print(doc, aset);
fos.close();
} catch (PrintException pe) {
System.err.println(pe);
} catch (IOException ie) {
System.err.println(ie);
public int print(Graphics g,PageFormat pf,int pageIndex) {
if (pageIndex == 0) {
Graphics2D g2d= (Graphics2D)g;
g2d.translate(pf.getImageableX(), pf.getImageableY());
g2d.setColor(Color.black);
g2d.drawString("example string", 250, 250);
g2d.fillRect(0, 0, 200, 200);
return Printable.PAGE_EXISTS;
} else {
return Printable.NO_SUCH_PAGE;
public static void main(String args[]) {
Print2DtoStream sp = new Print2DtoStream();
However when i run this program,it prints "example string" as used in g2d.drawString("example string",250,250) method above.
What if i want to print content from any file.
So anybody konwing this plz reply

This is covered pretty well in the Java Print Service API Guide.
You could start here http://java.sun.com/j2se/1.4.1/docs/guide/jps/spec/printing.fm1.html
Basically, you have two choices - either you're going to throw a document at the print service, or you're going to print using Graphics2D commands. You also have the choice between printing to a printer, or to a stream. Mix and match for four combinations.
Whether you can just take a raw document and send it to a printer via the document printing stuff depends on what print services you have installed. For the standard J2SE, it's pretty limited.
If you're doing it via the Graphics2D approach, however, you can print anything you can draw. That's nice - it means you can use the same code to display stuff on the screen and print it.

Similar Messages

  • How to print a document in reverse order using Java Print API ?

    I need to print a document in reverse order using Java Print API (*Reverse Order Printing*)
    Does Java Print API supports reverse order printing ?
    Thnks.,

    deepak_c3 wrote:
    Thanks for the info.,
    where should the page number n-1-i be returned ?
    Which method implementation of Pageable interface should return the page number ?w.r.t. your first question: don't return that number but return page n-1-i when page i is requested; your document will be printed in reverse order. Your class should implement the entire interface and wrap the original Pageable. (for that number n your class can consult the wrapped interface; read the API for the Pageable interface).
    kind regards,
    Jos

  • Printing a microsoft word doc using Java Print API

    Hi,
    I have to print a microsoft word doc.I am using Java Print API, but the code is printing only Hashcodes instead of the actual document.
    Here is the code. Please let me know whats wrong in it.
    CODE:::
    public String print() throws Exception {
    String realPath = getRealPath("/images/formLibrary/csaAddressContactRequestForm100.doc");
    PrintRequestAttributeSet pras1 = new HashPrintRequestAttributeSet();
    DocFlavor flavor1 = DocFlavor.INPUT_STREAM.AUTOSENSE;
    PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
    DocPrintJob job = defaultService.createPrintJob();
    FileInputStream fis1 = new FileInputStream(realPath);
    DocAttributeSet das = new HashDocAttributeSet();
    Doc doc1 = new SimpleDoc(fis1, flavor1, das);
    job.print(doc1, pras1);
    Thread.sleep(10000);
    System.exit(0);
    return "";
    }

    By using an appropriate library. JText, whatever.
    Google, man.I think Rene meant iText!Whatever. :) Never used it, I just remembered there was something named like that. Thanks.

  • How to use java print API???  very very urgent

    Hi
    I fed up with the JAVA print API. If anybody knows how to print a file .txt, please let me know.
    cheers
    shyam

    import javax.swing.*;
    import java.util.*;
    import java.awt.*;
    import java.awt.image.*;
    import java.awt.event.*;
    import java.sql.*;
    import javax.print.*;
    import javax.print.attribute.*;
    import utility.*;
    import java.awt.print.*;
    public class remRunPrint extends JFrame implements ActionListener, Printable {
         static JButton j = new JButton("Print");
         String printer = "IT";
         java.util.Date pDate;
         public void setCopies(int i) {
              copies = i;
         public void setPrinter(String s) {
              if (s.length() > 0) {
                   printer = s;
         public void getInfo(int vid) {
              ResultSet verRS;
              try {
                   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                   Connection conn = DriverManager.getConnection("jdbc:odbc:SOMEdbnAME");
                   Statement stmt = conn.createStatement();
                   verRS = stmt.executeQuery("SOME SQL QUERY HERE");
                   verRS.next();
                   //SET SOME VARIABLES HERE..
              } catch (Exception e) {
                   System.out.println("getinfo: " + e);
    public void actionPerformed(ActionEvent e) {
    if (e.getSource() instanceof JButton) {  
                   wookie();
         public void wookie() {
              PrinterJob printJob = PrinterJob.getPrinterJob();
              Paper paper = new Paper();
              PageFormat page = new PageFormat();
              paper.setImageableArea(0, 0, 600, 800);     
              page.setPaper(paper);
              printJob.setPrintable(this, page);
              PrintService[] services = PrintServiceLookup.lookupPrintServices(null, new HashPrintRequestAttributeSet());
              PrintService ps = PrintServiceLookup.lookupDefaultPrintService();
              for (int i=0; i<services.length;i++) {
                   if (services.toString().indexOf(printer) > 0) {
                        ps = services[i];     
              try{
                   printJob.setCopies(copies);
                   //printJob.pageDialog(page);
                   printJob.setPrintService(ps);
                   //if (printJob.printDialog()) {
                        printJob.print();
              } catch (Exception e) {
                   System.out.println("wookie1run1" + e);
         public static void main(String[] args) {
              remRunPrint at = new remRunPrint();
              at.getInfo((new Integer(args[0])).intValue());
              at.drawShapes();
              at.wookie();
         public void drawShapes() {
              setBounds(0, 0, 670, 550);
              addWindowListener(new WindowAdapter() {public void windowClosing(WindowEvent e) {System.exit(0);}});
              JLabel l = new JLabel("<html><body><table><tr bgcolor=blue><td><font color=red>Hello EVERYONE</font></td></tr></table></body></html>");
              l.setBounds(20, 20, 120, 20);
              j.setBounds(10, 10, 10, 10);
              j.addActionListener(this);
              getContentPane().setLayout(null);
              getContentPane().add(l);
              getContentPane().add(j);
              show();
         public remRunPrint(){}
         public void paint(Graphics g) {
              g.setFont(new Font("SansSerif", Font.PLAIN, 6));
              g.drawString("PrintDate:", 520, 20);
              g.setFont(new Font("SansSerif", Font.BOLD, 9));
              g.drawString(pDateSTR, 550, 20);
              g.drawString("JOB: ", 23, 37);
              g.drawString("VERSION:", 310, 37);
              g.drawString("#" + vID, 310, 28);
              g.setFont(new Font("SansSerif", Font.BOLD, 18));
              g.drawString(jName, 48, 37);
              g.drawString(vName, 355, 37);
              //HERE ARE A COUPLE LINES OF AWT DRAWING TO A SCREEN THAT WORK ... IF YOU LAUNCH THIS APP FROM THE COMMAND LINE
              //IT WILL SHOW YOU WHAT YOU ARE GOING TO PRINT.. SO YOU CAN FORMAT IT AND BUILD IT FIRST THEN PRINT IT WITH THE
              //BUTTON...
         public int print(Graphics g, PageFormat pf, int pi) throws PrinterException {
    if (pi >= 1) {
    return Printable.NO_SUCH_PAGE;
              paint(g);
    return Printable.PAGE_EXISTS;

  • How to print PDF files using java print API

    Hi,
    I was goign throw lot of discusion and reading lot of forums related to print pdf files using java api. but nothing seems to be working for me. Can any one tell me how to print pdf files using java api.
    Thanks in advance

    Mike,
    Can't seem to get hold of the example described in your reply below. If you could let us have the URL to get then it would be great.
    My GUI application creates a pdf document which I need to print. I want to achieve this using the standard Java class PrinterJob (no 3rd party APIs I'm afraid, commercial restraints etc ..). I had a stab at it using the following code. When executed I get the pretty printer dialog then when I click ok to print, nothing happens!
    boolean showPrintDialog=true;
    PrinterJob printJob = PrinterJob.getPrinterJob ();
    printJob.setJobName ("Contract.pdf");
    try {
    if (showPrintDialog) {
    if (printJob.printDialog()) {
    printJob.print();
    else
    printJob.print ();
    } catch (Exception PrintException) {
                   PrintException.printStackTrace();
    Thank you and a happy new year.
    Cheers,
    Chris

  • PrintScreen Functionality using Java Print Api(without Robot)

    Hi Guys
    I have an issue to discuss,can any of you tell me that is it possible to take the screen shot of screen(not printing on paper) in java using Print Api .
    I have done it with robot but i want to do it without using Robot.
    Thanks
    Vipul

    Vipul wrote:
    can u please tell me how to implement it.i want to take the screenshot not printing a java container on paper.
    package test;
    * Screenshot.java
    import java.awt.*;
    import java.awt.print.*;
    import javax.swing.*;
    public class Screenshot extends JPanel {
        private Container container;
        public Screenshot(Container container) {
            this.container = container;
        @Override
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            container.print(g);
        //"main" only for Testing:
        public static void main(String[] args) {
            final JFrame f = new JFrame("Frame");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.setSize(500, 600);
            JPanel panel = new JPanel(new BorderLayout());
            panel.add(new JTextField("Begin"), BorderLayout.NORTH);
            panel.add(new JColorChooser());
            panel.add(new JTextField("End"), BorderLayout.SOUTH);
            f.add(panel);
            f.setVisible(true);
            new Thread(new Runnable() {
                public void run() {
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException ex) {
                    JDialog d = new JDialog(f, "Screenshot of Frame");
                    d.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
                    d.setSize(f.getSize());
                    d.setLocationRelativeTo(null);
                    d.add(new Screenshot(f.getContentPane()));
                    d.setVisible(true);
            }).start();
    }

  • Problem in using java print API

    I am facing a problem in using printAll and printComponents API.
    The application was developed in java1.1
    Now the same application is migrated to java 1.4
    But the reports are not being printed in desired format.
    The application make use of printAll() API of Component.
    Using java1.1 the print output is without the borders for components like textField or TextArea,
    whereas for java 1.4 we get border and scrollbar on print which is not the desired output.
    Can anybody suggest a solution for the same?
    here is the sample code, you can see the difference by executing this code in java1.1 and java 1.4.
    import java.awt.*;
    import java.util.*;
    public class TestPrint extends Frame implements java.awt.event.ActionListener {
    PrintJob job = null;
    //Frame aFrame = new Frame("Test Frame");
    private TextArea txaChangeNotes = null;
    private Label lb = null;
    private Panel ivjContentsPane = null;
    private Button ivjButton1 = null;
    TestPrint () {
         super("Test Frame");
         init();
    private void init() {
         ivjContentsPane = new java.awt.Panel();
         ivjContentsPane.setName("ContentsPane");
         txaChangeNotes = new java.awt.TextArea("",0,0,java.awt.TextArea.SCROLLBARS_BOTH);
         txaChangeNotes.setText("****\n&&&");
         ivjButton1 = new java.awt.Button();
         ivjButton1.setName("Button1");
         ivjButton1.addActionListener(this);
         ivjContentsPane.add(txaChangeNotes);
         ivjContentsPane.add(lb);
         ivjContentsPane.add(ivjButton1);
         this.add(ivjContentsPane);
         setSize(595, 735);
         show();
    public void actionPerformed(java.awt.event.ActionEvent e) {
         Object obj = e.getSource() ;
         if( obj instanceof java.awt.Button ){
              //Button but = e.getSource();
              print();
    private void print() {
         System.out.println("In Print");
         job = getPrintJob(this , "Print All Parts");
         //job.setPrintable(this);
         if(job!=null){
              System.out.println("Job not null");     
              /*if (job.printDialog()) {
         try {
                   System.out.println("printing");     
         job.print();
         } catch (Exception ex) {
         ex.printStackTrace();
              Graphics pg=job.getGraphics();
              if(pg!=null){
              System.out.println("graphics not null");     
                   this.requestFocus();
                   //this.printComponents(pg);
                   this.printAll(pg);
              }else{
              System.out.println("graphics null");     
                   //this.dispose();
                   return;
              pg.dispose();
         }else{
              System.out.println("job null");
              //this.dispose();
              return;
         job.end();     
    private PrintJob getPrintJob (Frame aFrame,String aString) {
         Properties printprefs = null;
         Toolkit toolkit = java.awt.Toolkit.getDefaultToolkit();
         PrintJob job = toolkit.getPrintJob(aFrame, aString, printprefs);
         /*JobAttributes jab = null;
         jab = new JobAttributes();
         PageAttributes pab = null;
         pab = new PageAttributes();
         pab.setPrinterResolution(70);
         jab.setDialog(JobAttributes.DialogType.COMMON);
    PrintJob job = Toolkit.getDefaultToolkit().getPrintJob(aFrame, aString, jab, pab);*/
         return job;
    public static void main(String arg[]){
         TestPrint objTestPrintFrame = new TestPrint();
    }

    You must not have the complete IFS_BASE_CLASSPATH defined in your CLASSPATH environment variable. The easiest way to do this is to type ". ifsenv.sh" on Solaris (or run ifsenv.bat on NT). Then you can invoke java like this:
    java -classpath $CLASSPATH:$IFS_BASE_CLASSPATH ...
    (your standard JDK classes should already be in the CLASSPATH; append our classpath to it)

  • Print .PDT,.DOC,.XLS files using java print API

    Hi,
    I need to print different types of documents like pdf, word, excel files etc.
    Please let me know how to proceed on this.
    I tried using the following code, but it is printing all junk/html tags on the paper.
    Please let me know how to resolve this.
    Thanks in advance
    import java.io.File;
    import java.io.IOException;
    import javax.print.DocFlavor;
    import javax.print.DocPrintJob;
    import javax.print.PrintException;
    import javax.print.PrintService;
    import javax.print.PrintServiceLookup;
    import javax.print.SimpleDoc;
    public class PrintDocument {
      static public void main(String args[]) throws Exception {
        try {
             PrintService defaultPrintService = PrintServiceLookup.lookupDefaultPrintService();
            DocPrintJob printerJob = defaultPrintService.createPrintJob();
            File pdfFile = new File("C:\\temp\\sample.doc");
            SimpleDoc simpleDoc = new SimpleDoc(pdfFile.toURL(), DocFlavor.URL.AUTOSENSE, null);
            printerJob.print(simpleDoc, null);
        } catch (IOException ie) {
          ie.printStackTrace();
        } catch (PrintException pe) {
          pe.printStackTrace();
    }

    Hi
    I would like to see if it was possible.  I thought it would be easy, as
    there is a standard batch processing sequence (Print 1st page of all) using
    Java that comes with Acrobat 7.  This allows you to print the first page of
    a number of files that you select when the sequence is run.  Its code is:
    /* Print 1st Page */
    /* This sequence prints the first page of
       each document selected to the default printer.
    this.print
    To my uninformed mind it seemed logical that the same code, slightly
    modified to print all pages, should work from within a form.
    Anyway, if there is a way to choose individual files, I would appreciate
    that.
    Thanks
    Rob

  • How to  print pdf file by using java print API ? I am trying with this code

    import java.io.FileInputStream;
    import java.io.InputStream;
    import javax.print.Doc;
    import javax.print.DocFlavor;
    import javax.print.DocPrintJob;
    import javax.print.PrintException;
    import javax.print.PrintService;
    import javax.print.PrintServiceLookup;
    import javax.print.SimpleDoc;
    import javax.print.attribute.HashPrintRequestAttributeSet;
    import javax.print.attribute.PrintRequestAttributeSet;
    import javax.print.attribute.standard.Copies;
    import javax.print.attribute.standard.MediaSizeName;
    public class PDFPrint {
    static public void print(InputStream inputStream, PrintService printService) throws PrintException {
    Doc doc = new SimpleDoc(inputStream, DocFlavor.INPUT_STREAM.AUTOSENSE, null);
    PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
    attributes.add(MediaSizeName.ISO_A4);
    attributes.add(new Copies(1));
    print(doc, attributes, printService);
    }//print()
    static public void print(Doc doc, PrintRequestAttributeSet attributes, PrintService printService) throws PrintException {
    if (printService == null) {
    printService = PrintServiceLookup.lookupDefaultPrintService();
    System.out.println("The Printer Name is :"+printService.getName());
    DocPrintJob docPrintJob = printService.createPrintJob();
    System.out.println("Before Print Start()");
    docPrintJob.print(doc, attributes);
    }//print()
    public static void main(String args[])
    PrintService defaultPrintService = PrintServiceLookup.lookupDefaultPrintService();
    String file="c:/BackUp/file.pdf";
    FileInputStream fis=new FileInputStream(file);
    System.out.println("Before Print() called ..");
    print(fis,defaultPrintService);
    System.out.println("After Printing....");
    I am using this code to print pdf file. But when I try this one automatically the printer starting with print ascii codes with infinite loop.
    I am using jdk1.4,Acrobat 8.0, Windows environment.
    Can u help me in this regard'
    Thank u
    grani

    import java.io.FileInputStream;
    import java.io.InputStream;
    import javax.print.Doc;
    import javax.print.DocFlavor;
    import javax.print.DocPrintJob;
    import javax.print.PrintException;
    import javax.print.PrintService;
    import javax.print.PrintServiceLookup;
    import javax.print.SimpleDoc;
    import javax.print.attribute.HashPrintRequestAttributeSet;
    import javax.print.attribute.PrintRequestAttributeSet;
    import javax.print.attribute.standard.Copies;
    import javax.print.attribute.standard.MediaSizeName;
    public class PDFPrint {
    static public void print(InputStream inputStream, PrintService printService) throws PrintException {
    Doc doc = new SimpleDoc(inputStream, DocFlavor.INPUT_STREAM.AUTOSENSE, null);
    PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
    attributes.add(MediaSizeName.ISO_A4);
    attributes.add(new Copies(1));
    print(doc, attributes, printService);
    }//print()
    static public void print(Doc doc, PrintRequestAttributeSet attributes, PrintService printService) throws PrintException {
    if (printService == null) {
    printService = PrintServiceLookup.lookupDefaultPrintService();
    System.out.println("The Printer Name is :"+printService.getName());
    DocPrintJob docPrintJob = printService.createPrintJob();
    System.out.println("Before Print Start()");
    docPrintJob.print(doc, attributes);
    }//print()
    public static void main(String args[])
    PrintService defaultPrintService = PrintServiceLookup.lookupDefaultPrintService();
    String file="c:/BackUp/file.pdf";
    FileInputStream fis=new FileInputStream(file);
    System.out.println("Before Print() called ..");
    print(fis,defaultPrintService);
    System.out.println("After Printing....");
    I am using this code to print pdf file. But when I try this one automatically the printer starting with print ascii codes with infinite loop.
    I am using jdk1.4,Acrobat 8.0, Windows environment.
    Can u help me in this regard'
    Thank u
    grani

  • HOW TO USE JAVA OWB API

    I'm sorry for my English.
    I try to use java owb api to execute process flow of my owb project from my web application. I use oracle 11g.
    I have found only this thread about use of owb api (https://kr.forums.oracle.com/forums/thread.jspa?threadID=248256&tstart=0).
    I can establish a connection, obtain the project, process flow or mapping object but i can't understand how to run it.
    Help me please
    Stefano

    > JMX and instrumentation are quite different things.
    Not that I know a great deal about either, but this is from the API:
    "Provides services that allow Java programming language agents to instrument programs running on the JVM."
    And this is from the overview I linked:
    "The Java virtual machine (JVM) is instrumented for monitoring and management, providing built-in ("out-of-the-box") management capabilities for for both remote and local access."
    That sounds at least superficially similar to me. I'll do more research when I have the time/need. Thanks for pointing it out, though.
    ~

  • How to do SAVE AS DRAFT using java mail api

    Hello,
    I want to know how to do SAVE AS DRAFT using Java mail Api.
    thanks

    Hello,
    I want to know how to do SAVE AS DRAFT using Java
    mail Api.
    thanksI don't think you can. That sounds like a feature of a mail client app itself. The Java mail API is for when you're ready to actually send the thing. Saving drafts is storing them somewhere like you would any other data; nothing to do with the mail API.

  • How can i access gmail's smtp server using java mail api

    i m using java mail api to access gmails pop and smtp service to receive and send mail from ur gmail account. I m able to access gmails pop server using the ssl and port 995 , but i can not use its smtp server to which i m connecting using ssl on 465 port. It requires authentication code.
    if anybody can help me in this regard i m thnkful to him/her.
    thnks in advance.
    jogin desai

    Here's an example of using SSL + Authentication
    http://onesearch.sun.com/search/onesearch/index.jsp?qt=ssl+authentication&subCat=siteforumid%3Ajava43&site=dev&dftab=siteforumid%3Ajava43&chooseCat=javaall&col=developer-forums

  • How to calculate call duration using java card API

    Hi,
    I am developing an application using Java card API. I want to calculate duration of otgoing calls in it. I am trying to start timer at the beginning of call in Call Control event. Can someone kindly check following code of Call control event? Here timerManagement function is sending proactive command for starting timer for 3 hours. Here I am asuming that maximum call will be of 3 hours. In callDisconnect event i can get current value of timer and use it to calculate duration of call. But this scenario is also not working.
    Problem is that during code execution program stuck at send command (proHdlr.send();) of timmerManagement function. I am sending postAsBERTLV command before starting timer so may be reason is that it is not possible to send proactive command while phone is busy.
    But I also cannot send postAsBERTLV after timerManagement function. Because it is mention in specification that "The EnvelopeResponseHandler content must be posted before the first invocation of a ProactiveHandler.send method or before the termination of the processToolkit, so that the GSM applet can offer these data to the ME (eg 9Fxx/9Exx/91xx). After the first invocation of the ProactiveHandler.send method the EnvelopeResponseHandler is no more available"
    Take a look at following code
                     * Method illustrating the use of the Call Control event.
                    private void callControlService() {
                                    /** @todo: Replace following sample code with your implementation */
                                    ProactiveHandler proHdlr = ProactiveHandler.getTheHandler();
                                    EnvelopeHandler envHdlr = EnvelopeHandler.getTheHandler();
                                    ProactiveResponseHandler rspHdlr = ProactiveResponseHandler
                                                                    .getTheHandler();
                                    EnvelopeResponseHandler envRspHdlr = EnvelopeResponseHandler
                                                                    .getTheHandler();
                                    durationCount = 0;
                                     // allow call with no modifications
                                    envRspHdlr.postAsBERTLV((byte)0x9F, (byte)0x00);
                                    // start clock using timer
                                    timerManagement(proHdlr, rspHdlr, (byte) 0x0, timer_id, tempBuffer);
                                    return;
                    }Please help me in this regard
    Thanks
    Yasir

    I am also unable to start timer in call connected event. I cannot send any proactive command while phone is busy. I am using Gemalto development Suite and there simulators (Simulation 2G chain).
    Is it limitation of simulator that you cannot send any proactive command while phone is busy?
    Is there any other work around for getting call duration?

  • How to use Java Mail API in Unix

    I am trying to write some code using Java mail API. I want to execute it in Unix. I downloaded the mail API to windows machine and ftped the mail.jar file to a Unix machine. Then I set the class path as below:
    export CLASSPATH=$CLASSPATH:/home.../mail.jar
    Then I tried to compile my Java program. The output is as below:
    error: error reading /home.../mail.jar; invalid END header (bad central directory offset)
    mail.java:1: package javax.mail does not exist
    import javax.mail.*;
    Can any one please help me out.

    You should also include the "activation.jar" file that you obtained from
    downloading the Java Activation Framework, in your CLASSPATH.
    For example:
    export CLASSPATH=$CLASSPATH:/urPath/activation/activation.jar
    Besides, assuming you unzipped javamail-1_4_1.zip in home/download the following should work
    export CLASSPATH=$CLASSPATH:home/download/javamail-1.4.1/mail.jar:.

  • Java Print API - Pages per sheet

    Hello
    I made a java application to print a file.
    Everything works fine.
    Now, I would like to be able to indicate that I want to print 2 pages per sheet.
    How can I do that?

    Thanks
    So I tried using 2 different ways: using javax.print API and using java.awt.print.PrinterJob
    Here is the code and result with the javax.print API:
    Result: the file is printed correctly but the properties I filled on the printer dialog selection, no properties has been taken: I choose monochrome, the file has been printed in colors, I choose 2 pages per sheet and 1 page has been printed each sheet.
    Code:
    import java.io.FileInputStream;
    import javax.print.Doc;
    import javax.print.DocFlavor;
    import javax.print.DocPrintJob;
    import javax.print.PrintService;
    import javax.print.PrintServiceLookup;
    import javax.print.ServiceUI;
    import javax.print.SimpleDoc;
    import javax.print.attribute.Attribute;
    import javax.print.attribute.AttributeSet;
    import javax.print.attribute.HashAttributeSet;
    import javax.print.attribute.PrintRequestAttributeSet;
    import javax.print.attribute.HashPrintRequestAttributeSet;
    import javax.print.attribute.PrintServiceAttributeSet;
    import javax.print.attribute.standard.JobName;
    import javax.print.attribute.standard.Sides;
    public class Tst4 {
         public static void main(String[] args) {
              FileInputStream fis = null;
              try {
                   PrintService[] services = PrintServiceLookup.lookupPrintServices(
                         null, null);
                   AttributeSet attributes = new HashPrintRequestAttributeSet();
                   PrintService service =  ServiceUI.printDialog(null, 50, 50,
                                            services, null, null,
                                            (HashPrintRequestAttributeSet)attributes);
                   if (service != null) {
                        fis = new FileInputStream("D:/Temp/coms/test/1.pdf");
                        Doc myDoc = new SimpleDoc(fis, DocFlavor.INPUT_STREAM.AUTOSENSE, null);
                        DocPrintJob job = service.createPrintJob();
                        try {
                             System.out.println("Printing");
                             PrintRequestAttributeSet attr_set = new HashPrintRequestAttributeSet();
                             attr_set.add(new JobName("tst.pdf", null));
                             job.print(myDoc, attr_set);
                        } catch (Exception pe) {
                           pe.printStackTrace();
              } catch(Exception e) {
                   e.printStackTrace();
              } finally {
                   try {
                        fis.close();
                   } catch(Exception ee) {}
    }Here is the code and result with the java.awt.print API:
    Result: the file has been printed correctly, the properties I choose on the printer dialog were well taken. The only problem is the printing seems to be slower.
    import java.awt.print.Book;
    import java.awt.print.PageFormat;
    import java.awt.print.PrinterJob;
    import java.io.File;
    import java.io.FileInputStream;
    import java.nio.ByteBuffer;
    import java.nio.channels.FileChannel;
    import com.sun.pdfview.PDFFile;
    import com.sun.pdfview.PDFPrintPage;
    public class Tst6 {
         public static void main(String[] args) {
              System.out.println("Begin");
              FileInputStream psStream = null;
              try {
                   File f = new File("D:/Temp/coms/test/1.pdf");
                   psStream = new FileInputStream(f);
                   FileChannel fc = psStream.getChannel();
                   ByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
                   PDFFile pdfFile = new PDFFile(bb);
                   PDFPrintPage pages = new PDFPrintPage(pdfFile);
                   PrinterJob pj = PrinterJob.getPrinterJob();
                   PageFormat pf = PrinterJob.getPrinterJob().defaultPage();
                   pj.setJobName(f.getName());
                   Book book = new Book();
                   book.append(pages, pf, pdfFile.getNumPages());
                   pj.setPageable(book);
                   if (pj.printDialog()) {
                        System.out.println("Printing");
                        pj.print();
              } catch(Exception e) {
                   e.printStackTrace();
              } finally {
                   try {
                        psStream.close();
                   } catch(Exception se) {}
              System.out.println("End");
    }What can I do to have the same result using both approached (I want to have the result of printing using java.awt libraries but using javax.print API - I want the properties on printer dialog to be taken when using javax.print API)
    Thanks
    Regards.
    Edited by: pjmorce on Feb 18, 2009 1:13 AM
    Edited by: pjmorce on Feb 18, 2009 5:51 AM

Maybe you are looking for

  • Photoshop CC 2014 Fehlermeldung "Adobe Photoshop CC 2014 funktioniert nicht mehr"

    Das Programm startet normal und nach ca. 2 - 4 Sekunden erscheint eine Fehlermeldung. Die Fehlermeldung lautet wie folgt: Das Programm wird aufgrund eines Problems nicht richtig ausgeführt. Das Programm wird geschlossen und Sie werden benachrichtigt,

  • URGENT:I need to trigger an idoc..HOW

    Hi Gurus, I need some help on the detailed steps on how to trigger MATMAS03 from R/3...i was told we can use transaction code we19. Can some one please help on this. Venkat

  • Mac Pro 2008, no soundcard with Lion

    Hi, I installed on my Mac Pro 2008 Lion and remarked, there is no more soundcard I returned to Snow Leopard and the sound worked now, I wanted to have iCloud with my other Apple Hardware, but when I restarted the Mac Pro while the Installation of Lio

  • Where should I add path of librearys before working on forms

    Hi Group, I gone through link given by you, Thanks for your replay, I feel happy If you give that path which starts with regedit\HKEY_LOCAL\SOFTWER----------------- Some thing I dont Know exactly. regards, Narendra, [email protected]

  • Multiple JRE's running on end user computer IE6

    Hi - First time poster... I was reading the other topic on the Citrix server and JRE's, so I wanted to ask if it was the same for end user computers. We have an upgrade that will be performed that will use JRE 1.4.2_06. Currently, we have 1.4.1_05 on