The CSS standard enables some advanced formatting. There is a @page directive in CSS that enables some formatting that applies only to paged media (like paper). See http://www.w3.org/TR/1998/REC-CSS2-19980512/page.html.
<html xmlns="http://www.w3.org/1999/xhtml">_x000D_
<head>_x000D_
<title>Print Test</title>_x000D_
<style type="text/css" media="print">_x000D_
@page _x000D_
{_x000D_
size: auto; /* auto is the current printer page size */_x000D_
margin: 0mm; /* this affects the margin in the printer settings */_x000D_
}_x000D_
_x000D_
body _x000D_
{_x000D_
background-color:#FFFFFF; _x000D_
border: solid 1px black ;_x000D_
margin: 0px; /* the margin on the content before printing */_x000D_
}_x000D_
</style>_x000D_
</head>_x000D_
<body>_x000D_
<div>Top line</div>_x000D_
<div>Line 2</div>_x000D_
</body>_x000D_
</html>
_x000D_
and for firefox use it
In Firefox, https://bug743252.bugzilla.mozilla.org/attachment.cgi?id=714383 (view page source :: tag HTML).
In your code, replace <html>
with <html moznomarginboxes mozdisallowselectionprint>.