Jump to content
Changes to the Jaspersoft community edition download ×

Printing Issue - Jasper Report

Recommended Posts

By: Shikha Meena - shikhameena

Printing Issue - Jasper Report

2006-05-12 07:51

Hi ,


In our project we are using jasperreports-1.2.0. The requirement in our project is such that the .jrprint file can be used to print on one of the network printer.

To achieve this functionality I have written following code : -


public void jasperPrint(PrintJobDTO prJobDto ,String fileName, UserSessionDataDTO argUserSessionDataDTO , String printerCode)




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


System.out.println( "jasperPrint >>>> "+ jasperPrint.getOrientation());

AttributeSet aset = new HashAttributeSet();

aset.add(new PrinterName(printerCode, null));

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

PrintService service = null;

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


service =services;

System.out.println( "service >>>> "+ service);

System.out.println( "service.getName() >>>> "+ service.getName() );




System.out.println("New jasperPrint fileName >> " + fileName );

PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();

printRequestAttributeSet.add(new Copies(prJobDto.getNumberOfCopies()));



System.out.println("before printer code >> " + printerCode);



new MediaPrintableArea(








System.out.println("MediaPrintableArea>> " +(!printRequestAttributeSet.containsKey(MediaPrintableArea.class)));


//PrintServiceAttributeSet printServiceAttributeSet = new HashPrintServiceAttributeSet();

//printServiceAttributeSet.add(new PrinterName(printerCode, null));

//System.out.println("after printer code " +printerCode );


JRPrintServiceExporter exporter = new JRPrintServiceExporter();

exporter.setParameter(JRExporterParameter.INPUT_FILE_NAME, fileName);

exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE, service);

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.FALSE);


exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);


System.out.println("Printing END>> " );


catch(JRException e)


System.out.println( "JRException >>>> "+ e.getMessage());


catch(Exception e)








But the print out using this method is not proper .It seems to truncate all the text even though the Text fields are set to stretch , the page size and page orientation of the print out is also not correct.



Please guide me in resolving this issue.


Any suggestions and views are welcome.


Many Thanks...



Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

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