Попробуйте это:
сервис:
getPdfDocument(): Observable<any> {
let headers = new HttpHeaders({ 'Content-Type': 'application/JSON' });
return this.httpClient
.get(this.configuration.serverUrl + this.configuration.getPdfDoc,
{ headers: headers, responseType: 'blob' as 'json', observe: 'response' as 'body' }
});
}
запрос:
this.service.getPdfDocument()
.subscribe(
(data) => {
this.openFileForPrint(data);
});
openFileForPrint(data: HttpResponse<any>) {
let fileUrl = window.URL.createObjectURL(data);
window.open(fileUrl, '_blank', 'location=yes,height=600,width=800,scrollbars=yes,status=yes');
}
Серверная сторона
[HttpGet]
public HttpResponseMessage getpdf(DateTime datum, int idlokacija)
{
var r = _printService.getdata(datum, idlokacija);
if (r == null)
{
return new HttpResponseMessage(HttpStatusCode.NotFound);
}
return SendPdfFile(r);
}
public static HttpResponseMessage SendPdfFile(string filePath, bool brisanje = true)
{
var stream = new FileStream(filePath, FileMode.Open);
HttpResponseMessage response = new FileHttpResponseMessage(filePath, brisanje)
{
StatusCode = HttpStatusCode.OK,
Content = new StreamContent(stream)
};
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
return response;
}