jsp and htnl table Design

Posted on 2004-08-18
Last Modified: 2013-12-03
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..
Question by:adriankelly
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
  • +2
LVL 11

Expert Comment

ID: 11832039
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.


Author Comment

ID: 11832165
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  |  
LVL 11

Expert Comment

ID: 11832263
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 11

Expert Comment

ID: 11832287
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.

Author Comment

ID: 11832479
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
LVL 11

Expert Comment

ID: 11832881
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


Expert Comment

ID: 11833183
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.

Author Comment

ID: 11839156
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.  

Expert Comment

ID: 11846284
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.

Accepted Solution

jjerome00 earned 125 total points
ID: 11853396
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!


Expert Comment

ID: 11853476
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.
LVL 11

Expert Comment

ID: 11866647
If you want to use reporting tools for free, I recommend jasper.

best luck,

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Retrieving file from bytes array in spring mvc 8 62
maven j2ee examles 2 64
Books that can get me started on JAVA 2 118
mysql jsp example issue 32 75
Facebook has became the #1 social media platform. People share many funny videos there, yet you don't know how to download them? Now you can download Videos from Facebook in just 3 simple steps.
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question