3

I have a web application that produce its reports in HTML format. Sometimes these reports become very much and the window shows scrollbars. The problem I have is that I can just print what I see in the web page, and whenever I want to print them, I have not more than 1 page to print. So I lose other repots that I expect to be in other papers.

What do I have to do ?

Mohammad Saberi
  • 12,864
  • 27
  • 75
  • 127

2 Answers2

8

The nature of the problem

Your problem is associated with styling.

It is hard to tell what exactly your problem is - we did not have a chance to see your stylesheets. For sure you should rewrite them to not crop the pages.

Apply different stylesheets to screen and print

One idea is to change current stylesheet to be applied only to screen media and apply different one specifically to printed media.

You can do it like that in HTML:

<link rel="stylesheet" type="text/css" media="screen" href="screen.css" />
<link rel="stylesheet" type="text/css" media="print" href="print.css" />

or like that in CSS (example from W3C):

@import url("fancyfonts.css") screen;
@media print {
    /* style sheet for print goes here */
}

Print-specific styling

For details on print-specific styles see the following page: http://www.w3.org/TR/CSS2/page.html

In your case the following styling may become useful:

table { page-break-inside: auto; }
tr { page-break-inside: avoid; page-break-after: auto; }
thead { display: table-header-group; }
tfoot { display: table-footer-group; }

It will allow for page breaks inside the table, will try to avoid page breaks inside rows, and will repeat both headers and footers of the table on each page. However, check whether it works in your target browsers, to be sure.

Tadeck
  • 132,510
  • 28
  • 152
  • 198
  • I found out that I need to use page-break property in CSS. But I don't know when do I must insert it. I have a table with many rows, and right now, some of these rows are not visible to print – Mohammad Saberi Jan 03 '12 at 12:30
  • @Mohammad: Does the following resource help you: http://stackoverflow.com/questions/1763639/how-to-deal-with-page-breaks-when-printing-a-large-html-table ? – Tadeck Jan 03 '12 at 14:46
0

If you are using ASP.NET, use Crystal Reports.

If you are using Java EE, use JasperReports.

If you are using PHP, use FPDF (there may be something else too).

These tools are better for bulding reports rather than pure HTML.

Acn
  • 1,010
  • 2
  • 11
  • 22
  • 1
    Your "better" is rather subjective. HTML can be simply styled for print, no need to export files to PDF (especially when you only want to print them). Exporting to PDF is however an alternative solution. – Tadeck Jan 03 '12 at 10:10