Topic
  • 14 replies
  • Latest Post - ‏2015-08-04T14:08:05Z by venkatachalapathi
Mekd1977
Mekd1977
3 Posts

Pinned topic JavaScript code to open Cognos 10.2 HTML output in PDF format.

‏2013-06-10T15:07:37Z |

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>

 

Updated on 2013-06-10T15:08:57Z at 2013-06-10T15:08:57Z by Mekd1977
  • Suresh_BI
    Suresh_BI
    21 Posts

    Re: JavaScript code to open Cognos 10.2 HTML output in PDF format.

    ‏2013-06-13T06:02:11Z  

    Hi,

               To convert the HTML output to PDF please follow as below.

    Drag New HTML Item to the report and write code like   <input type='Button' value="Report in PDF"  onclick="javascript:gCognosViewer.getRV().viewReport('PDF')">

    Thanks,

    Suresh.

  • Winson11
    Winson11
    29 Posts

    Re: JavaScript code to open Cognos 10.2 HTML output in PDF format.

    ‏2013-06-13T14:48:31Z  
    • Suresh_BI
    • ‏2013-06-13T06:02:11Z

    Hi,

               To convert the HTML output to PDF please follow as below.

    Drag New HTML Item to the report and write code like   <input type='Button' value="Report in PDF"  onclick="javascript:gCognosViewer.getRV().viewReport('PDF')">

    Thanks,

    Suresh.

    Thanks Suresh. 

    Excellent working fine.

     

    Also I tested O/P code it is also working fine with 10.1 as well.

     

    Winson.

    Updated on 2013-06-13T14:51:09Z at 2013-06-13T14:51:09Z by Winson11
  • Mekd1977
    Mekd1977
    3 Posts

    Re: JavaScript code to open Cognos 10.2 HTML output in PDF format.

    ‏2013-06-14T14:04:04Z  
    • Suresh_BI
    • ‏2013-06-13T06:02:11Z

    Hi,

               To convert the HTML output to PDF please follow as below.

    Drag New HTML Item to the report and write code like   <input type='Button' value="Report in PDF"  onclick="javascript:gCognosViewer.getRV().viewReport('PDF')">

    Thanks,

    Suresh.

    Hey Suresh,

     

    Thanks for providing code to export HTML output to PDF. I want to open PDF output in new Cognos viewer window. Your code is opening output in same Cognos viewer window..

     

    Any idea how to open HTML output in PDF (New Cognos viewer window)?

     

    Thanks,

    KD

  • Winson11
    Winson11
    29 Posts

    Re: JavaScript code to open Cognos 10.2 HTML output in PDF format.

    ‏2013-06-14T18:38:15Z  
    • Mekd1977
    • ‏2013-06-14T14:04:04Z

    Hey Suresh,

     

    Thanks for providing code to export HTML output to PDF. I want to open PDF output in new Cognos viewer window. Your code is opening output in same Cognos viewer window..

     

    Any idea how to open HTML output in PDF (New Cognos viewer window)?

     

    Thanks,

    KD

    Hey KD,

    I am not expert with JS. But if u really want someone to take a look at it and have quick fix. Here is the man who can do it.

     

    http://cognospaul.wordpress.com/category/prompts/

     

    Winson.

  • Missa
    Missa
    4 Posts

    Re: JavaScript code to open Cognos 10.2 HTML output in PDF format.

    ‏2013-06-20T17:18:27Z  
    • Suresh_BI
    • ‏2013-06-13T06:02:11Z

    Hi,

               To convert the HTML output to PDF please follow as below.

    Drag New HTML Item to the report and write code like   <input type='Button' value="Report in PDF"  onclick="javascript:gCognosViewer.getRV().viewReport('PDF')">

    Thanks,

    Suresh.

    Hi Suresh

    Your code works great. Can you tell me how I can do this same thing only export the report to Excel?

     

    Thanks

    Missa

  • Suresh_BI
    Suresh_BI
    21 Posts

    Re: JavaScript code to open Cognos 10.2 HTML output in PDF format.

    ‏2013-06-22T05:28:15Z  
    • Missa
    • ‏2013-06-20T17:18:27Z

    Hi Suresh

    Your code works great. Can you tell me how I can do this same thing only export the report to Excel?

     

    Thanks

    Missa

    Hi Missa,

     <input type='Button' value="Report in PDF"  onclick="javascript:gCognosViewer.getRV().viewReport('PDF')">= for PDF

    <input type='Button' value="Report in PDF"  onclick="javascript:gCognosViewer.getRV().viewReport('CSV')">= for CSV

    <input type='Button' value="Report in PDF"  onclick="javascript:gCognosViewer.getRV().viewReport('XML')">= for XML

    <input type='Button' value="Report in PDF"  onclick="javascript:gCognosViewer.getRV().viewReport('singleXLS')">= for single Excel sheet

    <input type='Button' value="Report in PDF"  onclick="javascript:gCognosViewer.getRV().viewReport('MHT')">= for active Report

    <input type='Button' value="Report in PDF"  onclick="javascript:gCognosViewer.getRV().viewReport('spreadsheetML')">= for Excel 2007

     

     

     

     

     

  • Missa
    Missa
    4 Posts

    Re: JavaScript code to open Cognos 10.2 HTML output in PDF format.

    ‏2013-06-25T15:20:11Z  
    • Suresh_BI
    • ‏2013-06-22T05:28:15Z

    Hi Missa,

     <input type='Button' value="Report in PDF"  onclick="javascript:gCognosViewer.getRV().viewReport('PDF')">= for PDF

    <input type='Button' value="Report in PDF"  onclick="javascript:gCognosViewer.getRV().viewReport('CSV')">= for CSV

    <input type='Button' value="Report in PDF"  onclick="javascript:gCognosViewer.getRV().viewReport('XML')">= for XML

    <input type='Button' value="Report in PDF"  onclick="javascript:gCognosViewer.getRV().viewReport('singleXLS')">= for single Excel sheet

    <input type='Button' value="Report in PDF"  onclick="javascript:gCognosViewer.getRV().viewReport('MHT')">= for active Report

    <input type='Button' value="Report in PDF"  onclick="javascript:gCognosViewer.getRV().viewReport('spreadsheetML')">= for Excel 2007

     

     

     

     

     

    Hi Suresh,

    Thanks for the quick reply.

    The code works great when I run the report straight from report folder, however I run my dashboard reports from a Page and it will not work when rendered from the Page. Any idea why the code wouldn't work on a tab within a Page?

    I've attached a spreadsheet with screenshots to explain a little better.

    Thank you so much for your help.

    Missa

    Attachments

  • Suresh_BI
    Suresh_BI
    21 Posts

    Re: JavaScript code to open Cognos 10.2 HTML output in PDF format.

    ‏2013-06-25T16:45:59Z  
    • Missa
    • ‏2013-06-25T15:20:11Z

    Hi Suresh,

    Thanks for the quick reply.

    The code works great when I run the report straight from report folder, however I run my dashboard reports from a Page and it will not work when rendered from the Page. Any idea why the code wouldn't work on a tab within a Page?

    I've attached a spreadsheet with screenshots to explain a little better.

    Thank you so much for your help.

    Missa

    Hi Missa,

                       Its working perfectly for me. It should work at your end also. Please check your HTML code.

    Please let me know if you need any info on this.

     

    thanks,

    Suresh.

  • Missa
    Missa
    4 Posts

    Re: JavaScript code to open Cognos 10.2 HTML output in PDF format.

    ‏2013-06-25T19:37:26Z  
    • Suresh_BI
    • ‏2013-06-25T16:45:59Z

    Hi Missa,

                       Its working perfectly for me. It should work at your end also. Please check your HTML code.

    Please let me know if you need any info on this.

     

    thanks,

    Suresh.

    Hi Suresh,

    I don't think it's the code because it works great from the report. It;s just when I run it from the Page, the Excel button reprompts and the PDF gives me the following error: 

     

    SOAPFaultException
    CV-0002 The request is not valid. Details are available in the log. Please contact your administrator.
    com.cognos.portal.fragment.server.SOAPFaultException: CV-0002 The request is not valid. Details are available in the log. Please contact your administrator.  
    

    I think the PDF error is a security issue, so I will need to buy the IT guys some donuts tomorrow, but I don't understand why the Excel code would be asking for the prompt selections again.

    Any idea's or suggestions would be helpful, but just so you know... it's not your code.

    Thanks,

    Missa

     

     

  • Missa
    Missa
    4 Posts

    Re: JavaScript code to open Cognos 10.2 HTML output in PDF format.

    ‏2013-06-25T19:55:32Z  
    • Missa
    • ‏2013-06-25T19:37:26Z

    Hi Suresh,

    I don't think it's the code because it works great from the report. It;s just when I run it from the Page, the Excel button reprompts and the PDF gives me the following error: 

     

    SOAPFaultException
    CV-0002 The request is not valid. Details are available in the log. Please contact your administrator.
    <pre dir="ltr">com.cognos.portal.fragment.server.SOAPFaultException: CV-0002 The request is not valid. Details are available in the log. Please contact your administrator. </pre>

    I think the PDF error is a security issue, so I will need to buy the IT guys some donuts tomorrow, but I don't understand why the Excel code would be asking for the prompt selections again.

    Any idea's or suggestions would be helpful, but just so you know... it's not your code.

    Thanks,

    Missa

     

     

    Let's just make this even stranger... I reselected the prompt information and it exported the report from the first tab instead of the tab I was on. I guess Page's isn't the way to go for Dashboards either. UGH!!

  • gopinaidu
    gopinaidu
    2 Posts

    Re: JavaScript code to open Cognos 10.1 HTML output in PDF format.

    ‏2013-11-25T11:47:56Z  
    • Suresh_BI
    • ‏2013-06-13T06:02:11Z

    Hi,

               To convert the HTML output to PDF please follow as below.

    Drag New HTML Item to the report and write code like   <input type='Button' value="Report in PDF"  onclick="javascript:gCognosViewer.getRV().viewReport('PDF')">

    Thanks,

    Suresh.

    I am using below javascript for Stacked bar in cognos 10.1, its rendering prefect in HTML output and coming to PDF its missing please help me any one regrading this...

     

    I think i Should include the following code, I tried it but no use

    CViewerManager.prototype.viewInPDF = function(){

                    var format = 'PDF';

     

    <script type="text/javascript">
                var bar1Percent = 70;
                var bar2Percent = 30;
                var length_driver =5;
                var width_driver = 200;
                var barlen = 40 * ((length_driver));
                var barheight = ((width_driver) / 10);
                var bar1Length = (barlen * bar1Percent) / 100;
                var bar2Length = (barlen * bar2Percent) / 100;
                var myTotalBar = '<div style="background-color:red;width:' + barlen + ';height:' + barheight + '">';
                var percent1 = '<div style="background-color:#F15A29; font-family:Source Sans Pro; font-size:11px; color:white; float:left; text-align:center; display:table-cell; vertical-align: middle;  width:' + bar1Length + ';height:' + barheight + '"> <span style="display:table-cell; width:inherit;height:inherit; vertical-align:middle"> <strong>' + bar1Percent.toFixed(1) + '%</strong></span></div>';
                var percent2 = '<div style="background-color:#2B3990; font-family:Source Sans Pro; font-size:11px;color:white; float:right;text-align:center; width:' + bar2Length + ';height:' + barheight + '"> <span style="display:table-cell; height:inherit; width:inherit; vertical-align:middle"> <strong>' + bar2Percent.toFixed(1) + '%</strong></span></div>';
                if (bar1Percent == 0)
                    percent1 = '';
                if (bar2Percent == 0)
                    percent2 = '';
                myTotalBar = myTotalBar + percent1 + percent2 + '</div>';
                document.write(myTotalBar);

    </script>

     

  • Chrismg
    Chrismg
    1 Post

    Re: JavaScript code to open Cognos 10.2 HTML output in PDF format.

    ‏2014-10-16T07:56:48Z  
    • Missa
    • ‏2013-06-20T17:18:27Z

    Hi Suresh

    Your code works great. Can you tell me how I can do this same thing only export the report to Excel?

     

    Thanks

    Missa

    Hi Missa,

     

    Did you managed to obtain a solution to rendering the correct portal tab when using the button from a portal page?

    Chris

  • Chris001
    Chris001
    20 Posts

    Re: JavaScript code to open Cognos 10.2 HTML output in PDF format.

    ‏2014-10-22T05:12:54Z  
    • Chrismg
    • ‏2014-10-16T07:56:48Z

    Hi Missa,

     

    Did you managed to obtain a solution to rendering the correct portal tab when using the button from a portal page?

    Chris

    Hi !

     

    Maybe the attached sample helps.

     

    Chris

    Attachments

  • venkatachalapathi
    venkatachalapathi
    4 Posts

    Re: JavaScript code to open Cognos 10.2 HTML output in PDF format.

    ‏2015-08-04T14:08:05Z  

    Hi Team,

     

    Can some one guide me , how to export the mhtml Active Report output to Excel output format.

    Client requirement is Cognos Active report to Excel . Please suggest me here.

     

    Thanks,

    Chala

    chalapati4u@gmail.com