ho risolto così, ovviamente sono da adattare in base alle vostre esigenze
codice:
<%@ attribute name="type" required="true"%>
STAMPA
<script type="text/javascript">
function stampaElenco() {
compileHTML();
}
function printJob() {
var myWindow = window.open('', '', 'width=screen.availWidth,height=screen.availHeight');
myWindow.document.write($("#printDivMain").text());
myWindow.document.write($("#printDiv").text());
myWindow.document.close();
myWindow.focus();
myWindow.print();
myWindow.close();
}
function compileHTML() {
$.ajax({
contentType : 'application/json; charset=utf-8',
type : 'POST',
url : '/jod-portal/calendar-portlet/service/rest/createHtml/printJob/${type}',
dataType : 'json',
data : JSON.stringify(idEventToSend),
success : function(results) {
$("#printDiv").text(results);
printJob();
},
error : function(results) {
$('#new_errorMessCompNewVisit').empty().html(results.responseText).attr('hidden', false);
}
})
}
</script>
<div id="printDivMain" style="display: none">
Pagina di stampa per ${type }
</div>
<div id="printDiv" style="display: none"></div>