gman
gman

Reputation: 167

Cognos v11 SDK export to pdf

Does anyone have an example that will generate a report as PDF using the sdk? The SDK.pdf only has html examples. I can't figure it out. I'm using a c# controller to call cognos to generate the report.

The runOptionStringArray value must be PDF.

outputFormat.value = new string[] { "PDF" };

The data i get back from the call looks like this: "JVBERi0xLjQKJeLjz9MNCjQgMCBvYmoKPDwvTGluZWFyaXplZCAxL0wgICAgIDExOTEyOC9IWyAgICAgICA1ODggICAgICAgIDE2MV0vTyA2L0UgICAgIDExODAzMi9OIDEvVCAgICAgMTE5MDAyPj4KZW5kb2JqCnhyZWYNCjQgMTUNCjAwMDAwMDAwMTYgMDAwMDAgbg0KMDAwMDAwMDc0OSAwMDAwMCBuDQowM"

I've tried this, but it still doesn't render as pdf.

asynchReply res = cBIRS.run( reportPath, parameters, runOptions );
// The report is finished, let's fetch the results and save them to a file.
string data = null;
if( res.status == asynchReplyStatusEnum.complete )
{
    for (int i = 0; i < res.details.Length; i++)
    {
        if (res.details[i] is asynchDetailReportOutput)
        {
            data = ( (asynchDetailReportOutput)res.details[i]).outputPages[0];
        }
    }
    FileStream fs = new FileStream(outputPath, FileMode.Create);
    byte[] hunk_data = UTF8Encoding.UTF8.GetBytes(data);
    fs.Write(hunk_data, 0, hunk_data.Length);
    fs.Close();
}

In the end the pdf does have data, but it can't be opened by adobe.

PS. I've also tried writing out the file without using the UTF8Encoding.UTF8.GetBytes and just using System.IO.File.WriteAllText(outputPath,data); That doesn't work either.

Upvotes: 1

Views: 311

Answers (1)

gman
gman

Reputation: 167

Replace

 byte[] hunk_data = UTF8Encoding.UTF8.GetBytes(data);

With

 byte[] hunk_data = Convert.FromBase64String(data);

Upvotes: 1

Related Questions