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

Sending the compiled and filled report to printer. Empty page!


ojive

Recommended Posts

heya!

I cant seem to be able to print my report. I have it compiled from jasperDesign, then filled, then i used the example from "demo/samples/printservice/src" and modified it to better match my task.

I changed INPUT_FILE_NAME to JASPER_PRINT_LIST ( i have a list of JasperPrints in it). However, the page that prints is empty.

I tried this method earlier but with PDFexporter, and the report that was generated (a PDF file) was just fine.

Any ideas? This is driving me nuts, JasperReports is being advertised as "easy to print", but at the moment, in my case, it really isnt :p

Code:
PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();printRequestAttributeSet.add(MediaSizeName.ISO_A4);PrintServiceAttributeSet printServiceAttributeSet = new HashPrintServiceAttributeSet();JRPrintServiceExporter exporter = new JRPrintServiceExporter();exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, list);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();
Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

 How sweet is this. My original problem was that when i created a pdf file from the report (JRPdfExporter), it ignored the font completely. So i tried to send the report directly to printer, and failed (blank page).

So i went back to the "first pdf, then print it"-solution that ignored the font and after a few hours of searching Lè G00glè, i found how to create a custom "fontmap" and add your own fonts to it.

See code below. Note: I dont quite remember where "PDFPRintPage" came from, but it might've been from a jar called PDFRenderer that i found on the web. PDFFile seems to come from Sun itself.

Code:
HashMap fontMap = new HashMap();						fontMap.put(new FontKey("Arabic Typesetting", false, false),new PdfFont("fonts\\arabtype.ttf",BaseFont.IDENTITY_H,true));			exp.setParameter(JRPdfExporterParameter.JASPER_PRINT_LIST, list);			exp.setParameter(JRPdfExporterParameter.OUTPUT_FILE, new File("label.pdf")); 			exp.setParameter(JRPdfExporterParameter.PDF_VERSION, JRPdfExporterParameter.PDF_VERSION_1_7);				exp.setParameter(JRPdfExporterParameter.FONT_MAP, fontMap);			exp.exportReport();//**********************************************************************************			// Create a PDFFile from a File reference			File f = new File("label.pdf");			FileInputStream fis = new FileInputStream("label.pdf"); 						FileChannel fc = fis.getChannel();			ByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());			PDFFile pdfFile = new PDFFile(bb); // Create PDF Print Page			PDFPrintPage pages2 = new PDFPrintPage(pdfFile);			// Create Print Job			PrinterJob pjob = PrinterJob.getPrinterJob();			PageFormat pf = pjob.defaultPage();			Paper paper = new Paper();			paper.setSize(jasperPrint.getPageWidth(), jasperPrint.getPageHeight());			pf.setPaper(paper);			pf.setOrientation(0);			pjob.setJobName(f.getName());			pjob.setPrintable(pages2,pf);			 			// Send print job to default printer			if (pjob.printDialog())		    {				pjob.print();		    }
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...