简体   繁体   中英

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 ac# 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.

Replace

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

With

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM