calculating html table length in php to pdf conversion

Discussion in 'PHP' started by learnerabn, Jul 20, 2010.

  1. #1
    Hi all,

    I am working under a project.
    it needs to convert html page to pdf file.
    in that there is two tables and their fields are retrieved from the database.
    so the height of the table is dynamic.
    my doubt here is can i calculate that height of the table in php so that i can display the table header again if the table leads to the second page also?(though i know since php is server side scripting it is not aware of the browser's table length)
    I can calculate the length using javascript or jquery but since i'm using html2pdf class file to convert the html page to pdf that class wont accept that script tags.

    can any one help me?...

    Any help is appreciable.

    Thanks in advance.
     
    learnerabn, Jul 20, 2010 IP
  2. WhyButUs

    WhyButUs Peon

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Can't you count rows and find out length in that way?
     
    WhyButUs, Jul 20, 2010 IP
  3. bencummins

    bencummins Peon

    Messages:
    55
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I did a similar thing recently using DOMPDF... a great script, and works really well. I don't remember having to find heights for tables or anything.

    Failing that, you could probably use the imagettfbbox function in php to work out the size of strings etc.. I believe PDF files are fixed sizes, so once you work out the width of a string you can use it to work out how many rows that is ceil($totalstringwidth / $pdfwidth) will give you the number of lines high it is... obviously , you will need to take into consideration the padding/spacing on the tables too
     
    bencummins, Jul 20, 2010 IP
  4. learnerabn

    learnerabn Peon

    Messages:
    131
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks for your replies guys,

    bencummins,i cant understand one thing what is that $pdfwidth stands for here?
     
    learnerabn, Jul 20, 2010 IP
  5. bencummins

    bencummins Peon

    Messages:
    55
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I just did a quick google,

    Adobe Illustrator has the following for a new A4 pdf, at 72dpi

    Width=595.2756 px
    Height=841.8898 px
     
    bencummins, Jul 21, 2010 IP
  6. learnerabn

    learnerabn Peon

    Messages:
    131
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    thanks for your replies
    i'll get back to you
    after trying this.
     
    learnerabn, Jul 21, 2010 IP