Menu

How to display image in export files ?

Help
vmrao
2008-04-17
2012-10-09
  • vmrao

    vmrao - 2008-04-17

    I have gone through all related threads in this forum but could not find the solution for displaying image in exported files ( pdf , rtf , excel ). Do I need to write a decorator for this ? Can anyone please help by posting the relavant code.

    I am able to export text caption but not an image in the caption.

    Here is my code which works properly for html (displays image and caption underneath).

    <display:table name="${tblSelQry.rows}" id="outerTbl" class="its" sort="list" export="true" pagesize="8" cellspacing="3" style="width:600px;">

    <display:caption title="Additional Notes table" media="html pdf excel rtf" class="ppcLogoLink" style="font-weight:bold;">Additional Notes table</display:caption>

    </display:table>

    In CSS, class 'ppcLogoLink' is defined as follows.
    .ppcLogoLink {PADDING-TOP: 125px; BACKGROUND: transparent url(/ptid/images/ppc_logo.gif) no-repeat center}

    Thanks

     
    • vmrao

      vmrao - 2008-04-17

      I have even tried the following but pdf is displaying html code.

      <display:column title="" media="pdf">
      <img src="/ptid/images/ppc_logo.gif" />
      </display:column>

       
      • Carl

        Carl - 2008-09-25

        Hello,

        I had the same issue so I created my own PdfView:
        package export;

        import java.net.URL;

        import org.apache.log4j.Logger;
        import org.displaytag.export.PdfView;

        import com.lowagie.text.BadElementException;
        import com.lowagie.text.Cell;
        import com.lowagie.text.Image;

        public class ImagePdfView extends PdfView {

        /* (non-Javadoc)
        
         * @see org.displaytag.export.PdfView#getCell(java.lang.String)
         * I had to make the getCell protected to be able to override it, it was that or copy full class
         * if value of cell starts with image: the url behind it is taken to get the image
         * for example:
         * 
                &lt;display:column title=&quot;Your title&quot; media=&quot;pdf&quot;&gt;
                    image:http://host:port/path/image.gif
                &lt;/display:column&gt;
         */
        @Override
        protected Cell getCell(String cellValue) throws BadElementException {
            if(cellValue != null &amp;&amp; cellValue.trim().startsWith(&quot;image:&quot;)){
                Cell cell;
                try {
                    cellValue = cellValue.trim().substring(&quot;image:&quot;.length());
                    cell = new Cell(Image.getInstance(new URL(cellValue)));
                    return cell;
                } catch (Exception e) {
                    Logger.getLogger(this.getClass()).error(&quot;error when getting content of cell &quot; + cellValue,e);
                }
            }
            return super.getCell(cellValue);
        }
        

        }

        then in the displaytag.properties:
        export.pdf.class=export.ImagePdfView

        Hope that will help others...

        Regards,

        Carl

         
  • freelanceproject

    getCell(String cellValue) throws BadElementException is private method in
    PdfView .class
    if you override it as protected how you can call super.getCell(cellValue); ?

     

Log in to post a comment.