- When using the $http.get(...) method in SPA to download a PDF, the printed document turns out blank.
- However, upon debugging, it was found that data is successfully retrieved from the API.
Can anyone assist with this issue?
Here is the API implementation to generate and return the PDF stream:
public Stream GetConsumerInformationReport(Guid id)
{
..........
var stream = cryRpt.ExportToStream(ExportFormatType.PortableDocFormat);
return stream;
}
This is how the SPA fetches the data from the API:
var print = function () {
var downloadPath = apiEndPoint + 'Reports/' + $state.current.data.printPrefix + '.pdf';
$http.get(downloadPath,httpConfig).
success(function (data) {
var blob = new Blob([data], { type: "application/pdf" });
var objectUrl = URL.createObjectURL(blob);
$window.open(objectUrl);
}).
error(function (data, status, headers, config) {
// if there's an error you should see it here
});
};