Quickie: PDF Report in New Window

One of the biggest frustrations people have with Cognos is that it will use the same window to export a report to PDF. Excel will open a new page, but not PDF. Why? Who knows? (IBMers, please feel free to comment below.)

Fortunately we can use JavaScript to force Cognos to do our bidding.

Since the JavaScript API changed in 10.2 I have two implementations, one for 10.1.1 and lower and one for 10.2 and higher. Simply paste the correct JavaScript into an HTML item, and fix up the button to meet your needs.


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.viewInPDF = function(){
                var oReq =new CCognosViewerRequest("render")
                oReq.addOption("run.outputFormat", "PDF");
<input type="button" onclick="window[nameSpace].getRV().viewInPDF()" value="Export to PDF"/>

10.2 is a bit easier to work with:

CViewerManager.prototype.runPDF = function ()
  var oReq = new ViewerDispatcherEntry(this.getCV());
<input type="button" onclick="window['oCV'+'_THIS_'].getRV().runPDF()" value="Export to PDF"/>

Remember, use only one of them. The 10.1.1 version won’t work in 10.2, but should work in previous versions. I don’t have access to the 8 versions any more, so I’d appreciate if someone could leave a comment saying if it works or not.

Export to PDF Report XML (648 downloads)

Many people have experienced issues with the version posted above on 10.2.1 and above. The following version works perfectly for me on 10.2.1 with IE 8 and Firefox.
Export-to-PDF-10.21.txt (782 downloads)