jsp and htnl table Design

I am currently writing a web application using jsp. The aim of the system is to price
items of work. I wont go too indepth as to what it does but I have jsp pages that
produce a sumary of prices and descriptions of each item of work(from database)
in html table format. As a requirement I need to be able to print this information from
Internet Explorer. I have been stuck on this for quite some time and i need some expert advise
as to how i would organise the dynamic content of my jsps to produce html tables that can be printed.
Eg.. if there are 400 items of works to be printed this will take perhaps 20 A4 printed pages, each row in the html table may be of different height, depending on the information regarding that item.
Is it possible that each page will contain the table heading;;
(simplified example..)
also is it possible to avoid table row entries being split horizontaly over 2 pages.
Thanks in Advance..
Who is Participating?
jjerome00Connect With a Mentor Commented:
HTML wasn't designed to have these features, but you can certainly cheat to get the results you want.  I would take a look at the data you are trying to display, and see how often these multiple lines of description usually are.  

First I would find out how many physical table rows fit on a page.  By physical rows I mean an actual line of text (i.e. one item might produce more than one physical row - your example above has 9 rows).

I would then keep track of how many of these physical rows have been used on the page.  Since you can set the width of the columns, you can calculate how many letters constitute a new row.  For example, the description field in your example might have 100 characters, and you know you can fit 20 characters per row - you have 5 rows for that one item.  The idea is to keep a relatively good idea of how many rows you are displaying.

When you get to the maximum number of rows for the page, then you can close out the table, add some space to get to the next page, and restart a new table.

Of course you will have to play around with your settings a bit, but you should be able to build a few functions to break down the problem into smaller tasks.  You can calculate how many rows an item entry should take and see if it will fit on the page, or if it should start on the next page.

Good luck!

if you want to split like this, I think it's possible by using programming.

1                     8
2                     9
3                     10
4                     11
5                     12
6                     13
7                     14

if you want to do like this, it's very quite difficult becuase we will not know how much row will fit to one page
but if you really want to do this you may provide textbox in the prior page for who want to print can configure
how many rows per page.

1                     4
2                     5
3                     6

7                     10
8                     11
9                     12


Hope this can generate your idea.

adriankellyAuthor Commented:
The table will look like

quanty |  price  | description| tax    |.....Top of table
2         |12.0    | a product  |  12% |    .....Typical table row
3         |11.0    | a product   |14% |   ...... A row with increased height
           |          |that needs  |
           |          | alot more   |
           |          |description  |  
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

the height of each row will depend on data its reside. but you have fix the width of column by

  <td width="30">
  <td width="50">

The above code will fix width of first column to 30 pixel and the second 50 pixel
about the table header that you want to print in every page. like I said you may ask client user to submit the number of row to print per page. so we can print the header again when the row reach the value they submit.
adriankellyAuthor Commented:
Imagine you have a web page with a html table with 400 rows in it. Each row is of varying tickness/ height. I need to print this table so that each printed page will have the table heading on it and no rows of the table will be split across 2 of the printed A4 paper pages
Umm. I see. So in case of the last row on that page, if that whole row can fit into the page so how can we push that row to the next page and also re-print the header of the table, right?

this comment just clarify your question. I will try to find solution for you

I think you may want a CSS printing style sheet. I am not familiar with the details of how to do it but I think it may be the solution to your problem.
adriankellyAuthor Commented:
Sompol has got what im trying to do.
Iv tried some CSS stuff but havent had much success. I am reasonably new to web design and felt that this problem would have been encountered before.
There has to be a way around it!
Could I take the info from my java classes and show the information on some
type of scrollable  applet as opposed to html??
I really need to get it sorted.  
This would be a different direction for you, but if the report needs to be printed, you should consider PDF generation.  PDF by design was made for this type of a thing whereas HTML by design was not.  There are plenty of free and/or inexpensive libraries to use for generating PDFs.  If you can find one that can provide you with some kind of feedback as to how much space you have left on a particular page as you are generating it, then you've found waht you need.
If you decide by chance to look at the PDF route, there is a product called pd4ml.  It is fairly inexpensive (approx $75 US per site or program you use it in) and even free if what you're doing is non-profit.  It converts HTML output to PDF, so if you can manage to get your HTML to format just the way you want you only have to worry about how it fits in one environment instead of making it work for every browser on the planet and every printer configuration that they have.
If you want to use reporting tools for free, I recommend jasper.


best luck,
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.