1

i am trying to place page breaks when printing a dynamic table that is part of an email body generated within an .Net 4.0 framework C# console program:

<table>
    <div style='page-break-before: always'>
    <tr><td> header data </td></tr> </div>

    <tr><td> data </td></tr>
    '' multiple rows
</table>

when the program runs i can see the data and format but it shows 4 times the number of pages within Outlook print preview, so by example where there should be 20 pages max there are 80+!!

i've run it within the debugger and the email body is okay but i cannot find out why the number of pages are off when viewing within Outlook and the print preview. i believe the div tag maybe the issue. i took it out and shows ok but no page breaks. i have to use inline css since using the usual 'style' tag doesn't work within the .Net email class.

also note that i tried using the 'style' tag on the row for the page-break-before but it didn't work.

  • I just saw your edit. Did you remove the `div` tag when you added `style`? can you also post some of your real HTML to try and figure out what went wrong? – Ted Aug 27 '14 at 19:25

1 Answers1

0

Well, it's rather obvious that using a div within a table tag is syntactically incorrect, Scrap it all together and add the following before your table tag:

table { page-break-inside:auto } tr { page-break-inside:avoid; page-break-after:auto }

Have you tried it like this: (make sure you remove the div after table.

<table style="page-break-before:always; page-break-after:always;"> <tr style="page-break-inside: avoid;"> . . . .

Ted
  • 3,985
  • 1
  • 20
  • 33
  • I just saw your edit, did you remove the `div` tag when you added `style`? – Ted Aug 27 '14 at 19:24
  • You don't understand, the email body is built with 'out' as a string. The string must only use inline CSS for styling. it's an Microsoft limitation for populating the email body. And already tried it using style tags to table and tr row. No luck previously researched from another question on stackoverflow: http://stackoverflow.com/questions/8712677/how-to-apply-css-page-break-to-print-a-table-with-lots-of-rows –  Aug 27 '14 at 19:33
  • Nope. didn't remove the 'div' tag. –  Aug 27 '14 at 19:34
  • I've used it before, but I cannot remember how, have you tried enclosing it with /* <![CDATA[ */ ... /* ]]> */ – Ted Aug 27 '14 at 19:36
  • remove the div tag and try again – Ted Aug 27 '14 at 19:36
  • Tried it without the div and using CDATA in the style tag wrapping the CSS statements. No luck. –  Aug 28 '14 at 13:15
  • removed DIV tag, added style markup to table and tr and still no page breaks. –  Aug 28 '14 at 13:53
  • 1
    I used your posted answer as a partial solution. MS Outlook evidently doesn't like it so i added an HTML version of the page as an attachment which the user can click and print from with you solution. –  Sep 02 '14 at 12:33