How to print from own print button if user hasn't Adobe Flash installed?
How to print from own print button if user hasn't Adobe Flash installed?
MichaelLand
Posts: 26Questions: 0Answers: 0
Hello, I'm building support to my application and it's possibility to print DataTables when Flash is installed or not.
Easier was build the one with Flash.
But haven't got a proper idea how to print DataTable when Flash is not installed. What I did so far was:
1. I checked with Javascript if Flash is installed
2. If not I created a own HTML input button and Javascript/jQuery in it's click handler
3. If my printing Function is following
$(function () {
// Hook up the print link.
$("#Print").click(
function () {
$("#GeneratedReport").print(); // This prints contents of DataTable
I get messy text into printer. I think because it's not html/css.
4. I tried to copy html data of from DataTable into Javascript window and meaning was printing it there.
But... I didn't know how to get data from DataTable in html format into Javascript Window so I could'n get it work.
Code was something like below ... or with small changes.
$("#Print").click(
function () {
var thePopup = window.open('', "Report", "menubar=0,location=0,height=700,width=700");
oTable = $('#GeneratedReport').dataTable();
var nNodes = oTable.fnGetNodes();
jQuery.each(nNodes, function (i) {
var text = document.createTextNode(nNodes[i].innerHTML);
thePopup.document.body.appendChild(text);
});
thePopup.print();
// This does not work...
How this kind of feature should be done?
Thanks,
Mike
Easier was build the one with Flash.
But haven't got a proper idea how to print DataTable when Flash is not installed. What I did so far was:
1. I checked with Javascript if Flash is installed
2. If not I created a own HTML input button and Javascript/jQuery in it's click handler
3. If my printing Function is following
$(function () {
// Hook up the print link.
$("#Print").click(
function () {
$("#GeneratedReport").print(); // This prints contents of DataTable
I get messy text into printer. I think because it's not html/css.
4. I tried to copy html data of from DataTable into Javascript window and meaning was printing it there.
But... I didn't know how to get data from DataTable in html format into Javascript Window so I could'n get it work.
Code was something like below ... or with small changes.
$("#Print").click(
function () {
var thePopup = window.open('', "Report", "menubar=0,location=0,height=700,width=700");
oTable = $('#GeneratedReport').dataTable();
var nNodes = oTable.fnGetNodes();
jQuery.each(nNodes, function (i) {
var text = document.createTextNode(nNodes[i].innerHTML);
thePopup.document.body.appendChild(text);
});
thePopup.print();
// This does not work...
How this kind of feature should be done?
Thanks,
Mike
This discussion has been closed.
Replies
Allan
Code like this works only one visual error comes to PrintPreviewPage
"oTableTools": {
"aButtons": [
{
"sExtends": "text",
"sButtonText": "Print report",
"sInfo": "Creating report." + "Return using ESC key.",
"fnClick": function (nButton, oConfig) {
this.fnPrint( true, oConfig );
}
}
When PrintPreviewPage is ready in it's top left corner comes text "Undefined".
Text comes before any rows in DataTable.
Any ideas what variable or which can cause this "Undefined" text to be there?
Best Regards,
Mike
Allan
Setting sMessage solved the problem.
Best Regards
Mike