JasperReport

File sourceFile = new File(fileName);
				JasperDesign jd = JRXmlLoader.load(sourceFile);//jrxml文件
				JasperReport jr = JasperCompileManager.compileReport(jd);
				JasperPrint jp = JasperFillManager.fillReport(jr, null,
						new JREmptyDataSource());
				JasperExportManager.exportReportToPdfFile(jp, "1.pdf");
				
				JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile);//jasper
		
				File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".pdf");
				
				JRPdfExporter exporter = new JRPdfExporter();
				
				exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
				exporter.setParameter(JRExporterParameter.OUTPUT_FILE, destFile);
				exporter.setParameter(JRPdfExporterParameter.IS_ENCRYPTED, Boolean.TRUE);
				exporter.setParameter(JRPdfExporterParameter.IS_128_BIT_KEY, Boolean.TRUE);
				exporter.setParameter(JRPdfExporterParameter.USER_PASSWORD, "jasper");
				exporter.setParameter(JRPdfExporterParameter.OWNER_PASSWORD, "reports");
				exporter.setParameter(
					JRPdfExporterParameter.PERMISSIONS, 
					new Integer(PdfWriter.AllowCopy | PdfWriter.AllowPrinting)
					);
				
				exporter.exportReport();


你可能感兴趣的:(jasperReport)