5 Replies Latest reply on Oct 31, 2013 11:36 PM by fbimage

    showing tiff image in PDF

    Pravin Katta Newbie
      I am trying to put a tiff image file in my PDF by using <p:image value="#{toevoegen.dataStr}"/> tag.

      implementation details:-

      entity class

      @Name("toevoegen")
      @AutoCreate
      public class Toevoegen {

      private ByteArrayInputStream dataStr;
      private byte[] data;

      public ByteArrayInputStream getDataStr() {

                      try {
                              data = getBytesFromFile("d:\\temp\\warning.tiff");
                              dataStr = getAwtImage(data);
                      } catch (IOException e) {
                              e.printStackTrace();
                      }

                      return dataStr;
              }

      public ByteArrayInputStream getAwtImage(byte[] data) {

                      ByteArrayInputStream inStream = new ByteArrayInputStream(data);
                      ByteArrayOutputStream outStream = new ByteArrayOutputStream();
                      try {
                              BufferedImage image = ImageIO.read(inStream);

                              ImageIO.write(image, "tiff", outStream);
                              // ImageIO.write(image, "TIF", new File("d:\\temp\\Bijlage.tif"));

                              outStream.close();
                      } catch (IOException e) {
                              e.printStackTrace();
                      }
                      return new ByteArrayInputStream(outStream.toByteArray());
              }

      private static byte[] getBytesFromFile(String path) throws IOException {

                      File file = new File(path);
                      InputStream is = new FileInputStream(file);

                      // Get the size of the file
                      long length = file.length();

                      /*
                       * You cannot create an array using a long type. It needs to be an int
                       * type. Before converting to an int type, check to ensure that file is
                       * not larger than Integer.MAX_VALUE;
                       */
                      if (length > Integer.MAX_VALUE) {
                              return null;
                      }

                      // Create the byte array to hold the data
                      byte[] bytes = new byte[(int) length];

                      // Read in the bytes
                      int offset = 0;
                      int numRead = 0;
                      while ((offset < bytes.length)
                                      && ((numRead = is.read(bytes, offset, bytes.length - offset)) >= 0)) {

                              offset += numRead;

                      }

                      // Ensure all the bytes have been read in
                      if (offset < bytes.length) {
                              throw new IOException("Could not completely read file "
                                              + file.getName());
                      }

                      is.close();
                      return bytes;

              }
      }

      in my xhtml :- <p:image value="#{toevoegen.dataStr}" />

      i have installed the Advanced Imaging Image I/O for tiff.

      main thing is the same code is working for jpeg images.
      but for tiff i am getting the following exception.

      java.lang.NullPointerException
              at org.jboss.seam.ui.graphicImage.Image.getImage(Image.java:154)
              at org.jboss.seam.pdf.ui.UIImage.createITextObject(UIImage.java:144)
              at org.jboss.seam.pdf.ui.ITextComponent.encodeBegin(ITextComponent.java:213)
              at org.jboss.seam.pdf.ui.ITextComponent.encode(ITextComponent.java:283)
              at org.jboss.seam.pdf.ui.ITextComponent.encodeChildren(ITextComponent.java:256)
              at javax.faces.component.UIComponent.encodeAll(UIComponent.java:930)
              at javax.faces.component.UIComponent.encodeAll(UIComponent.java:933)
              at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
              at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:100)
              at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:176)
              at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110)
              at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
              at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
              at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
              at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
              at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
              at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:390)
              at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:517)
              at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
              at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
              at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
              at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
              at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
              at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
              at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
              at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
              at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
              at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
              at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
              at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
              at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
              at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
              at java.lang.Thread.run(Thread.java:619)

      thanks