I have the following code, being called by an ajax, which is converting a pdf to a base64 string and then sending the result as a json:
public object LoadPDF(string fileName)
{
string filePath = Server.MapPath(new Uri(fileName).LocalPath);
PdfLoadedDocument loadedDoc = new PdfLoadedDocument(filePath);
MemoryStream stream = new MemoryStream();
loadedDoc.Save(stream);
byte[] docBytes = stream.ToArray();
loadedDoc.Close(true);
return Json(new { data = "data:application/pdf;base64," + Convert.ToBase64String(docBytes.ToArray()) });
}
This is working fine except that when the file is above 2MB. I get the following error message in my ajax success:
Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.
Any work around for this please?