Jump to content
We've recently updated our Privacy Statement, available here ×

Please Help,Printing reports at client Side


2005 IR Help

Recommended Posts

By: Kukku - kukku

Please Help,Printing reports at client Side

2004-09-22 09:38

I am generating the jasper reports.It all works fine.

What I want is to print this report directly to printer.

 

From my machine it works fine as webapp is deployed on my machine,but when I try to print this report from another machine I am not able to do this.

 

My problem is how an application get the printer at client side to print report at their end.

 

I am using the following code.

public void getMediaPrintableArea()

{

PrintRequestAttributeSet printRequestAttributeSet = null;

PrintServiceAttributeSet printServiceAttributeSet = null;

AttributeSet attributeSet = new HashAttributeSet();

 

printRequestAttributeSet = new HashPrintRequestAttributeSet();

printRequestAttributeSet.add(MediaSizeName.ISO_A4);

printRequestAttributeSet.add(OrientationRequested.LANDSCAPE);

 

printServiceAttributeSet = new HashPrintServiceAttributeSet();

attributeSet.addAll(printRequestAttributeSet);

attributeSet.addAll(printServiceAttributeSet);

 

PrintService[] services = PrintServiceLookup.lookupPrintServices(null, attributeSet);

 

for (int i = 0; i < services.length; i++)

{

System.out.println("exportReport:" + services.getName());

Object[] o = (Object[]) services.getSupportedAttributeValues(MediaPrintableArea.class, null, attributeSet);

for (int j = 0; j < o.length; j++) {

MediaPrintableArea pa = (MediaPrintableArea) o[j];

System.out.println("exportReport:" +

"x=" + pa.getX(MediaPrintableArea.MM) + ", " +

"y=" + pa.getY(MediaPrintableArea.MM) + ", " +

"w=" + pa.getWidth(MediaPrintableArea.MM) + ", " +

"h=" + pa.getHeight(MediaPrintableArea.MM));

}

}

}

 

get the values and set the EXACTLY when you export the project:

 

if (TASK_PRINT_SERVICE.equals(taskName))

{

String jprint = DOWNLOAD_FOLDER + File.separator + reportName + ".jrprint";

JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(jprint);

 

PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();

printRequestAttributeSet.add(MediaSizeName.ISO_A4);

 

PrintServiceAttributeSet printServiceAttributeSet = new HashPrintServiceAttributeSet();

//printServiceAttributeSet.add(new PrinterName("Epson Stylus 800 ESC/P 2", null));

//printServiceAttributeSet.add(new PrinterName("HP LaserJet 4P", null));

 

log.debug("Orientation: " + jasperPrint.getOrientation());

if (jasperPrint.getOrientation() == JRReport.ORIENTATION_LANDSCAPE)

{

printRequestAttributeSet.add(OrientationRequested.LANDSCAPE);

printRequestAttributeSet.add(new MediaPrintableArea(

// HP LaserJet 4100 PCL 6: x=4.233, y=4.233, w=200.829, h=287.782

4.233f, 4.233f, 200.829f, 287.782f, MediaPrintableArea.MM));

}

else

{

printRequestAttributeSet.add(OrientationRequested.PORTRAIT);

}

 

JRPrintServiceExporter exporter = new JRPrintServiceExporter();

exporter.setParameter(JRExporterParameter.INPUT_FILE_NAME, jprint);

exporter.setParameter(JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET, printRequestAttributeSet);

exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET, printServiceAttributeSet);

exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.FALSE);

exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.TRUE);

exporter.exportReport();

log.info("Printing time : " + (System.currentTimeMillis() - start));

}

 

 

I will really appriciate if some body can help me out.

 

Thanks in advance.

Link to comment
Share on other sites

  • 7 years later...
  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...