I am getting this error from Chrome failed to load PDF document. I am returning a byte[] as the Content and ContentType is set to application/pdf. Is this the correct way to display a PDF file in Typescript using a ajax Post?
Ts
printItems(versionKeys: string[]): JQueryPromise<any> {
console.log('printItems');
$.ajax({
type: "post",
contentType: "application/json",
data: JSON.stringify(versionKeys),
url: this.apiUrls.PrintTemplates,
success: function (data, status, xhr) {
console.log(data);
var file = new Blob([data.Content], { type: data.ContentType });
var fileURL = URL.createObjectURL(file);
window.open(fileURL);
console.log('success');
}
});
return;
}
Controller
[HttpGet, HttpPost]
[ApplicationApiAuthorize("Administrator, ContentManager")]
public IHttpActionResult PrintTemplates([FromBody] List<string> versionKeys)
{
var templates = versionKeys
.Select(v => TemplatesDataService.GetTemplate(v))
.ToList();
var templateIds = templates.Select(b => b.Id).ToList();
var templateFile = TemplatesDataService.PrintTemplate(templateIds);
return Ok(templateFile);
}