Monday, March 25, 2013

How to view PDF file in browser using iframe in zk

Two ways can view
First one simple use src attribute.
<iframe id="iframe" src=""
                width="600px" height="400px" style="border: 1px solid gray" />
find here details in zk fiddle.

2nd   way to view
    <window border="normal" title="Himanshu" apply="pkg$.TestComposer">
           <iframe id="report" height="800px" width="800px" autohide="true"></iframe>

import org.zkoss.zk.ui.*;
import org.zkoss.zk.ui.event.*;
import org.zkoss.zk.ui.util.*;
import org.zkoss.zk.ui.ext.*;
import org.zkoss.zul.*;

public class TestComposer extends GenericForwardComposer{

        Iframe report;
                public void doAfterCompose(Component comp) throws Exception {
          URL url1 =
      new URL("");
    byte[] ba1 = new byte[1024];
    int baLength;
                InputStream is1 = null;
          ByteArrayOutputStream bios = new ByteArrayOutputStream();
    try {
      URLConnection urlConn = url1.openConnection();

      // Checking whether the URL contains a PDF
      if (!urlConn.getContentType().equalsIgnoreCase("application/pdf")) {
      "Not a pdf!!!");
      } else {
        try {

          // Read the PDF from the URL and save to a local file
         is1 = url1.openStream();
          while ((baLength = != -1) {
              bios.write(ba1, 0, baLength);
        }catch(Exception e) {
          } finally { 
          final AMedia amedia = new AMedia("PDFReference16.pdf", "pdf","application/pdf", bios.toByteArray());
                } catch(Exception ex) {
                public void onClick$btn(Event e) throws InterruptedException{
                      "Hi btn");
Find here details in zk fiddle

How to Calculate the Future Investment Value of Investment.

Below java program for calculate future investment value. Here calculate s using the formula futureInvestmentValue =investmentAmount x (...