如何从水晶报表的 ExportToStream 中的 Web API 中获取 pdf 流?

Dat*_* Me 5 c# pdf crystal-reports asp.net-web-api angularjs

我在通过流式传输将水晶报告导出为 pdf 时遇到问题。我使用 Web Api 并据称将 pdf 流式返回到我的客户端(即 angularJS)

这是我的代码..

服务器端

控制器

[Route("api/transcript")]
        [HttpPost]
        public async Task<HttpResponseMessage> Post(HttpRequestMessage request)
        {
            var content = request.Content;
            string jsonContent = content.ReadAsStringAsync().Result;

            // this code here is in repository. It will return ReportDocument.
            // It is functional and return the document file so i didnt include the code for this.
            ReportDocument rdoc = ITORRepo.LoadReport(jsonContent); 

            TOR _tor = JsonConvert.DeserializeObject<TOR>(jsonContent);
            string hdStudCode;
            hdStudCode = _tor.studCode;
            try
            {                   
                HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);

                response.Content = new StreamContent(rdoc.ExportToStream(ExportFormatType.PortableDocFormat));
                response.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment");
                response.Content.Headers.ContentDisposition.FileName = "Transcript.pdf";

                return response;
            }
            catch (Exception)
            {
                //return string.Empty;
                throw;
            }
        }
Run Code Online (Sandbox Code Playgroud)

客户端

AngularJS

$scope.Generate = function () {
        if (typeof $scope.id != 'undefined') {
            var data = {
                filename: 'OTR.rpt',
                studCode: $scope.studCode,
                orno: $scope.orNumber,
                orderno: $scope.orderNumber,
                orderdate: document.getElementById('date').value,
                graduationdate: document.getElementById('date2').value,
                remarks: $scope.remarks
            };
            $http.post(serviceUrl + 'api/transcript', data, { responseType: 'arraybuffer' }).success(function (response) {
                var file = new Blob([response], { type: 'application/pdf' });
                var fileURL = URL.createObjectURL(file);
                $scope.content = $sce.trustAsResourceUrl(fileURL);
                $('#TranscriptModal').modal('show');
            });
        }
    };
Run Code Online (Sandbox Code Playgroud)

HTML 页面

<object data="{{content}}" width="100%" height="100%">
 <div class="alert alert-danger text-center" style="border-radius:0">
You don't have PDF Plugin for this browser.  <a href="{{content}}">[ Click Here ]</a> to download the PDF File.
 </div>
 </object>
Run Code Online (Sandbox Code Playgroud)

该代码有时会起作用..这意味着有时会生成并显示pdf,但有时则不显示..

我的服务器端和客户端都没有错误。

请告诉我我的代码有什么问题,为什么有时没有显示,有时有显示......请帮助我解决我的问题的最佳方法是什么。

太感谢了...