$(document).on('click', '.result-div .download-button', function(e) { $('.table.main-table').DataTable().destroy(); // Get product details /* var product = $(".media-heading")[0].innerText; */ var product = $(".media-body")[0].innerText; if (typeof product === "undefined") { product = ""; } //Copy the value of the filters var connection = $(".result-div input[id*='research_form_connection']:checked").val(); if (typeof connection === "undefined") { connection = ""; } tab = []; connects_to = $(".result-div input[id*='research_form_connects_to']:checked").each(function(e){ tab.push($(this).val()) }); connects_to = tab.join(', '); wearing_style = $(".result-div input[id*='research_form_wearing_style']:checked").val(); if (typeof wearing_style === "undefined") { wearing_style = ""; } $('#table_content_compat tr th').each(function(i) { //select all tds in this column var tds = $(this).parents('table') .find('tr td:nth-child(' + (i + 1) + ')'); if(tds.is(':empty') || $(this)[0].innerText === 'Related Notes / Articles' || $(this)[0].innerText === '') { $(this).hide(); tds.hide(); } }); // Static base64 for example purposes /* base64Img = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyBAMAAADsEZWCAAAAG1BMVEXMzMyWlpaqqqq3t7exsbGcnJy+vr6jo6PFxcUFpPI/AAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAQUlEQVQ4jWNgGAWjgP6ASdncAEaiAhaGiACmFhCJLsMaIiDAEQEi0WXYEiMCOCJAJIY9KuYGTC0gknpuHwXDGwAA5fsIZw0iYWYAAAAASUVORK5CYII='; */ var doc = new jsPDF('p', 'pt', 'a4',false); doc.autoTable({ html: '#table_content_compat', bodyStyles: {minCellHeight: 15}, columnStyles: { 0: {cellWidth: 100}, 1: {cellWidth: 100}, 2: {cellWidth: 100} }, didDrawPage: function(data) { // Header if (doc.internal.getNumberOfPages() == 1){ doc.setTextColor(44,129,195); doc.setFontSize(16); doc.setFontStyle('bold'); /* if (base64Img) { doc.addImage(base64Img, 'JPEG', 260, 30, 30, 20); } */ doc.text(product, 50, 30); doc.setTextColor(0,0,0); doc.setFontSize(9); doc.setFontStyle('normal'); doc.text('Connection:' + connection, 400, 30); doc.text('Connects-to:' + connects_to, 400, 40); doc.text('Wearing style:' + wearing_style, 400, 50); } // Footer var footerinfo = " Information correct at the time of creation " + new Date().toLocaleString() + " For the latest compatibility information please visit"; var footerurl = "www.poly.com/compatibility"; doc.setTextColor(44,129,195); doc.setFontSize(9); doc.setFontStyle('normal'); var pageSize = doc.internal.pageSize; var pageHeight = pageSize.height ? pageSize.height : pageSize.getHeight(); var pagenumber = 'Page ' + doc.internal.getNumberOfPages(); doc.text(footerinfo, data.settings.margin.left, pageHeight - 25); doc.setTextColor(0,0,238); doc.setFontStyle('italic'); doc.text(footerurl, 240, pageHeight - 15); doc.setFontStyle('bold'); doc.setTextColor(44,129,195); doc.text(pagenumber, 525, pageHeight - 10); }, didDrawCell: function(data) { var td = data.cell.raw; if (td.getElementsByTagName('img')[0] != null && data.cell.section === 'body') { var children = data.cell.raw.childNodes; children.forEach(function(item){ if(item.nodeName === 'IMG'){ if(item.currentSrc.includes('yes.png') || item.currentSrc.includes('exclamation-point.png') || item.currentSrc.includes('obsolete.png')){ var img = 'data:image/png;base64,'; var code = getBase64Image(item); img = img+code; doc.addImage(img,'png',data.cell.x + 30,data.cell.y + 4 ,15,15); } }else if (item.nodeName === 'A') { if(item.childNodes.length > 0){ var grandsons = item.childNodes; grandsons.forEach(function(item2){ if(item2.nodeName === 'IMG'){ if(!(item2.currentSrc.includes('yes.png') || item2.currentSrc.includes('exclamation-point.png') || item2.currentSrc.includes('obsolete.png'))){ var img = 'data:image/png;base64,'; var code = getBase64Image(item2); img = img+code; doc.addImage(img,'png',data.cell.x + 30 ,data.cell.y + 4 ,15,15); } } }); } } }); } }, margin: {top: 80} }); doc.save('Poly_Websearch_Export.pdf'); $('#table_content_compat tr th').each(function(i) { //select all tds in this column var tds = $(this).parents('table') .find('tr td:nth-child(' + (i + 1) + ')'); if(tds.is(':empty') || $(this)[0].innerText === 'Related Notes / Articles') { $(this).show(); tds.show(); } }); //Reset the size of the first collumn $(".table tbody tr td.details-control").css("width", "20px"); //Reinstall the datatble $('.table.main-table').DataTable({"pageLength": 20, "orderFixed": [collumns, "desc"], "columnDefs": [{"targets": [collumns], "visible": false, "searchable": false}], "language": {"emptyTable": "No results found, please contact Plantronics Customer Care for further help by visiting www.poly.com/contact"}}); function getBase64Image(img) { var canvas = document.createElement("canvas"); canvas.width = img.width; canvas.height = img.height; var ctx = canvas.getContext("2d"); ctx.drawImage(img, 0, 0); var dataURL = canvas.toDataURL("image/png"); return dataURL.replace(/^data:image\/(png|jpg);base64,/, ""); } });