我在Angular 2中遇到問題在Iframe或任何控件中顯示PDF。PDF顯示Angular 2
你能指導我嗎?
我的Web API代碼:
[Route("GetReportStream")]
[HttpPost]
public HttpResponseMessage GetReportStream(string strReportUrl)
{
strReportUrl = "http://sample.com/ReportServer?%2fN+Team+3%2fD+Online+Reports%2fMemo+to+the+Court&rs:Command=Render&rc:Parameters=False&DocumentID=8&rs:Format=PDF";
byte[] pdf;
byte[] buffer = new byte[4096];
try
{
WebRequest request = WebRequest.Create(strReportUrl);
request.UseDefaultCredentials = true;
using (WebResponse resp = request.GetResponse())
{
using (Stream responseStream = resp.GetResponseStream())
{
using (MemoryStream memoryStream = new MemoryStream())
{
int count = 0;
do
{
count = responseStream.Read(buffer, 0, buffer.Length);
memoryStream.Write(buffer, 0, count);
} while (count != 0);
pdf = memoryStream.GetBuffer();
}
}
}
}
catch (Exception ex)
{
pdf = null;
}
var response = Request.CreateResponse<byte[]>(HttpStatusCode.OK, pdf);
return response;
}
我回國作爲我接受它字節。
private getReportStreamOnSuccess(response): void {
debugger;
var byteArray = new Uint8Array(response);
var blob = new Blob([byteArray], { type: 'application/pdf' });
//var file = new Blob([response], { type: 'application/pdf' });
var fileURL = URL.createObjectURL(blob);
this.url = this.domSanitizer.bypassSecurityTrustResourceUrl(fileURL);
}
我試過所有的選項沒有任何工作。
我只想在iframe或任何控件中查看它。
當我嘗試加載BLOB我得到這個 Image
它沒有工作,我嘗試同樣也是如此。我有一份SSRS報告我希望以PDF形式顯示在角度2中無需保存。 – Venk