Shrinking wide page to A4

Hello,

I have a problem with printing a report, which doesn't fit to one page.
The size of the report can vary, but let's take the example I have, width 1800, height 150.
Because it is much wider than high, I turn to Landscape.
The whole report must fit to one page, so I try to configure this in the printing dialog. The JasperViewer shows the report correct, so as I want it.
(Screenshot 1)
But when I try to print it out, some columns are cut off. (Screenshot 2/3)
This is the code:

final PrinterJob pJob = PrinterJob.getPrinterJob();
pJob.setJobName("Some Name");
final PrintService service = pJob.getPrintService();
final PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
printRequestAttributeSet.add(OrientationRequested.LANDSCAPE);
printRequestAttributeSet.add(new NumberUp(1));
final 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, service.getAttributes());
exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.FALSE);
exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.TRUE);
exporter.exportReport();

As I told, jasperPrint is correct, I see this in the Viewer.

Another idea I had was to create a PDF and print that.
The PDF will be correct, and when I save it and print the saved file, it's ok.
But I don't want to save it and open it with a PDF-Viewer, I want to print directly.
I tried this:

ByteArrayOutputStream outstream = new ByteArrayOutputStream();
JasperExportManager.exportReportToPdfStream(jasperPrint, outstream);
byte[] buffer = outstream.toByteArray();
outstream.close();
InputStream instream = new ByteArrayInputStream(buffer);
final PrinterJob pJob = PrinterJob.getPrinterJob();
pJob.setJobName("Some Name");
final PrintService service = pJob.getPrintService();
final PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
printRequestAttributeSet.add(OrientationRequested.LANDSCAPE);
printRequestAttributeSet.add(new NumberUp(1));
final JRPrintServiceExporter exporter = new JRPrintServiceExporter();
exporter.setParameter(JRExporterParameter.INPUT_STREAM, instream);
exporter.setParameter(JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET, printRequestAttributeSet);
exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET, service.getAttributes());
exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.FALSE);
exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.TRUE);
exporter.exportReport();

But this leads to the error:
net.sf.jasperreports.engine.JRException: Error loading object from InputStream

Can anybody help?

Thanks a lot.

Attachments: 
gal64's picture
9
Joined: May 24 2007 - 6:12pm
Last seen: 7 years 4 months ago

0 Answers:

No answers yet
Feedback
randomness