If you are unable to create a new account, please email support@bspsoftware.com

 

News:

MetaManager - Administrative Tools for IBM Cognos
Pricing starting at $2,100
Download Now    Learn More

Main Menu

PDF output button

Started by qvixote, 27 May 2016 09:58:18 AM

Previous topic - Next topic

qvixote

Hello!

We have some reports with anonymous access, and with javascript code to hide the cognos toolbars on top of the page. In one of those reports, I need to provide PDF version to users, but the list to choose report output format is hidden. I've looked up the code of the HTML report page of others reports and found that the button that launch the PDF execute this javascript:

window.oCV_NS_.getRV().viewReport('PDF');

So I've made a HTML element like this:

<a href="javascript:window.oCV_NS_.getRV().viewReport('PDF');">PDF</a>

The problem is that it launch the report in PDF output in a new window, but the javascript that hide the toolbars dont run, so the users can see them. I was wandering if there's a way to launch PDF directly, instead of showing a new windows with the classic pdf outpot report view of report studio viewer. Once I've searched how to do this with excel format and foud a solution, putting this code in a HTML element:

<script>
CViewerManager.prototype.runExcel = function ()
{
  var oReq = new ViewerDispatcherEntry(this.getCV());
  oReq.addFormField("ui.action","render");
  oReq.addFormField("run.outputFormat","spreadsheetML");
  this.viewInNewWindowWithResize(oReq);
};

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;}
  var nameSpace = "oCV" + preFix;

 

CViewerManager.prototype.viewInNewWindowWithResize = function(oReq, browserHandle)
{
var oldUnload=window.onbeforeunload;
window.onbeforeunload=null;

if (browserHandle != null) {
browserHandle.close();
}
var target = "winNAT_" + ( new Date() ).getTime();
var sPath = this.getCV().getWebContentRoot() + "/" + "rv/blankNewWin.html?cv.id=" + this.getCVId();

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 oFWR = document["formWarpRequest" + this.getCVId()];
if (oFWR && oFWR["run.outputFormat"]) {
oReq.addFormField("previousFormat", oFWR["run.outputFormat"].value);
}


var formFieldNames = oReq.getFormFields().keys();
for (var index = 0; index < formFieldNames.length; index++)
{
var name = formFieldNames[index];

// we'll force the action and respons format later on so we don't indirectly send this request to the fragment server
// since we're now doing a render, don't pass along the tracking. We still need to pass the
// conversation since we want to reuse the parameters and options
if(name != "cv.responseFormat" && name != "b_action" && name != "m_tracking")
{
oForm.appendChild(createHiddenFormField(name, oReq.getFormField(name)));
}
}

oForm.appendChild(createHiddenFormField("cv.responseFormat", "page"));
oForm.appendChild(createHiddenFormField("b_action", "cognosViewer"));
oForm.appendChild(createHiddenFormField("BIline1", RV_RES.RV_RUNNING));
oForm.appendChild(createHiddenFormField("BIline2", RV_RES.RV_PLEASE_WAIT));


document.body.appendChild(oForm);
oForm.target = target;

browserHandle = window.open(sPath, target, "rv,resizable=1");

window.onbeforeunload=oldUnload;
};
</script>


Then adding another HTML element with:

<a href='#' class='listlink' onclick="window[nameSpace].getRV().runExcel()">Download Excel file</a>

And it opens a new windows but launch the file download. Someone know how can I do the same with PDF format?

Thanks.

afzaki7

I think this could help
it will open in the same window


<input type='Button' value="Report in PDF"  onclick="javascript:gCognosViewer.getRV().viewReport('PDF')">
" إِذَا مَاتَ ابْنُ آدَمَ انْقَطَعَ عَمَلُهُ إِلا مِنْ ثَلاثٍ : مِنْ صَدَقَةٍ جَارِيَةٍ ، أَوْ عِلْمٍ يُنْتَفَعُ بِهِ ، أَوْ وَلَدٍ صَالِحٍ يَدْعُو لَهُ "

qvixote

Thanks for answering, afzaki7!

The code you said

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

do exactly the same functionality as the code I've said

<a href="javascript:window.oCV_NS_.getRV().viewReport('PDF');">PDF</a>

But what I need is just the PDF, without the cognos toolbars above, so it doesn't resolve my problem.


afzaki7

did you tried my code ?
" إِذَا مَاتَ ابْنُ آدَمَ انْقَطَعَ عَمَلُهُ إِلا مِنْ ثَلاثٍ : مِنْ صَدَقَةٍ جَارِيَةٍ ، أَوْ عِلْمٍ يُنْتَفَعُ بِهِ ، أَوْ وَلَدٍ صَالِحٍ يَدْعُو لَهُ "