Jump to content
Changes to the Jaspersoft community edition download ×

gal64

Recommended Posts

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.

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