Sunday, January 13, 2013

ColdFusion - cfdocument, pdf and html tables

cfdocument tag of ColdFusion 8 is a great tool to generate extremely good looking PDF files/reports. Yesterday, when I was working on a PDF Generation System built on ColdFusion, I just noticed that cfdocument do not understand style="border-collapse: collapse" style. Therefore, if you are using tables in your PDF, you will see a lots of spaces and thick borders all around your tables and cells.

I highly recommend to use tableless structure inside cfdocument to avoid such problems. But if is absoulte necessary for you to use tables, then here is a fix for you :-)

  • Make sure that values of attribute border, cellpadding and cellspacing is set to 0 in each table. e.g <table cellspacing="0" border="0" cellspacing="0">
  • Add following style in your style sheet.
       td {
    margin-left:0;
    border-bottom:0;
    border-top:0;
    border-right:0;
    padding-left:0;
    }
Please also keep in mind that do not use <hr/> tag to generated colored horizontal line. Instead use colored image. And last but not the least, if your code inside cfdocument tag is XHTML validated, you will get perfect output.

No comments:

Post a Comment