Zul:
<zk xmlns:x="xhtml" xmlns:zk="zk">
<window width="100%" height="100%"
apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('com.demo.ReadPdf')">
<iframe id="report" height="100%" width="100%"
autohide="true">
</iframe>
</window>
</zk>
Java:
package com.demo;
import java.net.MalformedURLException;
import org.apache.log4j.Logger;
import org.zkoss.bind.annotation.AfterCompose;
import org.zkoss.bind.annotation.ContextParam;
import org.zkoss.bind.annotation.ContextType;
import org.zkoss.bind.annotation.ExecutionArgParam;
import org.zkoss.util.media.AMedia;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.select.Selectors;
import org.zkoss.zk.ui.select.annotation.Wire;
import org.zkoss.zul.Iframe;
public class ReadPdf {
@Wire
Iframe report;
@AfterCompose
public void afterCompose(@ContextParam(ContextType.VIEW) Component view, @ExecutionArgParam(BYTE) byte[] byteData)
throws MalformedURLException {
logger.info("Correspondence View Page");
Selectors.wireComponents(view, this, false);
viewPdfFile(byteData);
}
private void viewPdfFile(byte[] byteData) {
try {
AMedia amedia = null;
amedia = new AMedia(BYTE,"pdf", "application/pdf", byteData);
report.setContent(amedia);
} catch (Exception ex) {
showInfo(ex.toString());
}
}
}
<zk xmlns:x="xhtml" xmlns:zk="zk">
<window width="100%" height="100%"
apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('com.demo.ReadPdf')">
<iframe id="report" height="100%" width="100%"
autohide="true">
</iframe>
</window>
</zk>
Java:
package com.demo;
import java.net.MalformedURLException;
import org.apache.log4j.Logger;
import org.zkoss.bind.annotation.AfterCompose;
import org.zkoss.bind.annotation.ContextParam;
import org.zkoss.bind.annotation.ContextType;
import org.zkoss.bind.annotation.ExecutionArgParam;
import org.zkoss.util.media.AMedia;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.select.Selectors;
import org.zkoss.zk.ui.select.annotation.Wire;
import org.zkoss.zul.Iframe;
public class ReadPdf {
@Wire
Iframe report;
@AfterCompose
public void afterCompose(@ContextParam(ContextType.VIEW) Component view, @ExecutionArgParam(BYTE) byte[] byteData)
throws MalformedURLException {
logger.info("Correspondence View Page");
Selectors.wireComponents(view, this, false);
viewPdfFile(byteData);
}
private void viewPdfFile(byte[] byteData) {
try {
AMedia amedia = null;
amedia = new AMedia(BYTE,"pdf", "application/pdf", byteData);
report.setContent(amedia);
} catch (Exception ex) {
showInfo(ex.toString());
}
}
}
No comments:
Post a Comment