6 Replies Latest reply on Dec 21, 2010 11:04 AM by azmir

    Table in PDF footer is rendered in header

    csweeney

      When I try and include a table (because the footer I need is two lines of text) the footer is rendered behind an image that I have in the header. Anyone have any success with more complex footers? Example



      <f:facet name="header">
                <font size="14" family="garamond">
                <header borderWidth="0" >
                 <ui:include src="../components/Header.xhtml"/>
              </header>
         
                
              <footer borderWidthTop="1" borderWidthBottom="0" alignment="center">
              <table columns="1" horizontalAlignment="center">
                <f:facet name="defaultCell">
                      <cell  horizontalAlignment="center" borderWidth="0"/>
                      </f:facet>
                <cell horizontalAlignment="center"><paragraph><font size="7" horizontalAlignment="center">Contact information:</font></paragraph></cell>
                      <cell horizontalAlignment="center"><paragraph><font size="7" horizontalAlignment="center">Line 2:</font></paragraph></cell>
                </table>
              </footer>
               </font>
      </f:facet>


        • 1. Re: Table in PDF footer is rendered in header
          norman

          Can you open a JIRA issue for this?  I definitely see that this is a problem.

          • 2. Re: Table in PDF footer is rendered in header
            grasshopperus

            I wanted to have in my footer the report date on the left and page x on the right.  I also tried a table at first but I had the same problem you did.  I found that just using space characters rendered line spacing in the pdf (scroll all the way to the right to see what I mean!):



            <f:facet name="header">                     
            <font size="8">            
            <footer borderWidthTop="0" borderWidthBottom="0" alignment="center">#{dateTimeDisplay.dateDisplay}                                                                                                                                                                                                                                                  Page: <pageNumber /></footer>                
            </font>
            </f:facet>



            If your footer text width might vary widely this might not work for you.  I feel comfortable with it in my scenario since the text widths will remain pretty much the same.

            • 3. Re: Table in PDF footer is rendered in header

              hi,


              i also have the same problem. The footer is get out just under the header.
              I try to get a table in the footer but have no success with it.
              I saw in the forum some ideas to use html table. But it does not work in the footer.


              Since this thread is one year old i would hope there should be a workaroud or a fix


              If it was implemented already may be there are some ideas how it could  be implemented??


              any tips would be very nice


              thanks and regards
              Dmitri

              • 4. Re: Table in PDF footer is rendered in header

                hi,


                i have built my own solution for this problem. May be someone find it usefull...
                First i have implemented a TAG:




                public class UIDirectFooter extends ITextComponent
                {
                     /**
                      * @return the footerContent
                      */
                     public Iterator<Element> getFooterContent()
                     {
                          return footerContent.iterator();
                     }
                
                     protected List<Element> footerContent = null;
                
                     /** {@inheritDoc} */
                     @Override
                     public void createITextObject(FacesContext context) throws IOException, DocumentException
                     {
                          System.out.println("UIDirectFooter createITextObject() called");
                          footerContent = new ArrayList<Element>();
                     }
                
                     /** {@inheritDoc} */
                     @Override
                     public Object getITextObject()
                     {
                          System.out.println("UIDirectFooter getITextObject() called");
                          return null;
                     }
                
                     /** {@inheritDoc} */
                     @Override
                     public void handleAdd(Object other)
                     {
                          System.out.println("UIDirectFooter handleAdd() called");
                          if (other instanceof Element)
                          {
                               Element element = (Element) other;
                               System.out.println("try to add " + element.getClass().getName());
                               footerContent.add(element);
                          }
                          else
                          {
                               throw new IllegalArgumentException("cannot add " + other);
                          }
                
                     }
                
                     /** {@inheritDoc} */
                     @Override
                     public void removeITextObject()
                     {
                          System.out.println("UIDirectFooter removeITextObject() called");
                     }
                     
                     
                }
                


                Then i have a seam component derived from UIDocument. The footer drawing is made in it.



                @Name("documentoSeamFooterPdf")
                @Scope(ScopeType.CONVERSATION)
                public class SeamPdfFooterDocument extends UIDocument
                {
                
                     /** {@inheritDoc} */
                     @Override
                     protected void processHeaders()
                     {
                          processHeader("header");
                          processHeader("footer");
                     }
                
                     protected void processHeader(String facetName)
                     {
                          UIComponent facet = getFacet(facetName);
                
                          if (facet == null)
                          {
                               return;
                          }
                
                          try
                          {
                               encode(FacesContext.getCurrentInstance(), facet);
                          }
                          catch (Exception e)
                          {
                               throw new RuntimeException(e);
                          }
                     }
                
                     protected UIDirectFooter getDirectFooter()
                     {
                          UIComponent facet = getFacet("footer");
                          if (facet == null)
                          {
                               return null;
                          }
                
                          if (!(facet instanceof UIDirectFooter))
                          {
                               throw new RuntimeException("Only directFooter tag is allowed in facet 'footer'");
                          }
                          return (UIDirectFooter) facet;
                     }
                
                     /** {@inheritDoc} */
                     @Override
                     public void encodeBegin(FacesContext context) throws IOException
                     {
                          super.encodeBegin(context);
                
                          DocWriter writer = getWriter();
                          if (writer != null && writer instanceof PdfWriter)
                          {
                               PdfWriter pdfWriter = (PdfWriter) writer;
                               pdfWriter.setPageEvent(new PdfDocumentEventListener());
                          }
                     }
                
                     private class PdfDocumentEventListener extends PdfPageEventHelper
                     {
                
                          /** {@inheritDoc} */
                          @Override
                          public void onEndPage(PdfWriter writer, Document document)
                          {
                               PdfContentByte cb = writer.getDirectContent();
                
                               UIDirectFooter footer = getDirectFooter();
                               if (footer == null)
                               {
                                    return;
                               }
                
                               PdfPTable footerTable = new PdfPTable(1);
                               footerTable.setTotalWidth(document.right() - document.left());
                
                               PdfPCell footerCell = new PdfPCell();
                               footerCell.setBorder(PdfPCell.NO_BORDER);
                               footerCell.setHorizontalAlignment(Element.ALIGN_LEFT);
                               footerCell.setVerticalAlignment(Element.ALIGN_TOP);
                               footerCell.setPadding(0);
                               for (Iterator<Element> iterator = footer.getFooterContent(); iterator.hasNext();)
                               {
                                    Element element = (Element) iterator.next();
                                    footerCell.addElement(element);
                               }
                               footerTable.addCell(footerCell);
                
                               footerTable.writeSelectedRows(0, -1, document.left(), document.bottom() + footerTable.getTotalHeight(), cb);
                
                          }
                     }
                }
                



                and the using sample:




                <p:document xmlns:ui="http://java.sun.com/jsf/facelets"
                     xmlns:f="http://java.sun.com/jsf/core"
                     xmlns:p="http://jboss.com/products/seam/pdf"
                     xmlns:ej="http://mydomain.com/taglib"
                     binding="#{documentoSeamFooterPdf}">
                
                
                     <f:facet name="header">
                          <p:header borderWidthTop="0" borderColor="blue" borderWidthBottom="1"
                               alignment="center">
                               <p:font size="12">
                                    HEADER
                            </p:font>
                          </p:header>
                     </f:facet>
                
                     <f:facet name="footer">
                          <ej:directFooter>
                               <p:text value="ich bin text inside of direct footer" />
                        <p:table columns="1" horizontalAlignment="center">
                            <f:facet name="defaultCell">
                                <p:cell horizontalAlignment="center" borderWidth="0" />
                            </f:facet>
                            <p:cell horizontalAlignment="center">
                                <p:paragraph>
                                    <p:font size="7" horizontalAlignment="center">#{someBean.line}</p:font>
                                </p:paragraph>
                            </p:cell>
                            <p:cell horizontalAlignment="center">
                                <p:paragraph>
                                    <p:font size="7" horizontalAlignment="center">Line 2:</p:font>
                                </p:paragraph>
                            </p:cell>
                        </p:table>
                          </ej:directFooter>
                     </f:facet>
                
                     <p:font size="12" style="bold">
                          <p:paragraph alignment="right" indentationRight="30">-INVOICE-</p:paragraph>
                     </p:font>
                
                </p:document>



                It works fine for me.


                regards
                Dmitri







                • 5. Re: Table in PDF footer is rendered in header
                  falcken

                  I have also struggled to make work with tables in footer, but haven't got it to work until I tried your solutuion. Thanks a lot Dmitri!

                  • 6. Re: Table in PDF footer is rendered in header
                    azmir

                    Hallo,


                    I spend two days to makeing work the code from Dmitri but i dont get it working.


                    I put a new xy.taglib.xml to WEB-INF directory:



                    <?xml version="1.0"?>
                    <!DOCTYPE facelet-taglib PUBLIC
                       "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"
                       "facelet-taglib_1_0.dtd">
                       
                    <facelet-taglib>
                        <namespace>http://localhost:8080/app/taglib</namespace>
                        <tag>
                            <tag-name>directFooter</tag-name>
                            <component>
                                <component-type>com.app.common.UIDirectFooter</component-type>
                            </component>
                        </tag>
                    </facelet-taglib>



                    when i bind a dmitri document i xhtml




                    <p:document xmlns="http://www.w3.org/1999/xhtml"
                         xmlns:p="http://jboss.com/products/seam/pdf"
                         xmlns:ui="http://java.sun.com/jsf/facelets"
                         xmlns:f="http://java.sun.com/jsf/core"
                         xmlns:h="http://java.sun.com/jsf/html"
                         xmlns:s="http://jboss.com/products/seam/taglib"
                         xmlns:si="http://localhost:8080/app/taglib"
                         binding="#{documentoSeamFooterPdf}">
                         
                         <p:font>
                              <p:paragraph>test</p:paragraph>
                         </p:font>
                    
                    </p:document>



                    I became folowing error:



                    java.lang.RuntimeException: Couldn't find ITextComponent parent for component org.jboss.seam.pdf.ui.UIFont
                         at org.jboss.seam.pdf.ui.ITextComponent.noITextParentFound(ITextComponent.java:142)
                         at org.jboss.seam.pdf.ui.ITextComponent.addToITextParent(ITextComponent.java:136)
                         at org.jboss.seam.pdf.ui.UIFont.handleAdd(UIFont.java:122)
                         at org.jboss.seam.pdf.ui.ITextComponent.add(ITextComponent.java:59)
                         at org.jboss.seam.pdf.ui.ITextComponent.addToITextParent(ITextComponent.java:132)
                         at org.jboss.seam.pdf.ui.ITextComponent.encodeEnd(ITextComponent.java:227)
                         at org.jboss.seam.pdf.ui.ITextComponent.encode(ITextComponent.java:300)
                         at org.jboss.seam.pdf.ui.ITextComponent.encodeChildren(ITextComponent.java:256)
                         at org.jboss.seam.pdf.ui.ITextComponent.encode(ITextComponent.java:289)
                         at org.jboss.seam.pdf.ui.ITextComponent.encodeChildren(ITextComponent.java:256)
                         at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1613)
                         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
                         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
                         at java.lang.reflect.Method.invoke(Unknown Source)
                         at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
                         at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32)
                         at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
                         at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)
                         at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                         at org.jboss.seam.bpm.BusinessProcessInterceptor.aroundInvoke(BusinessProcessInterceptor.java:51)
                         at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                         at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
                         at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                         at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
                         at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)
                         at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)
                         at com.sidion.common.SeamPdfFooterDocument_$$_javassist_seam_5.encodeAll(SeamPdfFooterDocument_$$_javassist_seam_5.java)
                         at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1616)
                         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:127)
                         at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
                         at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
                         at javax.faces.webapp.FacesServlet.service(FacesServlet.java:313)
                         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:336)
                         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242)
                         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:206)
                         at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
                         at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
                         at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
                         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.web.HotDeployFilter.doFilter(HotDeployFilter.java:53)
                         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:274)
                         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242)
                         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:276)
                         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
                         at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:183)
                         at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
                         at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:95)
                         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:368)
                         at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:872)
                         at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:653)
                         at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951)
                         at java.lang.Thread.run(Unknown Source)
                    



                    I need a table object in footer of document. This ist the last one that dosn't working on my PDF-Export. Has anyone any idea how could i solve this.


                    JBossAS 6.0.0.M2, Seam 2.2


                    Thanks a lot for any halp,
                    Azmir