Cognos v11 SDK export to pdf

て烟熏妆下的殇ゞ 提交于 2019-12-11 04:12:46

问题


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.


回答1:


Replace

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

With

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


来源:https://stackoverflow.com/questions/52335592/cognos-v11-sdk-export-to-pdf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!