Java Printing API - Unable to print on HP LaserJet

Hi,
I'm trying to use Java's printing API to print a PDF file onto a network/local printer.
My code works fine when I try printing onto Canon printers but the behavior is erratic on HP LaserJet printers.
I've tried using two different models of HP LaserJet (4050 Series and 1020 Series )
1. On HP LaserJet 4050 Series PS the print job is processed, but the printer outputs junk/ascii characters instead of the actual pdf
2. On HP LaserJet 1020 Series the print job reaches the queue but stays there indefinitely with the status message 'Printing'.
After this the only way to bring the printer back alive is to shut it down and restart it again.
In both these cases printing from any other application works fine, I run into these issues while using the printing API.
Here's a code snippet that demonstrates the way my client code is written.
  PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
  pras.add(new Copies(1));
  pras.add(MediaSizeName.ISO_A4);
  DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE; 
  ByteArrayInputStream bytesinputStream =  new ByteArrayInputStream(myPDFfileContent);
  //'printJob' was obtained by iterating over PrintServiceLookup.lookupPrintServices(null, pras);
  DocPrintJob job = printJob.getPrintService().createPrintJob();
  doc = new SimpleDoc(bytesinputStream, flavor, new HashDocAttributeSet());
  job.print(doc, pras);I'm hoping that someone has experienced this issue before and can help me with this..
Thank you....

plz try to download the following set of drivers from the link below :::\
http://gimp-print.sourceforge.net/MacOSX.php3
This is a new set of default drivers and mayhelp u in resolving the issue.
Plz do run disk first aid after installing the driver....might suggest even before installaing.
Thanx !! for trying.

Similar Messages

  • Using an HP officejet pro 8500 wireless printer and unable to print anything web based/inte​rnet

    checked wireless connection and it is fine but unable to print anything that is web based like an airline itinerary. McAfee says it is not the firewall. Any ideas?

    Are you able to print other things than web based ? Like word documents, etc.
    What behaviour you may see while printing from the web?
    As well, did you tried the HP Smart Print toolbr Application?
    http://h41112.www4.hp.com/bing_toolbar2/us/en/smar​t.html?jumpid=ex_r602_ww/en/hho/ipg/xx-mu-aw_chev/​...
    Say thanks by clicking the Kudos thumb up in the post.
    If my post resolve your problem please mark it as an Accepted Solution

  • Printing BUT unable to print more than one copy

    When printing, I'm unable to print more than one copy

    Still need help, I want more than one print of one picture in a set.

  • ABLE TO PRINT IMAGES, UNABLE TO PRINT BOOKS!

    I saw a message a while back with the same problem, but with no answer. Please help! I can print images, but i can't print a book's page, unless there's only text in the page!
    Thank you for your help!
    MacBook Pro   Mac OS X (10.4.8)  

    Aperture.
    Print image: YES
    Print book: NO
    Print book page with text only: YES
    Print book page with image: NO
    Print book page with text and image: NO
    Generated PDF from within Aperture, then tried printing it: same behaviour (got prints only for pages with text only).
    Any other PDFs in my computer print fine, whether pages with images, photos, text or combination of all of them.
    It seems that aperture is not only unable to print from its own system, but it inherits those flaws to the PDFs it generates as well.
    PLEASE HELP!
    Thank you.
    MacBook Pro   Mac OS X (10.4.8)  

  • PSE  9 fails to show print preview unable to print?

    Changed printer from HP to Canon today and cannot get into the print from PSE 9 mac - no image on photo. I re-installed PSE 9 and still the problem remains.
    CF

    sfwta wrote:
    I had a diagnostic test done on my Mac OSX 9.6.8 no problems there.
    <snip>
    if I buy the PSE 12 version, would I have the same problem?
    PSE12 requires a minimum of OSX 10.7 - http://www.adobe.com/uk/products/photoshop-elements/tech-specs.html - so you wouldn't be able to run it at all on 9.6.8.
    Cheers,
    Neale
    Insanity is hereditary, you get it from your children
    If this post or another user's post resolves the original issue, please mark the posts as correct and/or helpful accordingly. This helps other users with similar trouble get answers to their questions quicker. Thanks. on 9.6.8

  • 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

  • J4680 unable to print on heavier media

    Hello!
    I have big problems printing one stronger media. Plane paper (80 g/m²) works reasonably good. I have some 250 g/m² inkjet glossy photo paper and 160 g/m² special inkjet matt paper. The printer is unable to print on both of these papers. It tries to pick it up but always ends in a paper jam. I think the problem is the turning of the page and the rear paper rollers just next to the print head, I think they are too tight so the paper can't pass trough.
    Is there any way to fix this?
    regards,
    Alex

    You're on a Mountain Lion forum, but your post above says you're runnijng Snow Leopard.   Hmmm....
    I will assume you're running Mountain Lion.  Here's the troubleshooter:
    OS X Mountain Lion: If a document doesn’t print

  • Problem with Java Print API ( awt ) : Migrated from 1.1 to 1.4

    We had migrated an application ( applet based) from Java 1.1.8 to java 1.4.
    We use the java.awt.print apis for printing data from our applications.
    There is difference in print quality after the migration. For e.g. if the data frame had a scroll bar when taken print out, the scroll bar was not visible in java1.1 version application but is being printed with java1.4 version.
    We are unable to find the cause of this problem. Any help in this regard would be of great help.
    Thanks in advance.

    Hi,
    thanks, this solved the problem.
    Thank you.
    Best regards,
    Peter

  • Java Printer API

    I have problems printing .doc,.xls...files....need to print multple file formats in my program and i'm unable to print the above formats....As far as i knw the API does not have a way to do it.....pls help me on this..
    Dilshan

    you need a 3rd party product to do it or do some nice jni programming. TideStone has such a product for Java (or at least that is what they used to be called, I believe the company has been sold). Also there is some interesting things you can do with a product called JPrint.

  • 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.

  • Printing a PDF document using Java 1.4 Printing API

    Hi,
    When I tried to print a PDF document using JAVA 1.4 Printing API, I got the following exception.
    Exception in thread "main" sun.print.PrintJobFlavorException: invalid flavor
    at sun.print.Win32PrintJob.print(Win32PrintJob.java:290)
    at Printing.main(Printing.java:40)
    I am able to print the same PDF document using Acrobat reader.
    Is PDF format not supported in JAVA 1.4 printing API? or is something wrong in my code?
    here is the sample JAVA program that I was using
    import javax.print.*;
    import javax.print.attribute.*;
    import java.io.*;
    public class Printing {
    public static void main(String args[]) throws Exception {
    String filename = args[0];
    PrintRequestAttributeSet pras =
    new HashPrintRequestAttributeSet();
    DocFlavor flavor = DocFlavor.INPUT_STREAM.PDF;
    PrintService defaultService =
    PrintServiceLookup.lookupDefaultPrintService();
    DocPrintJob job = defaultService.createPrintJob();
    FileInputStream fis = new FileInputStream(filename);
    DocAttributeSet das = new HashDocAttributeSet();
    Doc doc = new SimpleDoc(fis, flavor, das);
    job.print(doc, pras);
    Thread.sleep(10000);
    System.exit(0);
    Thank you
    Sumana

    Here's a pure Java solution (that works!):
    http://www.mycgiserver.com/~zhouwu/pdf/readme.html
    The caveats are:
    - prints only to the default printer
    - requires a properties file located in the home directory
    my workaround for the last:
         * Print a PDF file to the default printer (might consume lots of memory!).
         * <p>
         * <b>Required:</b>
         * <ul>
         * <li>a file "acrobat.properties" needs to be in the working directory. The content is:
    <table align="center" bgcolor="#E0E0E0" border=1 cellpadding="10" cellspacing="0"><tr><td><pre style="margin-top:0; margin-bottom:0">
    #com.adobe.acrobat.Viewer Properties
    #Wed Oct 29 20:34:05 PST 2003
    com.adobe.acrobat.AcceptedLicAgreement=true
    com.adobe.acrobat.Fax_Fine_Mode=true
    com.adobe.acrobat.Find\:FindAll=false
    com.adobe.acrobat.Find\:FindBackwards=false
    com.adobe.acrobat.Find\:FindWholeWord=false
    com.adobe.acrobat.Find\:MatchCase=false
    com.adobe.acrobat.Open_Dialog_Directory=C\:\\temp\\
    com.adobe.acrobat.Open_Dialog_File=itext.pdf
    com.adobe.acrobat.Print_Method_Known=true
    com.adobe.acrobat.Shrink_To_Fit=false
    com.adobe.acrobat.SitePreferencesURL=file\://localhost/C\:/pdf/acrobat-site.properties
    com.adobe.acrobat.Use_Print_Server=false
    com.adobe.acrobat.util.fontDirectories=C\:\\Winnt\\Fonts
    com.adobe.acrobat.util.fontIgnoreExtensions=.fon;.pfm;.ini;.lst;.txt;.doc;.ttmap;.z;.enc;.dir;.afm;.f3b;.pfa;.spd;.ps;.bepf;.map;.alias;.scale;.all;.upr
    </pre></td></tr></table>
         * <li>The JAR files PDFPrinter.jar, acrobat.jar and MRJToolkitStubs.zip in the CLASSPATH.
         * </ul>
         * <p>
         * Note: the file "acrobat.properties" is expected to be in the user's home directory. As this is not always feasible,
         * the system property "user.home" is mapped to "user.dir" for the time of execution.
         * @param fileName Name of PDF file to print.
         * @throws Exception on error.
         * @see <a href="http://www.mycgiserver.com/~zhouwu/pdf/readme.html">PDF Server (Silent) Printing</a>
        public void printPDF(String fileName) throws Exception {
            String oldHome = System.getProperty("user.home");
            System.setProperty("user.home", System.getProperty("user.dir"));
            PDFPrinter vi = new PDFPrinter();
            vi.activate();
            vi.setDocumentInputStream(new FileInputStream(fileName));
            vi.printAll();
            System.setProperty("user.home", oldHome);
        }//printPDF()I just need the following additional files in my CLASSPATH: PDFPrinter.jar, acrobat.jar and MRJToolkitStubs.zip. Despite the note at the site above that "printing quality is not very good", i can't agree: the print quality is quite good. Not perfect, but acceptable for most uses.
    (Tested on Windows 2000 SP4, J2SE 1.4.2_03, hp laserjet 2300dn)

  • 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)

  • Problem with too small page size using Java 2D Printing API.

    Hello,
    I have problem with resolution of printer using Java 2D Printing API. Despite my printer has 600 x 600 DPI, inside java.awt.print.Printable.print(Graphics, PageFormat, int) I receive page format with 600 x 840 page size.
    I have tried to set resolution using javax.print.attribute.PrintRequestAttributeSetand javax.print.attribute.standard.PrinterResolution, but with no result.
    Can anybody solve this problem?
    Regards,
    Karl.

    600 x 840 is a Point value; Point is defined as 1/72nd of an inch. Printers do have much higher DPI than this, but I believe that this DPI has to do with richness of the printed image, not an actual ability to color with that level of resolution. You might want to try calling zoom on your Graphics2D object. Otherwise, I don't know what else you can try.

  • 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();
    }

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

Maybe you are looking for