Cannot import javax.print.*;

Hi All,
I have to send a file to printer Directly.
For this i want to use java print service API.
I installed J2SE 1.4.2
But i could not import javax.print.*;
Plese help me.

The package javax.print was added in Java version 1.4, so if you are using 1.4.2 you should be able to use it.
Are you sure you are using Java 1.4.2? Don't you have another version of Java installed somewhere? Open a command prompt and type:
java -version
Which version does it say you're using?

Similar Messages

  • Cannot Import javax.swing.JOptionPane   Please HELP!!!

    import javax.swing.JOptionPane;
    this line of code returns the error:
    C:\Java Files\BankAccount\BankAccount_Test.java:1: Class javax.swing.JOptionPane not found in import.
    import javax.swing.JOptionPane;
    ^
    1 error
    Process completed.
    Please help, I don't know what the problem could be....

    Swing was not part of any JDK's earlier than 1.2. Swing (or anything with a J in front of it, ie. JFrame, JOptionPane, etc...) was probably the most dramatic (if not largest) modification/addition to the Java language, that's why versions later than, and including, 1.2 are known as "Java 2".

  • Cannot import javax.servlet

    Hello,
    I'm trying to write a javabean to use with in jsp code.
    In the bean I need to use <code>HttpServletResponse and for this I need to add :
    </code>import javax.servlet.*;
    import javax.servlet.http.*;
    this throws me the exception : package javax.servlet does not exist.
    CLASSPATH = .;D:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\servlet-api.jar;D:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\jsp-api.jar;D:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\el-api.jar;
    I have no idea where I need to include this class.
    Thanks in advance for your help.

    No idea about Netbeans, but in Eclipse you can just accosiate an application server with the web project, then it will automatically take its libraries (the javax.servlet and so on) in the buildpath.

  • Cannot import  javax.faces.model

    Dear friends,
    Greetings,
    I want to use the model classes : ArrayDataModel, ListDataModel,ResultSetDataModel, etc. ,,,
    According to "core JavaServer Faces" Book ( Sun - By David Geary ),
    Chapter 5( Data Tables) , these classes are in javax.faces.model.
    Iam using Oracle JDeveloper 10g Early Access . Trying
    import javax.faces , faces is not in the drop list of javax .
    Please advise .... thanks and regards
    Salah Beidas

    Hello,
    I don't know Oracle JDeveloper, but I don't think it is different from other IDE's:
    You have to add the JSF library to your project.
    I personnaly downloaded jsf-1_1_01.zip, unzipped it in C:\java\jsf-1_1_01
    Then right-clicked on project libraries to add this library:
    C:\java\jsf-1_1_01\lib\jsf-api.jar
    Hope this will help!

  • Cannot import javax.jms

    I've installed J2SE 1.3.1_01 and J2EE 1.3_01. I use Forte for Java CE 3.0. When I type import javax.
    I get nothing!
    Why I cant use javax ????
    Please help an new Java-Fan

    Typing! It's realy a bad thing. I thought I can use the J2EE Packeges (J2EE.JAR), but the only way I can do it is in building a own Package of the class-files included there!
    Have you an idea?

  • Cannot Import javax.servlet.* and javax.servlet.http.*

    Hello,
    I am a University Student and now doing a project using Servlet and JSP
    I have installed WinXP and Tomcat 5.0 on my computer
    When I compile the servlet , there are error messages "package javax.servlet does not exist" and "package javax.servlet.http does not exist" coming out.
    I have set the classpath already
    i.e. %CATALINA_HOME%\common\lib\servlet-api.jar;%CATALINA_HOME%\common\lib\jsp-api.jar
    ( Of course "%CATALINA_HOME%" = my folder that install the Tomcat )
    Can Anybody Explain what is happening and suggest a solution to me?
    Please give a hand.

    When you ran that command, what happened? Let javac.exe tell you the right answer.
    I'd advise two things:
    (1) Installing any s'ware in a directory whose name contains spaces (e.g., "Apache Software Foundation" or "Tomcat 5.0") is a very bad idea, IMO. I'd reinstall to a new directory.
    (2) Your HelloServlet.java servlet probably doesn't have a package statement in it. Tomcat 5.0 won't play nicely with servlets or beans that aren't in packages. I'd add one and use the -d . option on javac.exe to make sure it created the package directory structure for me.

  • Cannot import javax.servlet onto classpath

    Hi guys, newbie question.
    Im using jedit on linux; compiling with j2sdk1.4.2_04 but it will not pick up the javax.serlet
    classes!! Is there an add on I need to download to develop j2ee stuff, as I thought j2sdk1.4.2_04 was all that was required.
    Thanks in advance

    Wrong. You need a JAR that has the javax.servlet and javax.servlet.http packages, and they don't come with the J2SE.
    If you want to run servlets/JSPs, you must have a servlet/JSP engine. If you already have one, root around for the servlet JAR. If don't, download Tomcat. It's Sun's reference implementation for the servlet/JSP specifications. The servlet JAR will be in the TOMCAT_HOME/common/lib directory.

  • How can I print a html Using javax.print

    Hi friends,
    I am in big trouble . I use following code to print a html file using javax.print api.
    import java.io.*;
    import javax.print.*;
    import javax.print.attribute.*;
    import javax.print.attribute.standard.*;
    import javax.print.event.*;
    public class PrintPS
         public static void main(String args[]) {
              PrintPS html = new PrintPS();
         public PrintPS() {
         DocFlavor flavor = DocFlavor.INPUT_STREAM.TEXT_HTML_HOST;
         PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
         aset.add(MediaSizeName.ISO_A4);
         aset.add(new Copies(1));
         aset.add(MediaTray.MAIN);
         PrintService pservices = PrintServiceLookup.lookupDefaultPrintService();
         if(pservices==null)
              System.out.println(" printer not found");
         if (pservices!= null) {
         System.out.println("selected printer " + pservices.getName());
         DocPrintJob pj = pservices.createPrintJob();
         try {
         InputStream fis = new FileInputStream("abc.html");
         Doc doc = new SimpleDoc(fis, flavor, null);
    System.out.println("printing started ");
         pj.print(doc, aset);
    System.out.println("printing completed");
         } catch (IOException ie) {
         System.err.println(ie);
         } catch (PrintException e) {
         System.err.println(e);
    This code gives me "sun.print.PrintJobFlavorException: invalid flavor"
    So i use all four TEXT_HTML flavor but i do not find the solution.
    I am able to print pdf, jpg, gif files but i can not able to print txt and html file.
    My printer supports txt and html printing becaue i do printing directolly by browser's or notpad's print command .

    Hi friends,
    I am in big trouble . I use following code to print a
    html file using javax.print api.Use Code Tags
    http://forum.java.sun.com/help.jspa?sec=formatting
    My printer supports txt and html printing becaue i do
    printing directolly by browser's or notpad's print
    command .Notepad & your browser prob. convert to the HTML/text(1) into the printers native format.
    1) I am suprised that it does not print text.

  • Javax.print problem: data not of declared type

    Hi all,
    I'm trying to print a simple text-only document with the below code but it keeps giving me an illegal argument exception. By the way, I've tried all the combinations of DocFlavor.*.* and SERVICE_FORMATTED.PRINTABLE and SERVICE_FORMATTED.PAGEABLE are the only ones working for me. Is this normal?
    Thanks!
    IllegalArgumentException:
    java.lang.IllegalArgumentException: data is not of declared type
            at javax.print.SimpleDoc.<init>(SimpleDoc.java:82)
            at DiagnosticsPane.actionPerformed(DiagnosticsPane.java:350)
    import java.io.*;
    import javax.print.*;
    import javax.print.attribute.*;
    class testPrint
         public static void main(String args[])
              PrintRequestAttributeSet pras =     new HashPrintRequestAttributeSet();
              DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
              PrintService ps[] = PrintServiceLookup.lookupPrintServices(flavor, pras);
              PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
              PrintService service = ServiceUI.printDialog(null, 200, 200, ps, defaultService, flavor, pras);
              if (service != null) {
                   try {
                        DocPrintJob job = service.createPrintJob();
                        DocAttributeSet das = new HashDocAttributeSet();
                        FileInputStream fis = new FileInputStream("report.txt");
                        Doc doc = new SimpleDoc(fis, flavor, das);
                        try {
                             job.print(doc, pras);
                             System.err.println("Job sent to printer.");
                        } catch (PrintException e) {
                             System.err.println("Print error!\n\n" + e.getMessage());
                   } catch (FileNotFoundException e) {
                        System.err.println("File not found!\n\n" + e.getMessage());
    }

    Hi duffymo,
    I've tried all the available DocFlavors and even wrote a little program to list all my supported DocFlavors. And, I've only got 2 available for each of my printers, one being a Canon i320 and the other is a Adobe PDF printer.
    import javax.print.*;
    import javax.print.attribute.*;
    class listDocFlavor
      public static void main(String args[])
        PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
        DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
        PrintService ps[] = PrintServiceLookup.lookupPrintServices(flavor, pras);
        for (int j = 0; j < ps.length; j++) {
          DocFlavor df[] = ps[j].getSupportedDocFlavors();
          for (int i = 0; i < df.length; i++)
            System.err.println(j + ": " + df);
    0: application/x-java-jvm-local-objectref; class="java.awt.print.Pageable"
    0: application/x-java-jvm-local-objectref; class="java.awt.print.Printable"
    1: application/x-java-jvm-local-objectref; class="java.awt.print.Pageable"
    1: application/x-java-jvm-local-objectref; class="java.awt.print.Printable"

  • PDF printing using javax.print

    Hi!
    I need to create an aplication that generates a PDF document and then prints it. For creating the PDF doc, I use the iText package.
    I have some problems with printing. I don't know how to print the document I generate. Could you give me a hint please? (I can print GIF docs, yet I do not know how to convert the PDF to GIF).
    Thanks in advance,
    Alex

    import javax.print.*;
    import javax.print.attribute.DocAttributeSet;
    import javax.print.attribute.HashDocAttributeSet;
    import javax.print.attribute.HashPrintRequestAttributeSet;
    import javax.print.attribute.PrintRequestAttributeSet;
    import javax.print.attribute.standard.Copies;
    import javax.print.attribute.standard.MediaSizeName;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    public class PDFfilePrinter {
    public static void main(String[] args) {
    DocAttributeSet fset = new HashDocAttributeSet();
    PrintRequestAttributeSet pset = new HashPrintRequestAttributeSet();
    String filename = "somefile.pdf"; //name of file to print
    DocFlavor docf = DocFlavor.INPUT_TYPE.PDF;
    PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
    if (0 < services.length) {
    DocPrintJob printer = services[0].createPrintJob(); //default printer on my system
    try {
    FileInputStream fis = new FileInputStream(filename);
    Doc toprint = new SimpleDoc(fis, docf, fset);
    pset.add(MediaSizeName.ISO_A4);
    pset.add(new Copies(1));
    printer.print(toprint, pset);
    } catch (PrintException e) {
    e.printStackTrace();
    } catch (FileNotFoundException fnfe) {
    fnfe.printStackTrace();
    Here's the code I'm working with for printing. This stuff works .... in a very strange way - it prints out all sort of crazy characters. I know I am doing something wrong and I think it's all in this line:
    DocFlavor docf = DocFlavor.INPUT_TYPE.PDF;
    Should I use a different flavor? I read somewhere that the PDF file format is not entirely supported bye javax.print. Could this be the problem?
    Thanks in advance,
    Alex

  • Javax.print problems on applet - bug on mac os implementation?

    Dear All,
    I am working on an applet and application that include a print function and I get a weird behaviour on MacOS in applet mode (both with Safari and Firefox - Mac OS X Versione 10.4.9 (Build 8P135) ). In contrast, things work fine on Windows XP (both Explorer 7 and Firefox with Java Plug-in 1.6.0_01) and even in MacOS when using the application.
    The problems are:
    - the print dialogue goes on and off a few times before letting the user interact with it
    - the page format in the dialogue is set to A5 (instead of the printer's default)
    - there is a small empty window appearing together with the dialogue and not disappearing even after the applet is closed
    Is this a known problem? If so, are there work-arounds?
    (I had no luck on Google about this)
    To reproduce the problem I created a stripped down version of the applet, in 2 files, I report it at the bottom of this message. I am using a modified version the PrintUtilities class from http://www.apl.jhu.edu/~hall/java/Swing-Tutorial/Swing-Tutorial-Printing.html
    Am I doing something wrong? Or shall I consider submitting a bug report?
    Any suggestion is welcome! Please let me know if I should provide more detailed information.
    Thank you in advance,
    Enrico
    PrintMe.java
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import javax.swing.JApplet;
    import javax.swing.JPanel;
    public class PrintMe extends JApplet implements MouseListener{
         private static final long serialVersionUID = 1L;
         private JPanel jContentPane = null;
         public PrintMe() {
              super();
         private class MyComponent extends JPanel{
              private static final long serialVersionUID = 1L;
              public void paintComponent(Graphics g) {
                   super.paintComponent(g);
                  Graphics2D g2 = (Graphics2D) g;
                  g2.setColor(Color.black);
                  g2.drawString( "Test text", 0, g2.getFontMetrics().getHeight() );
         public void init() {
              MyComponent aComponent = new MyComponent();
              jContentPane = new JPanel();
              jContentPane.setLayout(new BorderLayout());
              jContentPane.add(aComponent);
              this.setContentPane(jContentPane);
              this.addMouseListener(this);
         public void print(){
              try{
                   PrintUtilities.printComponent(this);
              }catch (Exception e) {
                   e.printStackTrace();
         public void mouseClicked(MouseEvent e) {
              print();
         public void mouseEntered(MouseEvent e) {
              // not used
         public void mouseExited(MouseEvent e) {
              // not used
         public void mousePressed(MouseEvent e) {
              // not used
         public void mouseReleased(MouseEvent e) {
              // not used
    PrintUtilities.java
    import java.awt.Component;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.print.PageFormat;
    import java.awt.print.Printable;
    import java.awt.print.PrinterException;
    import java.awt.print.PrinterJob;
    import javax.print.attribute.HashPrintRequestAttributeSet;
    import javax.print.attribute.PrintRequestAttributeSet;
    import javax.swing.RepaintManager;
    import javax.swing.RootPaneContainer;
    /** A simple utility class that lets you very simply print
    *  an arbitrary component. Just pass the component to the
    *  PrintUtilities.printComponent. The component you want to
    *  print doesn't need a print method and doesn't have to
    *  implement any interface or do anything special at all.
    *  If you are going to be printing many times, it is marginally more
    *  efficient to first do the following:
    *    PrintUtilities printHelper = new PrintUtilities(theComponent);
    *  then later do printHelper.print(). But this is a very tiny
    *  difference, so in most cases just do the simpler
    *  PrintUtilities.printComponent(componentToBePrinted).
    *  7/99 Marty Hall, http://www.apl.jhu.edu/~hall/java/
    *  May be freely used or adapted.
    public class PrintUtilities implements Printable {
         private Component componentToBePrinted;
         public static void printComponent(Component c) {
              new PrintUtilities(c).print();
         public PrintUtilities(Component componentToBePrinted) {
              this.componentToBePrinted = componentToBePrinted;
         public void print() {
              try{
                   PrinterJob printJob = PrinterJob.getPrinterJob();
                   printJob.setPrintable(this);
                   PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
                   if( printJob.printDialog(attributes) ){
                        try {
                             printJob.setJobName("MyName");
                             printJob.print(attributes);
                        } catch(PrinterException pe) {
                             System.err.println("Error printing: " + pe);
                             pe.printStackTrace();
              }catch (Exception e) {
                   e.printStackTrace();
         public int print(Graphics g, PageFormat pageFormat, int pageIndex) {
              if (pageIndex > 0) {
                   return(NO_SUCH_PAGE);
              } else {
                   RootPaneContainer rpc = (RootPaneContainer)(this.componentToBePrinted);
                   rpc.getRootPane().getGlassPane().setVisible( false );
                   Graphics2D g2d = (Graphics2D)g;
                   double sy = pageFormat.getImageableHeight() / componentToBePrinted.getHeight();
                   double sx = pageFormat.getImageableWidth() / componentToBePrinted.getWidth();
                   if( sx > sy ){
                        sx = sy;
                   }else{
                        sy = sx;
                   g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
                   g2d.scale(sx, sy);
                   disableDoubleBuffering(componentToBePrinted);
                   componentToBePrinted.paint(g2d);
                   enableDoubleBuffering(componentToBePrinted);
                   return(PAGE_EXISTS);
         /** The speed and quality of printing suffers dramatically if
          *  any of the containers have double buffering turned on.
          *  So this turns if off globally.
          *  @see enableDoubleBuffering
         public static void disableDoubleBuffering(Component c) {
              RepaintManager currentManager = RepaintManager.currentManager(c);
              currentManager.setDoubleBufferingEnabled(false);
         /** Re-enables double buffering globally. */
         public static void enableDoubleBuffering(Component c) {
              RepaintManager currentManager = RepaintManager.currentManager(c);
              currentManager.setDoubleBufferingEnabled(true);
    }

    Trying to answer to myself..
    Is it possible that the problems are due to me mixing java.awt.print and javax.swing.print ?

  • Javax.print

    hi
    In which jar can i find the following packages?
    javax.print.*;
    javax.print.attribute.*;
    javax.print.attribute.standard.*;
    javax.print.event.*;

    Hi ,
    I am getting the following error when accessing the DOCFlavor method of the javax.print package.I am using j2sdk1.4.1_02.I am in urgent need of this code.Please help
    D:\JavaSCTest>javac PrintToStream.java
    PrintToStream.java:16: cannot access javax.print.DocFlavor
    bad class file: c:\j2sdk1.4.1_02\jre\lib\rt.jar(javax/print/DocFlavor.class)
    class file has wrong version 48.0, should be 47.0
    Please remove or make sure it appears in the correct subdirectory of the classpa
    th.
    DocFlavor flavor = new DocFlavor("image/gif","java.io.InputStream");
    ^
    1 error

  • Importing  javax.swing.plaf.basic.BasicListUI.MouseInputHandler

    Hi!!
    I have totally no idea why I cannot import javax.swing.plaf.basic.BasicListUI.MouseInputHandler. The compiler says BasicListUI interface is expected.

    Agreed (maybe even so for 1.4.1 that I've just wiped out so I can't cehck my old rt.jar :o).
    For the moment I use my old translation of the basic.properties (and windods.properties) packed in a jar-file placed in
    jreXX/lib/ext/myLanguage.jar
    So far it works for the dialogs in my applications ...
    However, I don't find this a clean solution. I now find basic.class in rt.jar. Juged from all the other basic_xx.class files in rt.jar I guess this is where basic.properties went ... My next move will be to get hands on the source code of JAVA and check out how basic.java looks like ... perhaps this is a class filled with static fields and a simple method that sets properties in memeory or ? or ? ... In particular I need find out if some 'fields' have been added or removed compared to the old basic.properties. If so, the old translation would only be parial and my apps would be a mix of danish and english.
    I'm not really that much of a JAVA programmer and this is just to share some thoughts. Does anyone out there know a central reference on how those of us that speak minority languges easily get translations of core JAVA stuff (meaning Yes, No, Cancel and the like) take effect the easy way? Are there national boards that take care of such business?
    Maybe I haven't searched enough for information - my apologies if you found it waste of time reading this reply.
    With kind regards and thanks in advance, MJTJ

  • Epson all in one printer - compatible with 10.9.5? Cannot import from scanner in Preview

    Got a new Epson printer. Set up is fine; wirelessly connected.  Downloaded and updated all drivers. Still cannot import from scanner into Preview. Anyone else? Seems like this was a problem in 2013 as far as I can see from other forum discussions. Any advice?  Scanner works manually so it's the set up, compatibility or...?

    What do you mean "import from scanner to Preview?"
    Does the scanner actually scan, if so what file format (jpg, pdf, tiff, etc...) are you scanning in? Once you have successfully scanned simply open Preview and open the file. Another method is selecting the scanned file, right click and select Open With and select Preview.

  • Getting an error like this The import javax.servlet cannot be resolved

    HI
    i am getting an error like this "The import javax.servlet cannot be resolved".wht i ahve done in eclipse right click->open->servlet->packge name->servlet name->next->nexyt>finish.hereinterfaces is javax.servlet.Servlet.
    do i need add jar for it.can any one tell me why i got error like this.
    vijay

    Please don't doublepost. Answer is given here: http://forum.java.sun.com/thread.jspa?threadID=5220686

Maybe you are looking for

  • ICloud with Numbers: Only Works In One Direction?

    Hello, Trying to get started with iCloud and a problem from the outset; I use two computers; iMac OS10.8.5 Macbook Pro OS10.9.2 and Numbers 2.3 on both. When I upload to my iCloud the files can be read by both computers if I upload from my Macbook, b

  • Testing ASP pages in DW CS3?

    Hello. I need to start learning ASP, so I bought a book on it. I opened up a (very simple) sample ASP page from the accompanying CD ROM in Dreamweaver (CS3). The page opened and was viewable, but when I clicked F12 to preview in a browser, the page d

  • Can't See ERP Integrator in Workspace

    Hello, I have installed and apparently successfully configured ERP Integrator on 11.1.1.3, Windows 2003 R2. Now when I goto workspace -> navigate -> administer I don't see ERP Integrator. Bear in mind that I do not have ODI installed yet, (for variou

  • Quicktime Player can't convert .avi files

    So I have a project where we have to make a trailer for a book of our choice and I was assigned video editor. A group member sent me some footage we had gotten with an old flip. I downloaded it but quicktime player couldn't open it. It told me to see

  • Files and Streams Question

    Hi! Java is my first and only language; and I am very new to Java. This is my first somewhat knowledgeable attempt to get a question answered on a forum of any kind. I put a question in this forum about two weeks ago, but I lost it. So, I am very gra