2012-05-09 5 views
3

IS_COMPRESSED = true 속성을 Jasper PDF 보고서에 어떻게 적용합니까? JasperReports에서 PDF를 압축하는 방법

내가 무엇을 가지고하지만 난 PDF 보고서를 만들 때 사용할 압축없이 복제의로 동일한 크기 : 내 보고서로 PDF 파일 출력의 크기가하지 않았다 것을 발견

File pdfFile = new File (pdfDirectory.getAbsolutePath() + File.separator + reportName + ".pdf"); 
File jrPrintFile = new File(jrprintFileLocation.getAbsolutePath() + File.separator + templateName + ".jrprint"); 

JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(jrPrintFile); 

JRPdfExporter jrPdfExporter = new JRPdfExporter(); 

jrPdfExporter.setParameter(JRPdfExporterParameter.IS_COMPRESSED, true); 
jrPdfExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); 
jrPdfExporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, pdfFile.getAbsolutePath()); 

jrPdfExporter.exportReport(); 
+0

이 코드를 확인해 보았습니다 :'jrPdfExporter.setParameter (JRPdfExporterParameter.IS_COMPRESSED, Boolean.TRUE);'괜찮습니다. 나는 JR 4.1.2를 사용하고있다. –

+0

재미 있습니다. 내 PDF 크기에 차이가 보이지 않습니다 ... Jasper에서 기본적으로 true로 설정되었을 수 있습니까? – travega

+0

설명서에 기본값이 * false * –

답변

0

가 각 서브 리포트에 압축 속성 (net.sf.jasperreports.export.pdf.compressed)이 삽입되어 'true'로 설정 될 때까지 변경하십시오.

그 후, 보고서에서 생성 된 PDF의 크기는 4MB에서 1MB를 약간 넘었습니다. 나쁘지 않다.

+0

이 속성을 어디에 포함합니까? – Gustavo

2

수행하기 위해 이것은 오래된 질문 할 수있다,하지만 난 PDF 파일을 압축하는 방법을 찾고 약간의 시간을 할애하고 나는 대답을 공유 할 ... setParameter를 방법의 대안이되지 않습니다

하고, 마찬가지로 설명서에는 PdfExporterConfiguration의 구현을 사용해야한다는 내용이 나와 있습니다. SimplePdfExporterConfiguration라는 간단한 일이 제공되며, 다음과 같이 사용한다 :

SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration(); 
configuration.setCompressed(true); 

소스로 XML을 사용하여 PDF 생성의 완벽한 예 :

Document document = JRXmlUtils.parse(JRLoader.getLocationInputStream(PATH_XML)); 

//report parameters 
Map params = new HashMap(); 
//document as a parameter 
params.put(JRXPathQueryExecuterFactory.PARAMETER_XML_DATA_DOCUMENT, document); 
//other parameters needed for the report generation 
params.put("parameterName", parameterValue); 

JasperPrint jasperPrint = JasperFillManager.fillReport(PATH_JASPER, params); 

JRPdfExporter exporter = new JRPdfExporter(); 
exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); 
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(PATH_PDF)); 

//configuration 
SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration(); 
configuration.setCompressed(true); 

//set the configuration 
exporter.setConfiguration(configuration); 
//finally exporting the PDF 
exporter.exportReport(); 

내가 파일을 압축 관리 누군가가 더 나은 대안이나 더 나은 방법을 알고 있다면 4mb에서 1.9mb로이 답변에 대해 의견을 말하십시오.

관련 문제