GeeCON Prague 2014*
The moose likes BEA/Weblogic and the fly likes No Printer Found Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Products » BEA/Weblogic
Bookmark "No Printer Found" Watch "No Printer Found" New topic
Author

No Printer Found

Manjunatha Reddy
Greenhorn

Joined: Sep 27, 2005
Posts: 1
Hi all,
i have written a java programme to do print for 1000 pages for 30 times.
When i run the application as standalone it works fine but when i deploy it in weblogic and test it through my browser , spool is gonna hung after 9 printouts(i.e after spooling 9*1000 9000 pages).. please do help me in solving this.. Find below the Exception and programme

Exception....

java.awt.print.PrinterException: No printer found.
at sun.awt.windows.WPrinterJob._startDoc(Ljava.lang.String V(WPrinterJob.java:???)
at sun.awt.windows.WPrinterJob.startDoc()V(WPrinterJob.java:1066)
at sun.print.RasterPrinterJob.print(Ljavax.print.attribute.PrintRequestAttributeSet V(Optimized Method)
at sun.print.RasterPrinterJob.print()V(Optimized Method)
at com.dhl.src.PrintUtility.print(Ljava.lang.String V(Optimized Method)
at com.dhl.src.PrintAction.execute(Lorg.apache.struts.action.ActionMapping;Lorg.apache.struts.action.ActionForm;Ljavax.servlet.http.HttpServletRequest;Ljavax.servlet.http.HttpServletResponse Lorg.apache.struts.action.ActionForward;(Optimized Method)
at org.apache.struts.action.RequestProcessor.processActionPerform(Ljavax.servlet.http.HttpServletRequest;Ljavax.servlet.http.HttpServletResponse;Lorg.apache.struts.action.Action;Lorg.apache.struts.action.ActionForm;Lorg.apache.struts.action.ActionMapping Lorg.apache.struts.action.ActionForward;(Optimized Method)
at org.apache.struts.action.RequestProcessor.process(Ljavax.servlet.http.HttpServletRequest;Ljavax.servlet.http.HttpServletResponse V(Optimized Method)
at org.apache.struts.action.ActionServlet.process(Ljavax.servlet.http.HttpServletRequest;Ljavax.servlet.http.HttpServletResponse V(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doGet(Ljavax.servlet.http.HttpServletRequest;Ljavax.servlet.http.HttpServletResponse V(ActionServlet.java:507)
at javax.servlet.http.HttpServlet.service(Ljavax.servlet.http.HttpServletRequest;Ljavax.servlet.http.HttpServletResponse V(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(Ljavax.servlet.ServletRequest;Ljavax.servlet.ServletResponse V(HttpServlet.java:853)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run()Ljava.lang.Object;(ServletStubImpl.java:1006)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(Ljavax.servlet.ServletRequest;Ljavax.servlet.ServletResponse;Lweblogic.servlet.internal.FilterChainImpl V(Optimized Method)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(Ljavax.servlet.ServletRequest;Ljavax.servlet.ServletResponse V(Optimized Method)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run()Ljava.lang.Object;(Optimized Method)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(Lweblogic.security.subject.AbstractSubject;Ljava.security.PrivilegedAction Ljava.lang.Object;(Optimized Method)
at weblogic.security.service.SecurityManager.runAs(Lweblogic.security.acl.internal.AuthenticatedSubject;Lweblogic.security.acl.internal.AuthenticatedSubject;Ljava.security.PrivilegedAction Ljava.lang.Object;(Optimized Method)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(Lweblogic.servlet.internal.ServletRequestImpl;Lweblogic.servlet.internal.ServletResponseImpl V(Optimized Method)
at weblogic.servlet.internal.ServletRequestImpl.execute(Lweblogic.kernel.ExecuteThread V(Optimized Method)
at weblogic.kernel.ExecuteThread.execute(Lweblogic.kernel.ExecuteRequest V(Optimized Method)
at weblogic.kernel.ExecuteThread.run()V(ExecuteThread.java:178)
at java.lang.Thread.startThreadFromVM(Ljava.lang.Thread V(Unknown Source)


Programme:::

package com.dhl.src;
/**
* Class: POCCode <p>
*
* Print in Java
* This program takes an argument
* Example :- java POCCode 1
* if the value is 1, it prints using the PRINTER_1
* else it prints in the PRINTER_2
*
*/




import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.TextArea;
import java.awt.print.Book;
import java.awt.print.PageFormat;
import java.awt.print.Paper;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;

import javax.print.PrintService;


public class PrintUtility {


/**
* Constructor: POCCode <p>
* @throws PrinterException
*
*/
public PrintUtility ()
{

}

public void PrintJob(String printer )
{
// Create a new PrinterJob object
PrinterJob prnJob = PrinterJob.getPrinterJob ();
PrintDetails m_pr = new PrintDetails();

// get the paper_width and paper_hieght using properties file
int paper_width=getInt(m_pr.getProperty("PAPER_WIDTH"));
int paper_height=getInt(m_pr.getProperty("PAPER_HEIGHT"));

PageFormat format = new PageFormat();
Paper paper=new Paper();
// Set the imagable area to 300.0 and 435.0
paper.setImageableArea(0.0,0.0,paper_width,paper_height);

// Set the paper size to 300 width and 435 width.
paper.setSize(paper_width,paper_height);
format.setPaper(paper);

prnJob.setPrintable(new Document(),format);

/**
*
* Get the value from the properties file to print to
* the appropriate printer (Preferred Printer)
* Property names are
* 1. PRINTER_1
* 2. PRINTER_2
* Example :-
* PRINTER_1=Microsoft Office Document Image Writer
* PRINTER_2=\\\\igtewf39\\TVS MSP 345/Champion/XL Classic
*
* PRINTER_2 is having the proper value while PRINTER_1 is not.
* Printer name should have the server name Pre-fixed to it.
*
*/

String prefferedPrinter = null;
prefferedPrinter=printer;
//
// if("1".equals(printer))
// {
// prefferedPrinter = m_pr.getProperty("PRINTER_1");
// }
// else if("2".equals(printer))
// {
// prefferedPrinter = m_pr.getProperty("PRINTER_2");
// }
// else if("3".equals(printer))
// {
// prefferedPrinter = m_pr.getProperty("PRINTER_3");
// }
//
/**
*
* Get the printer from the list.
* Print the contents to the printer
* There might be lot of Printers configured in the system
* We have to get the contents printed on our preferred Printer.
*
*/

PrintService[] array = PrinterJob.getPrinterJob().lookupPrintServices();
int device= -1;
for (int i=0; i<array.length;i++)
{
if(prefferedPrinter.equalsIgnoreCase(array[i].getName())) device=i;
System.out.println(array[i].toString());
}
try
{
prnJob.setPrintService(prnJob.lookupPrintServices()[device]);
prnJob.setCopies(1);
prnJob.print();
}
catch(PrinterException ex)
{
ex.printStackTrace();
}
}

/**
* Class: Document <p>
*
* This class is the painter for the document content.<p>
*
*/
public class Document implements Printable {

int pageNumber;
/**
*
*/
public Document()
{
}
/**
* Method: print <p>
*
* @param g a value of type Graphics
* @param pageFormat a value of type PageFormat
* @param page a value of type int
* @return a value of type int
*/
public int print (Graphics g, PageFormat pageFormat, int page) {


// Create the Graphics2D object
Graphics2D g2d = (Graphics2D) g;
// Translate the origin to 0,0 for the top left corner
g2d.translate (pageFormat.getImageableX (), pageFormat.getImageableY ());

// Set the drawing color to black
g2d.setPaint (Color.black);


Coordinates m_cor = new Coordinates();
PrintDetails m_pr = new PrintDetails();

String font_type=m_pr.getProperty("FONTTYPE");
int font_size=getInt(m_pr.getProperty("FONTSIZE"));

/**
*
* Read the property file to print the contents
* at the correct Coordinates
* The Coordinates can be changed in the coor.properties file.
*
*/

if ( page >= (getInt(m_pr.getProperty("COPIES")))) return Printable.NO_SUCH_PAGE;

if(page == 0)
{
g2d.drawString("START PAGE", (getInt(m_cor.getProperty("X_COOR"))+getInt(m_cor.getProperty("DESCRIPTION_X"))), (getInt(m_cor.getProperty("Y_COOR"))+getInt(m_cor.getProperty("DESCRIPTION_Y"))));
}
else
{
//From Shipper
g2d.setFont(new Font(font_type,Font.PLAIN,font_size));
g2d.drawString(m_pr.getProperty("ACCOUNT"),(getInt(m_cor.getProperty("X_COOR"))+ getInt(m_cor.getProperty("ACCOUNT_X"))), (getInt(m_cor.getProperty("Y_COOR"))+getInt(m_cor.getProperty("ACCOUNT_Y"))) );
g2d.drawString(m_pr.getProperty("SHIPPER"), (getInt(m_cor.getProperty("X_COOR"))+getInt(m_cor.getProperty("SHIPPER_X"))), (getInt(m_cor.getProperty("Y_COOR"))+getInt(m_cor.getProperty("SHIPPER_Y"))));
g2d.drawString(m_pr.getProperty("COMPANYNAME"), (getInt(m_cor.getProperty("X_COOR"))+getInt(m_cor.getProperty("COMPANYNAME_X"))), (getInt(m_cor.getProperty("Y_COOR"))+getInt(m_cor.getProperty("COMPANYNAME_Y"))));
g2d.drawString(m_pr.getProperty("COMPANYADDRESS"), (getInt(m_cor.getProperty("X_COOR"))+getInt(m_cor.getProperty("COMPANYADDRESS_X"))), (getInt(m_cor.getProperty("Y_COOR"))+getInt(m_cor.getProperty("COMPANYADDRESS_Y"))));
g2d.drawString(m_pr.getProperty("POSTALCODE"), (getInt(m_cor.getProperty("X_COOR"))+getInt(m_cor.getProperty("POSTALCODE_X"))), (getInt(m_cor.getProperty("Y_COOR"))+getInt(m_cor.getProperty("POSTALCODE_Y"))));
g2d.drawString(m_pr.getProperty("PHONE"), (getInt(m_cor.getProperty("X_COOR"))+getInt(m_cor.getProperty("PHONE_X"))), (getInt(m_cor.getProperty("Y_COOR"))+getInt(m_cor.getProperty("PHONE_Y"))));

//To Reciver Data
g2d.drawString(m_pr.getProperty("TO"),(getInt(m_cor.getProperty("X_COOR"))+ getInt(m_cor.getProperty("TO_X"))), (getInt(m_cor.getProperty("Y_COOR"))+getInt(m_cor.getProperty("TO_Y"))) );
g2d.drawString(m_pr.getProperty("CONSIGNEE"), (getInt(m_cor.getProperty("X_COOR"))+getInt(m_cor.getProperty("CONSIGNEE_X"))), (getInt(m_cor.getProperty("Y_COOR"))+getInt(m_cor.getProperty("CONSIGNEE_Y"))));
g2d.drawString(m_pr.getProperty("CCOMPANYNAME"), (getInt(m_cor.getProperty("X_COOR"))+getInt(m_cor.getProperty("CCOMPANYNAME_X"))), (getInt(m_cor.getProperty("Y_COOR"))+getInt(m_cor.getProperty("CCOMPANYNAME_Y"))));
g2d.drawString(m_pr.getProperty("CCOMPANYADDRESS"), (getInt(m_cor.getProperty("X_COOR"))+getInt(m_cor.getProperty("CCOMPANYADDRESS_X"))), (getInt(m_cor.getProperty("Y_COOR"))+getInt(m_cor.getProperty("CCOMPANYADDRESS_X"))));
g2d.drawString(m_pr.getProperty("CPOSTALCODE"), (getInt(m_cor.getProperty("X_COOR"))+getInt(m_cor.getProperty("CPOSTALCODE_X"))), (getInt(m_cor.getProperty("Y_COOR"))+getInt(m_cor.getProperty("CPOSTALCODE_Y"))));
g2d.drawString(m_pr.getProperty("PHONE"), (getInt(m_cor.getProperty("X_COOR"))+getInt(m_cor.getProperty("PHONE_X"))), (getInt(m_cor.getProperty("Y_COOR"))+getInt(m_cor.getProperty("PHONE_Y"))));
g2d.drawString(m_pr.getProperty("CPHONE"), (getInt(m_cor.getProperty("X_COOR"))+getInt(m_cor.getProperty("CPHONE_X"))), (getInt(m_cor.getProperty("Y_COOR"))+getInt(m_cor.getProperty("CPHONE_Y"))));

//Shipment Details
g2d.drawString(m_pr.getProperty("TOTAL"), (getInt(m_cor.getProperty("X_COOR"))+getInt(m_cor.getProperty("TOTAL_X"))), (getInt(m_cor.getProperty("Y_COOR"))+getInt(m_cor.getProperty("TOTAL_Y"))));
g2d.drawString(m_pr.getProperty("PIECSE"), (getInt(m_cor.getProperty("X_COOR"))+getInt(m_cor.getProperty("PIECSE_X"))), (getInt(m_cor.getProperty("Y_COOR"))+getInt(m_cor.getProperty("PIECSE_Y"))));
g2d.drawString(m_pr.getProperty("LENGTH"), (getInt(m_cor.getProperty("X_COOR"))+getInt(m_cor.getProperty("LENGTH_X"))), (getInt(m_cor.getProperty("Y_COOR"))+getInt(m_cor.getProperty("LENGTH_Y"))));
g2d.drawString(m_pr.getProperty("WIDTH"), (getInt(m_cor.getProperty("X_COOR"))+getInt(m_cor.getProperty("WIDTH_X"))), (getInt(m_cor.getProperty("Y_COOR"))+getInt(m_cor.getProperty("WIDTH_Y"))));
g2d.drawString(m_pr.getProperty("HEIGHT"), (getInt(m_cor.getProperty("X_COOR"))+getInt(m_cor.getProperty("HEIGHT_X"))), (getInt(m_cor.getProperty("Y_COOR"))+getInt(m_cor.getProperty("HEIGHT_Y"))));

//DUTIALBE SHIPEMNT
g2d.drawString(m_pr.getProperty("DATA1"), (getInt(m_cor.getProperty("X_COOR"))+getInt(m_cor.getProperty("DATA1_X"))), (getInt(m_cor.getProperty("Y_COOR"))+getInt(m_cor.getProperty("DATA1_Y"))));
g2d.drawString(m_pr.getProperty("DATA2"), (getInt(m_cor.getProperty("X_COOR"))+getInt(m_cor.getProperty("DATA2_X"))), (getInt(m_cor.getProperty("Y_COOR"))+getInt(m_cor.getProperty("DATA2_Y"))));
g2d.drawString(m_pr.getProperty("DATA3"), (getInt(m_cor.getProperty("X_COOR"))+getInt(m_cor.getProperty("DATA3_X"))), (getInt(m_cor.getProperty("Y_COOR"))+getInt(m_cor.getProperty("DATA3_Y"))));
g2d.drawString(m_pr.getProperty("DATA4"), (getInt(m_cor.getProperty("X_COOR"))+getInt(m_cor.getProperty("DATA4_X"))), (getInt(m_cor.getProperty("Y_COOR"))+getInt(m_cor.getProperty("DATA4_Y"))));
g2d.drawString(m_pr.getProperty("DATA5"), (getInt(m_cor.getProperty("X_COOR"))+getInt(m_cor.getProperty("DATA5_X"))), (getInt(m_cor.getProperty("Y_COOR"))+getInt(m_cor.getProperty("DATA5_Y"))));
g2d.drawString(m_pr.getProperty("DATA6"), (getInt(m_cor.getProperty("X_COOR"))+getInt(m_cor.getProperty("DATA6_X"))), (getInt(m_cor.getProperty("Y_COOR"))+getInt(m_cor.getProperty("DATA6_Y"))));

g2d.drawString(m_pr.getProperty("DESCRIPTION"), (getInt(m_cor.getProperty("X_COOR"))+getInt(m_cor.getProperty("DESCRIPTION_X"))), (getInt(m_cor.getProperty("Y_COOR"))+getInt(m_cor.getProperty("DESCRIPTION_Y"))));




}
// Validate the page
return (PAGE_EXISTS);

}
}


public class FirstPage implements Printable {


/**
* Method: print <p>
*
* @param g a value of type Graphics
* @param pageFormat a value of type PageFormat
* @param page a value of type int
* @return a value of type int
*/
public int print (Graphics g, PageFormat pageFormat, int page) {

// Create the Graphics2D object
Graphics2D g2d = (Graphics2D) g;

// Translate the origin to 0,0 for the top left corner
g2d.translate (pageFormat.getImageableX (), pageFormat.getImageableY ());

// Set the drawing color to black
g2d.setPaint (Color.black);



Coordinates m_cor = new Coordinates();
PrintDetails m_pr = new PrintDetails();

String font_type=m_pr.getProperty("FONTTYPE");
// int font_size=getInt(m_pr.getProperty("FONTSIZE"));
/**
*
* Read the property file to print the contents
* at the correct Coordinates
* The Coordinates can be changed in the coor.properties file.
*
*/
g2d.setFont(new Font(font_type,Font.PLAIN,20));
//
// g2d.drawString(m_pr.getProperty("ACCOUNT"),(getInt(m_cor.getProperty("X_COOR"))+ getInt(m_cor.getProperty("ACCOUNT_X"))), (getInt(m_cor.getProperty("Y_COOR"))+getInt(m_cor.getProperty("ACCOUNT_Y"))) );
// g2d.drawString(m_pr.getProperty("SHIPPER"), (getInt(m_cor.getProperty("X_COOR"))+getInt(m_cor.getProperty("SHIPPER_X"))), (getInt(m_cor.getProperty("Y_COOR"))+getInt(m_cor.getProperty("SHIPPER_Y"))));
// g2d.drawString(m_pr.getProperty("COMPANYNAME"), (getInt(m_cor.getProperty("X_COOR"))+getInt(m_cor.getProperty("COMPANYNAME_X"))), (getInt(m_cor.getProperty("Y_COOR"))+getInt(m_cor.getProperty("COMPANYNAME_Y"))));
// g2d.drawString(m_pr.getProperty("COMPANYADDRESS"), (getInt(m_cor.getProperty("X_COOR"))+getInt(m_cor.getProperty("COMPANYADDRESS_X"))), (getInt(m_cor.getProperty("Y_COOR"))+getInt(m_cor.getProperty("COMPANYADDRESS_Y"))));
// g2d.drawString(m_pr.getProperty("POSTALCODE"), (getInt(m_cor.getProperty("X_COOR"))+getInt(m_cor.getProperty("POSTALCODE_X"))), (getInt(m_cor.getProperty("Y_COOR"))+getInt(m_cor.getProperty("POSTALCODE_Y"))));
// g2d.drawString(m_pr.getProperty("PHONE"), (getInt(m_cor.getProperty("X_COOR"))+getInt(m_cor.getProperty("PHONE_X"))), (getInt(m_cor.getProperty("Y_COOR"))+getInt(m_cor.getProperty("PHONE_Y"))));
g2d.drawString("START PAGE", (getInt(m_cor.getProperty("X_COOR"))+getInt(m_cor.getProperty("DESCRIPTION_X"))), (getInt(m_cor.getProperty("Y_COOR"))+getInt(m_cor.getProperty("DESCRIPTION_Y"))));
// Validate the page
return (PAGE_EXISTS);

}
}

int getInt(String property) {

return Integer.parseInt(property);

}

} // POCCode


Thanks in Advance
-Manju
 
GeeCON Prague 2014
 
subject: No Printer Found