I encoded a PDF file as Base64 and assign it to a property of my model object in ASP.NET WEB API which gets transferred as JSON. The response comes back to my client AngularJS application and the file is saved as I expect. The file size is one and 1/3 larger and the special accent characters are showing as two different characters and I receive a message from Adobe Reader that the embedded font doesn't open, but the PDF does open.
I suspect the problem is with the atob() decoding on the JavaScript side or with the encoding of the web page. I tried using utf-8, utf-16 and utf-32 for the web page with no difference on the result.
ASP.NET code:
byte[] document = File.ReadAllBytes(publishDocument.Path);
publishDocument.Document = Convert.ToBase64String(document, 0, document.Length);
JavaScript:
var content = atob(data.document);
var blob = new Blob([content], {
type: "application/pdf"
});
saveAs(blob, data.name);
I found the answer here: Save base64 string as PDF at client side with JavaScript
I replace the built-in
atob
andBlob
function with this one:For some reason, the .NET Base64 and the JavaScript Base64 are not the same.