javascript - how to export the 'hidden div' element as PDF without showing it on the UI -
please consider following hidden div element. using hidden element construct pdf contents , trying download pdf.
html elements declared below.
<div id="griddata" style="display:none;"> <div id="reportheader" style="display:none;"> consider other elements want show in pdf here </div> </div>
and below kendo export chart pdf code, call through loadpdf function.
function loadpdf() { try { $("#griddata").show(); $("#reportheader").show(); if ($("#chartdiv").html() != null && $("#griddata").html() != '') { settimeout(function () { kendo.drawing.drawdom($("#griddata")) .then(function (group) { // render result pdf file return kendo.drawing.exportpdf(group, { papersize: "auto", margin: { left: "1cm", top: "1cm", right: "1cm", bottom: "1cm" } }); }) .done(function (data) { // save pdf file kendo.saveas({ datauri: data, filename: window.sessionstorage.getitem('xxxname') + ".pdf", proxyurl: "/account/export" }); $("#reportheader").hide(); $("#griddata").hide(); }); }, 2000); } } catch (e) { $("#reportheader").hide(); $("#griddata").hide(); umgeneratealert('error while exporting data'); } { } }
the above method works fine, problem is, before exporting "griddata" div elements pdf, forced enable div. otherwise exported pdf returns no data. causing "griddata" div appear on screen till pdf gets exported , gets hidden once document downloaded.
please suggest me how can handle this, without displaying in ui.
try css print media query:
@media print { /* print styles go here */ #header, #footer, #nav { display: none !important; } #griddata, #reportheader { display: block !important; } }
or old way:
<link href="/print.css" rel="stylesheet" media="print" type="text/css" />
regarding grid part, have tried using visibility: hidden;
? since space , dimensions of element preserved.
if you, show overlay layer loading progress bar covers grid area , hide after finish hidding grid.
anyway, display: none
still part of dom, i'll update answer if there workaround.
Comments
Post a Comment