I'm using ajax to generate and view a File.
$.ajax({
url: '/Materials/Enquiries/GetRequisitionVersion',
type: 'POST',
data: $('#materialRequisitionVersionForm').serializeArray()
}).done(function (response) {
var file = new Blob([response], { type: 'application/pdf' });
var fileURL = URL.createObjectURL(file);
window.open(fileURL);
}).fail(function () {
})
This is my controller method. The GenerateMaterialRequisitionPreview function returns a byte Array. To test I created a filestream to save the file locally.
public async Task<IActionResult> GetRequisitionVersion(Guid requisitionId)
{
var bytes = await _reportingClient.GenerateMaterialRequisitionPreview(requisitionId);
//For testing
using (FileStream pdfOutput = new FileStream("test2.pdf", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite))
{
pdfOutput.Write(bytes);
}
return File(bytes, "application/pdf", "generated.pdf");
}
In the ajax response, when the new window opens, it returns an empty PDF file , however when i check the file saved by the filestream it's correct. generated.pdf test2.pdf
I inspected both pdf arrays and found that some of the characters in the generated pdf have been replaced by unknown characters □ and � If you compare these two images you'll see what i mean. corruptedPDF correctPDF
I'm not exaclty sure why the file is being corrupted this way and a fix for this. I am using google chrome.