Suggestions for creating a PDF table

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kirk Strauser

    Suggestions for creating a PDF table

    Short question:

    Is there a good library for generating HTML-style tables with the equivalent
    of colspans, automatically sized columns, etc. that can render directly to
    PDF?

    Longer question:

    I'm re-doing a big chunk of locally-written code. I have a
    report-generating function that takes a list of lists of lists as input and
    returns either a PDF, an HTML table, or an Excel spreadsheet as requested.
    For example, input might look like:

    makereport('htm l',
    headers=['Invoice number', 'Customer', 'Price'],
    data=[
    [['123', 'John Doe', '$50.00'],
    ['Ordered on 2008-01-01 via the website']],
    [['124', 'Peter Bilt', '$25.99'],
    ['Mail via African swallow']]
    ])

    This would result in HTML like:

    <table>
    <tr>
    <th>Invoice number</th>
    <th>Customer</th>
    <th>Price</th>
    </tr>
    <tr class="lightbac kground">
    <td>123</td>
    <td>John Doe</td>
    <td>$50.00</td>
    </tr>
    <tr class="lightbac kground">
    <td colspan="3">Ord ered on 2008-01-01 via the website</td>
    </tr>
    <tr class="darkerba ckground">
    <td>124</td>
    <td>Peter Bilt</td>
    <td>$25.99</td>
    </tr>
    <tr class="darkerba ckground">
    <td colspan="3">Mai l via African swallow</td>
    </tr>
    </table>

    Note particularly how the explanatory notes for each invoice are similar in
    appearance to the "primary" report lines they're associated with.

    Now, I have a similar transformation to PDF via pdflatex. This works fairly
    well but requires a bunch of temp files and subprocesses, and I've never
    been 100% happy with the LaTeX output (you have to calculate your own
    column widths, for instance). Since I plan to re-write this anyway, I'd
    like to find a more widely used library if one was available.

    ReportLab seemed *almost* perfect, except that it doesn't support colspans.
    As I hope I demonstrated in the example, most of our reports depend on that
    ability.

    So, again, any thoughts on a PDF generator that can generate tables with the
    same kind of flexibility as HTML?
    --
    Kirk Strauser
  • Larry Bates

    #2
    Re: Suggestions for creating a PDF table

    Kirk Strauser wrote:
    Short question:
    >
    Is there a good library for generating HTML-style tables with the equivalent
    of colspans, automatically sized columns, etc. that can render directly to
    PDF?
    >
    Longer question:
    >
    I'm re-doing a big chunk of locally-written code. I have a
    report-generating function that takes a list of lists of lists as input and
    returns either a PDF, an HTML table, or an Excel spreadsheet as requested.
    For example, input might look like:
    >
    makereport('htm l',
    headers=['Invoice number', 'Customer', 'Price'],
    data=[
    [['123', 'John Doe', '$50.00'],
    ['Ordered on 2008-01-01 via the website']],
    [['124', 'Peter Bilt', '$25.99'],
    ['Mail via African swallow']]
    ])
    >
    This would result in HTML like:
    >
    <table>
    <tr>
    <th>Invoice number</th>
    <th>Customer</th>
    <th>Price</th>
    </tr>
    <tr class="lightbac kground">
    <td>123</td>
    <td>John Doe</td>
    <td>$50.00</td>
    </tr>
    <tr class="lightbac kground">
    <td colspan="3">Ord ered on 2008-01-01 via the website</td>
    </tr>
    <tr class="darkerba ckground">
    <td>124</td>
    <td>Peter Bilt</td>
    <td>$25.99</td>
    </tr>
    <tr class="darkerba ckground">
    <td colspan="3">Mai l via African swallow</td>
    </tr>
    </table>
    >
    Note particularly how the explanatory notes for each invoice are similar in
    appearance to the "primary" report lines they're associated with.
    >
    Now, I have a similar transformation to PDF via pdflatex. This works fairly
    well but requires a bunch of temp files and subprocesses, and I've never
    been 100% happy with the LaTeX output (you have to calculate your own
    column widths, for instance). Since I plan to re-write this anyway, I'd
    like to find a more widely used library if one was available.
    >
    ReportLab seemed *almost* perfect, except that it doesn't support colspans.
    As I hope I demonstrated in the example, most of our reports depend on that
    ability.
    >
    So, again, any thoughts on a PDF generator that can generate tables with the
    same kind of flexibility as HTML?
    It does support the equivalent of colspans. See page 75 of the userguide manual.

    -Larry

    Comment

    • Ken Starks

      #3
      Re: Suggestions for creating a PDF table

      Kirk Strauser wrote:
      Short question:
      >
      Is there a good library for generating HTML-style tables with the equivalent
      of colspans, automatically sized columns, etc. that can render directly to
      PDF?
      >
      Longer question:
      >
      I'm re-doing a big chunk of locally-written code. I have a
      report-generating function that takes a list of lists of lists as input and
      returns either a PDF, an HTML table, or an Excel spreadsheet as requested.
      For example, input might look like:
      >
      makereport('htm l',
      headers=['Invoice number', 'Customer', 'Price'],
      data=[
      [['123', 'John Doe', '$50.00'],
      ['Ordered on 2008-01-01 via the website']],
      [['124', 'Peter Bilt', '$25.99'],
      ['Mail via African swallow']]
      ])
      >
      >
      <snip>
      >
      >
      Now, I have a similar transformation to PDF via pdflatex. This works fairly
      well but requires a bunch of temp files and subprocesses, and I've never
      been 100% happy with the LaTeX output (you have to calculate your own
      column widths, for instance). Since I plan to re-write this anyway, I'd
      like to find a more widely used library if one was available.
      >
      <snip>
      >
      >
      Short answer: LaTeX should be good. Use XML source; XSLT to TeXML; TeXML
      to LaTeX ( uses a python program); compile to PDF.

      Longer answer: Can you provide a minimal example of the kind of
      LaTeX source you would ideally like ?

      If not, your problem is with LaTeX itself, which has if anything
      __too_many__ ways of controlling tables rather than inadequate
      ways. If so, we may be able to help with the rather arcane
      transformation into TeXML format.

      As for all the temp files that LaTeX creates, they are easily dealt
      with using a makefile or whatever.

      Bye for now,
      Ken

      Comment

      Working...