Printing "≪Html≫" Using Html

Print the contents of a DIV

Slight changes over earlier version - tested on CHROME

function PrintElem(elem)
{
var mywindow = window.open('', 'PRINT', 'height=400,width=600');

mywindow.document.write('<html><head><title>' + document.title + '</title>');
mywindow.document.write('</head><body >');
mywindow.document.write('<h1>' + document.title + '</h1>');
mywindow.document.write(document.getElementById(elem).innerHTML);
mywindow.document.write('</body></html>');

mywindow.document.close(); // necessary for IE >= 10
mywindow.focus(); // necessary for IE >= 10*/

mywindow.print();
mywindow.close();

return true;
}

printing html using html

Use HTML character references:

<html>

Should output

<html>

Print Html template in Angular 2 (ng-print in Angular 2)

That's how I've done it in angular2 (it is similar to that plunkered solution) In your HTML file:

<div id="print-section">
// your html stuff that you want to print
</div>
<button (click)="print()">print</button>

and in your TS file :

print(): void {
let printContents, popupWin;
printContents = document.getElementById('print-section').innerHTML;
popupWin = window.open('', '_blank', 'top=0,left=0,height=100%,width=auto');
popupWin.document.open();
popupWin.document.write(`
<html>
<head>
<title>Print tab</title>
<style>
//........Customized style.......
</style>
</head>
<body onload="window.print();window.close()">${printContents}</body>
</html>`
);
popupWin.document.close();
}

UPDATE:

You can also shortcut the path and use merely ngx-print library for less inconsistent coding (mixing JS and TS) and more out-of-the-box controllable and secured printing cases.

Print div id=printarea/div only?

Here is a general solution, using CSS only, which I have verified to work.

@media print {
body * {
visibility: hidden;
}
#section-to-print, #section-to-print * {
visibility: visible;
}
#section-to-print {
position: absolute;
left: 0;
top: 0;
}
}

Alternative approaches aren't so good. Using display is tricky because if any element has display:none then none of its descendants will display either. To use it, you have to change the structure of your page.

Using visibility works better since you can turn on visibility for descendants. The invisible elements still affect the layout though, so I move section-to-print to the top left so it prints properly.

How to print a large HTML table with page breakers?

you could try using orphans to specify the number of empty lines to be left at the bottom of a page; if an element's layout conflicts with an orphans setting, the element will be printed on the next page. browser support is pretty shoddy though. i would set it on tr for your example, like this:

tr{orphans:3}

Auto start print html page using javascript

<body onload="window.print()">
or
window.onload = function() { window.print(); }

no border on HTML table when printing

As the table is being copied to a new window, your CSS is not being retained. You can get around this by passing some relevant CSS across to the new window in your document.write() method. You also need to provide a small amount of padding to introduce the borders. See the following JSFiddle showing this in action: http://jsfiddle.net/826Zm/3/

function printDiv() {
var divToPrint = document.getElementById('table');
var htmlToPrint = '' +
'<style type="text/css">' +
'table th, table td {' +
'border:1px solid #000;' +
'padding:0.5em;' +
'}' +
'</style>';
htmlToPrint += divToPrint.outerHTML;
newWin = window.open("");
newWin.document.write(htmlToPrint);
newWin.print();
newWin.close();
}

How to print each td../td on a new line in PHP?

concat "\n" to the front of the statement

Edit

$entries[$i] = "\n" . '<td>'.$id[$i] .'</td>';
$entries[$i] .= "\n" . '<td>'.$username[$i].'</td>';
$entries[$i] .= "\n" . '<td>'.$first_name[$i].'</td>';


Related Topics



Leave a reply



Submit