Anyone know JavaScript code to open Cognos 10.2 HTML output in PDF format. I want to add button using Javascript on Report page and user will export to PDF using button. We want to openPDF output in new cognos viewer window.
Below code is working as expected in Cognos 8.4. same code is not working in Cognos 10.2. Please help me to change below JavaScript…I am getting error 'CCognosViewerRequest' is undefined...
<script language="javascript">
CViewerManager.prototype.viewInPDF = function(){
var format = 'PDF';
var oReq =new CCognosViewerRequest("render");
oReq.addOption("run.outputFormat", format);
var oldUnload = window.onbeforeunload;
window.onbeforeunload = null;
var target = "winNAT_" + (new Date()).getTime();
var sPath = this.getCV().getWebContentRoot() + "/" + "rv/blankNewWin.html?cv.id=" + this.getCVId();
var oCV = this.getCV();
if (oCV && oCV.sSkin) { sPath += "&skin=" + oCV.sSkin; }
var sFormID = "viewForm" + this.getCVId();
var oForm = document.getElementById(sFormID);
if (oForm) {oForm.parentNode.removeChild(oForm);}
oForm = document.createElement("form");
oForm.setAttribute("method", "post");
oForm.setAttribute("id", sFormID);
oForm.setAttribute("action", this.getCV().getGateway());
oForm.style.display = "inline";
var oParams = this.getCV().generateRequestParams(oReq);
var oFWR = document["formWarpRequest" + this.getCVId()];
if (oFWR && oFWR['run.outputFormat']) {oParams.previousFormat = oFWR['run.outputFormat'].value;}
for (var idxParam in oParams)
{
if (idxParam != "cv.responseFormat" && idxParam != "b_action")
{
oForm.appendChild(createHiddenFormField(decodeURIComponent(idxParam), decodeURIComponent(oParams[idxParam])));
}
}
oForm.appendChild(createHiddenFormField("cv.responseFormat", "page"));
oForm.appendChild(createHiddenFormField("b_action", "cognosViewer"));
oForm.appendChild(createHiddenFormField("BIline1", this.getCV().oStrings.sReportIsRunning));
oForm.appendChild(createHiddenFormField("BIline2", this.getCV().oStrings.sPleaseWait));
document.body.appendChild(oForm);
oForm.target = target;
window.open(sPath, target, 'resizable=1');
window.onbeforeunload = oldUnload;
}
function runPDF(){
var node = document.getElementById("PDF");
while (node.nodeName != "FORM" && node.parentNode)
{
node = node.parentNode;
}
var formId = node.getAttribute("id").substring("formWarpRequest".length);
eval("oCV" + formId + ".getRV().viewInPDF()");
}
function gotoUrl(strFormat)
{
var fW = (typeof getFormWarpRequest == "function" ? getFormWarpRequest() : document.forms["formWarpRequest"]);
if ( !fW || fW == undefined) { fW = ( formWarpRequest_THIS_ ? formWarpRequest_THIS_ : formWarpRequest_NS_ );}
var preFix = "";
if (fW.elements["cv.id"]) { preFix = fW.elements["cv.id"].value; }
setTimeout('window.onload(oCV'+preFix+'.getRV().viewReport(\''+strFormat+'\'));', 100)
}
</script>
<html>
<table>
<tr>
<td align="center" id="PDF" onclick="runPDF();"class="toolbarButton" onmouseover="document.getElementById('PDF').className='toolbarButtonOver';window.status='';return true;" onmouseout="document.getElementById('PDF').className='toolbarButton';window.status='';return true;" style="cursor:pointer;">
<img src="../ps/portal/images/icon_result_pdf.gif" title="View Report in PDF."></td>
<td><img border="0" src="../qs/images/spacer.gif" width="1"></td>
</tr>
</table>
</html>