http://sourceforge.net/tracker/?func=detail&aid=2826268&group_id=176962&atid=955896 [Large report and big pdf]
- use temporary file for pdf rendering, use less memory on the server and works better with the latest adobe reader plugin ( 9.2+ )
This commit is contained in:
parent
62ab3c9244
commit
d47ded66a3
|
@ -1,10 +1,14 @@
|
|||
package org.adempiere.webui.window;
|
||||
|
||||
import net.sf.jasperreports.engine.JRException;
|
||||
import java.io.File;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import net.sf.jasperreports.engine.JasperExportManager;
|
||||
import net.sf.jasperreports.engine.JasperPrint;
|
||||
|
||||
import org.adempiere.exceptions.AdempiereException;
|
||||
import org.adempiere.webui.component.Window;
|
||||
import org.compiere.util.CLogger;
|
||||
import org.zkoss.util.media.AMedia;
|
||||
import org.zkoss.zkex.zul.Borderlayout;
|
||||
import org.zkoss.zkex.zul.Center;
|
||||
|
@ -15,12 +19,13 @@ import org.zkoss.zul.Toolbarbutton;
|
|||
|
||||
public class ZkJRViewer extends Window {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -7657218073670612078L;
|
||||
private static final long serialVersionUID = 2021796699437770927L;
|
||||
|
||||
private JasperPrint jasperPrint;
|
||||
|
||||
/** Logger */
|
||||
private static CLogger log = CLogger.getCLogger(ZkJRViewer.class);
|
||||
|
||||
public ZkJRViewer(JasperPrint jasperPrint, String title) {
|
||||
this.setTitle(title);
|
||||
this.jasperPrint = jasperPrint;
|
||||
|
@ -52,16 +57,36 @@ public class ZkJRViewer extends Window {
|
|||
iframe.setHeight("100%");
|
||||
iframe.setWidth("100%");
|
||||
|
||||
byte[] data = null;
|
||||
try {
|
||||
data = JasperExportManager.exportReportToPdf(jasperPrint);
|
||||
} catch (JRException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
AMedia media = new AMedia(getTitle(), "pdf", "application/pdf", data);
|
||||
iframe.setContent(media);
|
||||
String path = System.getProperty("java.io.tmpdir");
|
||||
String prefix = makePrefix(jasperPrint.getName());
|
||||
if (log.isLoggable(Level.FINE))
|
||||
{
|
||||
log.log(Level.FINE, "Path="+path + " Prefix="+prefix);
|
||||
}
|
||||
File file = File.createTempFile(prefix, ".pdf", new File(path));
|
||||
JasperExportManager.exportReportToPdfFile(jasperPrint, file.getAbsolutePath());
|
||||
AMedia media = new AMedia(getTitle(), "pdf", "application/pdf", file, true);
|
||||
iframe.setContent(media);
|
||||
} catch (Exception e) {
|
||||
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
||||
throw new AdempiereException("Failed to render report.", e);
|
||||
}
|
||||
center.appendChild(iframe);
|
||||
|
||||
this.setBorder("normal");
|
||||
}
|
||||
|
||||
private String makePrefix(String name) {
|
||||
StringBuffer prefix = new StringBuffer();
|
||||
char[] nameArray = name.toCharArray();
|
||||
for (char ch : nameArray) {
|
||||
if (Character.isLetterOrDigit(ch)) {
|
||||
prefix.append(ch);
|
||||
} else {
|
||||
prefix.append("_");
|
||||
}
|
||||
}
|
||||
return prefix.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -93,9 +93,6 @@ import org.zkoss.zul.Vbox;
|
|||
*/
|
||||
public class ZkReportViewer extends Window implements EventListener {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1492321933977608137L;
|
||||
/** Window No */
|
||||
private int m_WindowNo;
|
||||
|
@ -327,7 +324,15 @@ public class ZkReportViewer extends Window implements EventListener {
|
|||
AMedia media = null;
|
||||
Listitem selected = previewType.getSelectedItem();
|
||||
if (selected == null || "PDF".equals(selected.getValue())) {
|
||||
media = new AMedia(getTitle(), "pdf", "application/pdf", m_reportEngine.createPDFData());
|
||||
String path = System.getProperty("java.io.tmpdir");
|
||||
String prefix = makePrefix(m_reportEngine.getName());
|
||||
if (log.isLoggable(Level.FINE))
|
||||
{
|
||||
log.log(Level.FINE, "Path="+path + " Prefix="+prefix);
|
||||
}
|
||||
File file = File.createTempFile(prefix, ".pdf", new File(path));
|
||||
m_reportEngine.createPDF(file);
|
||||
media = new AMedia(getTitle(), "pdf", "application/pdf", file, true);
|
||||
} else if ("HTML".equals(previewType.getSelectedItem().getValue())) {
|
||||
String path = System.getProperty("java.io.tmpdir");
|
||||
String prefix = makePrefix(m_reportEngine.getName());
|
||||
|
|
Loading…
Reference in New Issue