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

Weird printing problem


nlasystems

Recommended Posts

Hi All

We have been using JasperReports for more than 7 years now and this is the first time this happenned.

We have 2 printers on the same server, namely an HP LaserJet P1005 and an HP Deskjet 2510 series. From the same application, printing to the LaserJet is OK but printing to the Deskjet produces a strange result. The fonts expand horizontally and as a result, the right hand half the page gets truncated horizontally.

The first thing we did was upgrade to the latest version (5.0.1) but exactly the same behaviour persisted.

If we export the report to a PDF, both printers print OK from Acrobat Reader. That is why we now think that the problem is with the JRPrintServiceExporter

*******I have also uploaded a pdf to show how the report should look like and a jpg scan of the wrong print-out. *******

We have captured the PrintServices Attributes which we are listing below.

Found print service: Win32 Printer : \SERVER-PCHP LaserJet P1005
job-name - Java Printing
requesting-user-name - USER
copies-supported - null
spool-data-destination - file:/R:/nlaPayroll/out.prn
orientation-requested - portrait
page-ranges - 1-2147483647
media - iso-a4
media-printable-area - (3.725,3.556)->(202.523,289.899)mm
ipp-attribute-fidelity - false
sheet-collate - uncollated
sun-alternate-media - null
chromaticity - color
printer-resolution - 60000x60000 dphi

Found print service: Win32 Printer : \SERVER-PCHP Deskjet 2510 series
job-name - Java Printing
requesting-user-name - USER
copies-supported - null
spool-data-destination - file:/R:/nlaPayroll/out.prn
orientation-requested - portrait
page-ranges - 1-2147483647
media - iso-a4
media-printable-area - (3.133,3.133)->(203.708,290.576)mm
ipp-attribute-fidelity - false
sheet-collate - collated
sun-alternate-media - null
chromaticity - color
printer-resolution - 60000x30000 dphi

 

This is the method we are using to print: -

 

    public void print(String printerName) throws Exception {
        try {
                Copies noOfCopies = new Copies(1);

                PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
                printRequestAttributeSet.add(MediaSizeName.ISO_A4);
                printRequestAttributeSet.add(noOfCopies);

                PrintServiceAttributeSet printServiceAttributeSet = new HashPrintServiceAttributeSet();
 
                JRPrintServiceExporter exporter = new JRPrintServiceExporter();

                exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
                exporter.setParameter(JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET, printRequestAttributeSet);
                exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET, printServiceAttributeSet);
                if (printerName==null) exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, true);
                else {
                    exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, false);
                    printServiceAttributeSet.add(new PrinterName(printerName, null));
                }

                exporter.exportReport();

                if (printerName==null) lastPrinterUsed=exporter.getPrintService().getName();;
            } catch (Exception e) {
                System.out.println("Docbuilder.print() error> "+e);
                throw e;
            }

    }

Link to comment
Share on other sites

  • 3 weeks later...
  • Replies 6
  • Created
  • Last Reply

Top Posters In This Topic

  • 3 months later...
  • 6 months later...

I had the same problem and this works for me:

PrintRequestAttributeSet printRequestAttrs = new HashPrintRequestAttributeSet();
printRequestAttrs.add(new PrinterResolution(600, 600, ResolutionSyntax.DPI)); // this resolution solved the problem
JRPrintServiceExporter exporter = new JRPrintServiceExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, report);
exporter.setParameter(JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET, printRequestAttrs);
exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.TRUE);
exporter.exportReport();

Link to comment
Share on other sites

Bingo!

Thanks Sunal! It worked for us too.

The only thing we need to amend now is to prompt printer setup BEFORE your exporting code because we will use this code for this exception only.

Incidentally we encountered another printer with the same problem (HP Deskjet 1050) In this case 600DPI made matters worse but 300 DPI woked just fine.

Thanks again.

 

Link to comment
Share on other sites

  • 3 weeks later...

GRRR!!! Actually it did not work, It worked for the HP Deskjet 1050 as stated above.

When I posted wictory I assumed that since it worked for the 1050 it is going to work for 2515 but sorry to say that it persistently kept printing half a page horizontally. We tried both 300 and 600 dpi.

Link to comment
Share on other sites

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